Ask Your Question
1

OpenCv: Extract portion of a Mat image

asked 2014-06-04 14:26:46 -0600

iulianrosca gravatar image

If I have a MatOfPoint that represents a rectangle, how can I extract this MatOfPoint from an image, another Mat. I just want to extract a portion of a image that is represented by the MatOfPoint. I can extract the coordinates from the MatOfPoint , how can I use the 4 coordinates to extract the portion of the Mat?

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
1

answered 2014-06-04 22:50:47 -0600

Haris gravatar image

Assume you got your point like, topLeft, topRight, bottomLeft, bottomRight.

Mat src;//Source image load here
Rect R(topLeft,bottomRight); //Create a rect 
Mat ROI = src(R) //Crop the region of interest using above rect
edit flag offensive delete link more
1

answered 2017-05-10 01:22:45 -0600

harsh_bangari gravatar image

updated 2017-05-10 01:26:57 -0600

Here, mat will be your originalMat.

Rect roi = new Rect(40, 100, 100, 120);
Mat cropped = new Mat(mat, roi);
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2014-06-04 14:26:46 -0600

Seen: 25,878 times

Last updated: May 10 '17