diff --git a/src/Frame.cpp b/src/Frame.cpp index c623ed48..8766a54e 100644 --- a/src/Frame.cpp +++ b/src/Frame.cpp @@ -129,6 +129,9 @@ Frame::~Frame() { // Clear all pointers image.reset(); audio.reset(); + #ifdef USE_OPENCV + imagecv.release(); + #endif } // Display the frame image to the screen (primarily used for debugging reasons) @@ -929,7 +932,7 @@ std::shared_ptr Frame::GetImage() // Convert Qimage to Mat cv::Mat Frame::Qimage2mat( std::shared_ptr& qimage) { - cv::Mat mat = cv::Mat(qimage->height(), qimage->width(), CV_8UC4, (uchar*)qimage->bits(), qimage->bytesPerLine()); + cv::Mat mat = cv::Mat(qimage->height(), qimage->width(), CV_8UC4, (uchar*)qimage->bits(), qimage->bytesPerLine()).clone(); cv::Mat mat2 = cv::Mat(mat.rows, mat.cols, CV_8UC3 ); int from_to[] = { 0,0, 1,1, 2,2 }; cv::mixChannels( &mat, 1, &mat2, 1, from_to, 3 ); @@ -945,19 +948,20 @@ cv::Mat Frame::GetImageCV() // Fill with black AddColor(width, height, color); - if (imagecv.empty()) - // Convert Qimage to Mat - imagecv = Qimage2mat(image); + //if (imagecv.empty()) + // Convert Qimage to Mat + imagecv = Qimage2mat(image); return imagecv; } std::shared_ptr Frame::Mat2Qimage(cv::Mat img){ cv::cvtColor(img, img, cv::COLOR_BGR2RGB); - std::shared_ptr imgIn = std::shared_ptr(new QImage((uchar*) img.data, img.cols, img.rows, img.step, QImage::Format_RGB888)); + QImage qimg((uchar*) img.data, img.cols, img.rows, img.step, QImage::Format_RGB888); + std::shared_ptr imgIn = std::make_shared(qimg.copy()); // Always convert to RGBA8888 (if different) if (imgIn->format() != QImage::Format_RGBA8888) - *image = imgIn->convertToFormat(QImage::Format_RGBA8888); + *imgIn = imgIn->convertToFormat(QImage::Format_RGBA8888); return imgIn; }