0

I have detected a area (rectangle) in my image with openCv and i have stored the 4 points of rectangle with their coordinates.

I would to crop the original image in this area.

I have:

Mat image_original; 
Point p1,p2,p3,p4;
Mat image_output;

How i do this? Thanks!

doctorWW
  • 31
  • 3
  • 6
  • Please check this link : http://stackoverflow.com/questions/15963464/opencv-crop-image-using-four-points/43632434#43632434 – user7176550 Apr 26 '17 at 11:09

1 Answers1

7
Mat image_original; 
Point p1,p2,p3,p4;
Rect rectCrop = new Rect(p1.x, p1.y , (p4.x-p1.x+1), (p4.y-p1.y+1));
Mat image_output= image_original.submat(rectCrop);

This is the code for croping image as per your requirement.I assumed that Point p1 is the top-left corner of the crop rectangle and Point p4 is the bottom-right corner of the crop rectangle as you have not mentioned anything about their positions.

hariprasad
  • 838
  • 1
  • 8
  • 16
  • Another question: if i want crop the image near a contours (it is a List) instead of a precise rectangle with 4 point, it is possibile? – doctorWW Jun 21 '16 at 14:30
  • 1
    @doctorWW Please accept / upvote if this answer your question. Different question should be _new_ questions. Hint: get the boundingRect of your contours points, and then use `submat` – Miki Jun 21 '16 at 14:32