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; } } }
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
Post a Comment