Ask Your Question
0

Copy Mat at Contour/Mask into another Mat.

asked 2018-09-21 09:22:56 -0600

LuisK gravatar image

Hello guys.

Is there a possibility, to copy a mat at a pixels bounded by a specific contour (not it´s boundRect!) resp. a binary Mask into another mat?

Thanks for helping.

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted
1

answered 2018-09-21 09:32:07 -0600

berak gravatar image

updated 2018-09-21 10:10:17 -0600

in short - NO. only rectangular areas can be copied.

but , what you can do is: make a mask from your contour, and mask out (blacken or such) anything inside the boundingRect but outside the contour:

Rect roi = boundingRect(contours[i])
Mat mask = Mat::zeros(roi.size(), img.type());
drawContours(mask,contours,i,Scalar::all(255), -1); // -1 == filled
Mat final;
img(roi).copyTo(final, mask);
edit flag offensive delete link more

Comments

The issue is, that there must be no black areas in the image, i wanna "copy" the contour in. I really want only the contour to be put in that image.

LuisK gravatar imageLuisK ( 2018-09-21 09:51:10 -0600 )edit

you obviously did not try it.

it will only copy, wher the mask in ON.

if it's still unclear -- the problem is in your question, then..

berak gravatar imageberak ( 2018-09-21 10:11:07 -0600 )edit

Thanks mate, your edits really helped me out! Thank you very much!

LuisK gravatar imageLuisK ( 2018-09-21 10:37:32 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2018-09-21 09:22:56 -0600

Seen: 2,391 times

Last updated: Sep 21 '18