Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Another approach:

// Assume "box" is a cvRect variable with the ROI dimensions

// Allocate space for a single-channel ROI (to store the grayscale ROI)
IplImage* gray_roi = cvCreateImage(cvSize(box.width, box.height), IPL_DEPTH_8U, 1);

// Allocate space for a temporary 3-channel image
IplImage* rgb_roi = cvCreateImage(cvSize(box.width, box.height), IPL_DEPTH_8U, 3);

// vid_frame is the original image. Let's set the ROI and perform a grayscale conversion.
cvSetImageROI(vid_frame, box);
cvCvtColor(vid_frame, gray_roi, CV_BGR2GRAY);

// Copy the processed image back to the original image
cvCvtColor(gray_roi, rgb_roi, CV_GRAY2BGR);
cvCopy(rgb_roi, vid_frame, NULL);

// Now reset the ROI so cvShowImage displays the full image
cvResetImageROI(vid_frame);
cvShowImage("Example", vid_frame);