Ask Your Question

OpenCv: Extract portion of a Mat image

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

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

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

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

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

harsh_bangari gravatar image

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

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


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

Seen: 21,861 times

Last updated: May 10 '17