Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Frank Dana <ferdnyc@gmail.com>
  • Loading branch information
BrennoCaldato and ferdnyc committed Jan 13, 2021
1 parent 1fa4e87 commit 73bf739
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/Frame.cpp
Expand Up @@ -943,7 +943,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()).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 );
Expand Down
4 changes: 3 additions & 1 deletion src/Frame.h
Expand Up @@ -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
Expand Down Expand Up @@ -295,6 +295,8 @@ namespace openshot
#ifdef USE_OPENCV
/// Convert Qimage to Mat
cv::Mat Qimage2mat( std::shared_ptr<QImage>& qimage);

/// Convert OpenCV Mat to QImage
std::shared_ptr<QImage> Mat2Qimage(cv::Mat img);

/// Get pointer to OpenCV Mat image object
Expand Down
35 changes: 18 additions & 17 deletions src/effects/ObjectDetection.cpp
Expand Up @@ -74,23 +74,24 @@ std::shared_ptr<Frame> ObjectDetection::GetFrame(std::shared_ptr<Frame> frame, i
cv::Mat cv_image = frame->GetImageCV();
std::cout<<"Frame number: "<<frame_number<<"\n\n";
// Check if frame isn't NULL
if(!cv_image.empty()){

// 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<detections.boxes.size(); i++){
cv::Rect_<float> 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<detections.boxes.size(); i++){
cv::Rect_<float> 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);
}
}

Expand Down

0 comments on commit 73bf739

Please sign in to comment.