Ask Your Question
0

Extract parts from image

asked 2016-02-10 07:56:47 -0600

Croolman gravatar image

I have tried to use ROI to extract parts of image, but I haven't succeded. I have an image which contains rectangles - outlines of detected moving object.Input

This is the outcome I want. i want to extract those parts which are defined by those rectangles to same-sized matrix

Output

I have tried something like

cropMat(boudingRect) = frame(boundinRect);

but with this I get only the rectangles, not the part that is inside

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
2

answered 2016-02-10 08:13:39 -0600

berak gravatar image

you want copyTo(), not a simple "=" assignment:

Mat cars = imread("cars.jpg");
Mat draw = Mat(cars.size(), cars.type(), Scalar::all(0));
Rect r1(84,81,130,76);
Rect r2(417,144,153,85);

cars(r1).copyTo(draw(r1));
cars(r2).copyTo(draw(r2));

imshow("draw",draw);
waitKey();

image description

edit flag offensive delete link more

Comments

copyTo is the right thing to do, now it is doing what I need to

Croolman gravatar imageCroolman ( 2016-02-10 08:23:23 -0600 )edit

What was wrong with the copyTo? why is it better than simple =?

thdrksdfthmn gravatar imagethdrksdfthmn ( 2016-02-11 04:21:26 -0600 )edit
1

"=" assing only the refference, not the actual data

Croolman gravatar imageCroolman ( 2016-02-13 08:16:40 -0600 )edit
0

answered 2016-02-10 08:17:33 -0600

thdrksdfthmn gravatar image

You could create a 0-image where you add the info in the rectangles; something like this :

cv::Mat justInfo = cv::Mat::zeros(frame.size(), frame.type());
for (cv::Rect roi : detections)
{
    justInfo(roi) = frame(roi);
}
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2016-02-10 07:56:47 -0600

Seen: 15,712 times

Last updated: Feb 10 '16