Actually I need to crop a rectangle portion in an image. I am having two points p1 and p2 of the rectangle. After cropping the rectangle I need to store that one for further reference.
Asked
Active
Viewed 2,385 times
0
-
3This question was already asked here (multiple times). stackoverflow requires that you perform search before posting question. – Michael Burdinov Apr 07 '14 at 13:38
-
1possible duplicate of [crop and Save ROI as new image in OpenCV 2.4.2 using cv::Mat](http://stackoverflow.com/questions/16014093/crop-and-save-roi-as-new-image-in-opencv-2-4-2-using-cvmat) – Michael Burdinov Apr 07 '14 at 13:40
-
1It's not working for me. Please suggest me if anything else is there. – Somashekar Apr 08 '14 at 05:14
1 Answers
1
Hi i know this is an old question, but this could be helpful to someone else having the same problem.
Given a rectangle containing your
roi: Rect
rect(topLeft_X,topLeft_Y,bottomRight_X,bottomRight_Y);
Say the image you want to crop is detectROI
, than to crop the roi
given the above rectangle, simply do the following:
Mat roi = detectROI(rect);
Than to save this image:
imwrite("ROI.jpg", roi);

J. Chomel
- 8,193
- 15
- 41
- 69