c++ - Create a rectangle region mask on image with OpenCV -


there image read in cv::mat format , want remain rectangle region detect in center of image. tried cvcopy approach, required image format cvarr , guys have idea how implement still use mat format well?


there code , screenshot creating mask , seems strange size of mask did not match original frame. tips here please?

    *cap >> frame1;     rect roi(100,100,100,100);     for(int =0; i<frame1.rows; i++)     {         for(int j=0; j<frame1.cols;j++)         {             if(!roi.contains(point(i,j)))             {                 frame1.at<uchar>(i,j) = 0;             }         }     } 

enter image description here

simply create new image, refers same data.

cv::rect const mask(x1, y1, x2, y2); cv::mat roi = image(mask); 

now can roi processing. changes on roi appply on image too.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -