Reputation: 1120
While I can write a whole image to a file with
cvSaveImage("image.png", img);
how can I write only a given rectangle from the image I'm working on to a file?
Upvotes: 0
Views: 94
Reputation: 8725
There's Mat
constructor:
Mat(const Mat& m, const Rect& roi);
So just use it!
Or if you use c
(not c++
) interface than you have to set ROI (Region Of Interest):
http://nashruddin.com/OpenCV_Region_of_Interest_(ROI)/
Your code should look like this:
cvSetImageROI(img, rect);//rect is a ROI
cvSaveImage("image.png", img);
If you want to work again with full image than you have to reset ROI:
cvResetImageROI( IplImage* img )
Upvotes: 1