Sorry, this content is no longer available

Ask Your Question
3

Opencv: cut image from the other image

asked Oct 31 '12

qwerty gravatar image

updated Oct 31 '12

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.

Preview: (hide)

2 answers

Sort by » oldest newest most voted
5

answered Oct 31 '12

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

or

Mat dst = src(Rect(roiLeft,roiTop,roiWidth,roiHeight)).clone();
Preview: (hide)
1

answered Oct 31 '12

Mahdi gravatar image

updated Oct 31 '12

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

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 (Oct 31 '12)edit

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

Mahdi gravatar imageMahdi (Oct 31 '12)edit

Question Tools

Stats

Asked: Oct 31 '12

Seen: 16,595 times

Last updated: Oct 31 '12