Ask Your Question

Revision history [back]

To change/access pixel of ROI, it's the same as access/change pixel in the Mat. Indeed, the ROI is just an header for the underling data, therefore:

Mat img = imread( "myimage.jpg" );
Rect my_roi( x, y, w, h );
Mat ROI = img( my_roi );
Vec3b pixel = ROI.at< Vec3b >( pixel_x, pixel_y );
// Swap color for the first pixel (BGR => RGB).
char tmp = pixel[0];
pixel[0] = pixel[2]; // set blue to red value
pixel[1] = pixel[1]; // do nothing on green
pixel[2] = tmp; // set red to blue

I use vector (Vec3b) in that sample, but you could use char or Ptr aceess on anything you want. Look at this page for the performance evaluation of accessors.