Ask Your Question

Opencv: cut image from the other image

asked 2012-10-30 23:12:15 -0500

qwerty gravatar image

updated 2012-10-30 23:12:53 -0500


Could you please tell me how I can cut image from the other image per coordinates in opencv. It should not be just choise of the region of interest but it should be created new IplImage object. Unfortunately I didn't find it in Google.

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted

answered 2012-10-31 03:19:40 -0500

Mahdi gravatar image

updated 2012-10-31 13:41:04 -0500

OpenCV 2.4:

src(Rect(left, top, src.cols, src.rows)).copyTo(dst);


cv::Mat img = ...;
cv::Mat subImg = img(cv::Range(0, 0), cv::Range(100, 100)).clone();
edit flag offensive delete link more



Mahdi, in your first example you are inserting whole src into dst (i.e. dst >= src), while qwerty wanted to copy part of src to dst (i.e. dst<=src). As for second example, it does not perform copy operation, but just defining ROI.

Michael Burdinov gravatar imageMichael Burdinov ( 2012-10-31 06:59:27 -0500 )edit

Oops, You are right! Thanks for the tip! I'll correct it.

Mahdi gravatar imageMahdi ( 2012-10-31 13:38:30 -0500 )edit

answered 2012-10-31 06:44:07 -0500

Michael Burdinov gravatar image
Mat dst;


Mat dst = src(Rect(roiLeft,roiTop,roiWidth,roiHeight)).clone();
edit flag offensive delete link more
Login/Signup to Answer

Question Tools


Asked: 2012-10-30 23:12:15 -0500

Seen: 16,319 times

Last updated: Oct 31 '12