Ask Your Question
1

OpenCv: Extract portion of a Mat image

asked Jun 4 '14

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?

Preview: (hide)

2 answers

Sort by » oldest newest most voted
1

answered Jun 5 '14

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
Preview: (hide)
1

answered May 10 '17

harsh_bangari gravatar image

updated May 10 '17

Here, mat will be your originalMat.

Rect roi = new Rect(40, 100, 100, 120);
Mat cropped = new Mat(mat, roi);
Preview: (hide)

Question Tools

1 follower

Stats

Asked: Jun 4 '14

Seen: 26,354 times

Last updated: May 10 '17