I think newer versions of OpenCV (2.3+) have a different way of doing ROI. This is what the manual says:
// create a new 320x240 image Mat img(Size(320,240),CV_8UC3); // select a ROI Mat roi(img, Rect(10,10,100,100)); // fill the ROI with (0,255,0) (which is green in RGB space); // the original 320x240 image will be modified roi = Scalar(0,255,0);
Here is what I did in one instance:
// adding a header on top of image Mat dst = Mat::zeros(frame.rows + HEADER_HEIGHT, frame.cols, CV_8UC3); // frame portion Mat roi(dst, Rect(0, HEADER_HEIGHT-1, frame.cols, frame.rows)); // header portion Mat head(dst, Rect(0,0,frame.cols, HEADER_HEIGHT)); // zeros to clear the header portion Mat zhead = Mat::zeros(head.rows, head.cols, CV_8UC3); frame.copyTo(roi); // copy new image to image portion of dst zhead.copyTo(head); // clear the header portion of dst
You can use any of the subframes ( roi and head in my example) to calculate the average value of the region. There is an adjustROI function for moving an area of โโinterest and a locateROI function, which can also be useful.
source share