You've already forked libopenshot
mirror of
https://github.com/OpenShot/libopenshot.git
synced 2026-03-02 08:53:52 -08:00
Bug fixes for the function Frame::SetImageCV
This commit is contained in:
@@ -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<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 );
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user