Ask Your Question
3

Opencv: cut image from the other image

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

qwerty gravatar image

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

Hello,

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
5

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

Michael Burdinov gravatar image
Mat dst;
src(Rect(roiLeft,roiTop,roiWidth,roiHeight)).copyTo(dst);

or

Mat dst = src(Rect(roiLeft,roiTop,roiWidth,roiHeight)).clone();
edit flag offensive delete link more
1

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

Mahdi gravatar image

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

OpenCV 2.4:

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

or

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

Comments

2

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 -0600 )edit

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

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

Question Tools

Stats

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

Seen: 16,590 times

Last updated: Oct 31 '12