Skip to content

Commit

Permalink
Bug fixes for the function Frame::SetImageCV
Browse files Browse the repository at this point in the history
  • Loading branch information
BrennoCaldato committed Jul 20, 2020
1 parent d3c8fb1 commit df328ef
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/Frame.cpp
Expand Up @@ -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)
Expand Down Expand Up @@ -929,7 +932,7 @@ std::shared_ptr<QImage> Frame::GetImage()
// Convert Qimage to Mat
cv::Mat Frame::Qimage2mat( std::shared_ptr<QImage>& 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 );
Expand All @@ -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<QImage> Frame::Mat2Qimage(cv::Mat img){
cv::cvtColor(img, img, cv::COLOR_BGR2RGB);
std::shared_ptr<QImage> imgIn = std::shared_ptr<QImage>(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<QImage> imgIn = std::make_shared<QImage>(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;
}
Expand Down

0 comments on commit df328ef

Please sign in to comment.