Ask Your Question
0

Copy Mat at Contour/Mask into another Mat.

asked Sep 21 '18

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.

Preview: (hide)

1 answer

Sort by » oldest newest most voted
1

answered Sep 21 '18

berak gravatar image

updated Sep 21 '18

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

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 (Sep 21 '18)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 (Sep 21 '18)edit

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

LuisK gravatar imageLuisK (Sep 21 '18)edit

Question Tools

1 follower

Stats

Asked: Sep 21 '18

Seen: 2,496 times

Last updated: Sep 21 '18