doctorWW
doctorWW

Reputation: 31

Crop image's area with openCV (java)

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!

Upvotes: 0

Views: 8815

Answers (1)

hariprasad
hariprasad

Reputation: 858

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.

Upvotes: 7

Related Questions