diff --git a/src/Frame.cpp b/src/Frame.cpp index e25aa5ad6..24acdc40e 100644 --- a/src/Frame.cpp +++ b/src/Frame.cpp @@ -943,7 +943,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()).clone(); + cv::Mat mat = cv::Mat(qimage->height(), qimage->width(), CV_8UC4, (const uchar*)qimage->constbits(), 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 ); diff --git a/src/Frame.h b/src/Frame.h index e241555ec..75976f17b 100644 --- a/src/Frame.h +++ b/src/Frame.h @@ -124,7 +124,7 @@ namespace openshot int64_t max_audio_sample; ///< The max audio sample count added to this frame #ifdef USE_OPENCV - cv::Mat imagecv; ///< OpenCV image. It will be always on BGR format + cv::Mat imagecv; ///< OpenCV image. It will always be in BGR format #endif /// Constrain a color value from 0 to 255 @@ -295,6 +295,8 @@ namespace openshot #ifdef USE_OPENCV /// Convert Qimage to Mat cv::Mat Qimage2mat( std::shared_ptr& qimage); + + /// Convert OpenCV Mat to QImage std::shared_ptr Mat2Qimage(cv::Mat img); /// Get pointer to OpenCV Mat image object diff --git a/src/effects/ObjectDetection.cpp b/src/effects/ObjectDetection.cpp index d4e1e0778..e21a9a847 100644 --- a/src/effects/ObjectDetection.cpp +++ b/src/effects/ObjectDetection.cpp @@ -74,23 +74,24 @@ std::shared_ptr ObjectDetection::GetFrame(std::shared_ptr frame, i cv::Mat cv_image = frame->GetImageCV(); std::cout<<"Frame number: "< bb_nrml = detections.boxes.at(i); - cv::Rect2d box((int)(bb_nrml.x*fw), - (int)(bb_nrml.y*fh), - (int)(bb_nrml.width*fw), - (int)(bb_nrml.height*fh)); - drawPred(detections.classIds.at(i), detections.confidences.at(i), - box, cv_image); - } + if(cv_image.empty()){ + return frame; + } + + // Check if track data exists for the requested frame + if (detectionsData.find(frame_number) != detectionsData.end()) { + float fw = cv_image.size().width; + float fh = cv_image.size().height; + + DetectionData detections = detectionsData[frame_number]; + for(int i = 0; i bb_nrml = detections.boxes.at(i); + cv::Rect2d box((int)(bb_nrml.x*fw), + (int)(bb_nrml.y*fh), + (int)(bb_nrml.width*fw), + (int)(bb_nrml.height*fh)); + drawPred(detections.classIds.at(i), detections.confidences.at(i), + box, cv_image); } }