Ask Your Question

GrabCut Sample code in Opencv

asked 2013-06-09 23:09:10 -0600

waqasp gravatar image


Hello all, I am using grabcut sample code from opencv as a part of my project... the final image which i am getting after using that sample code contain black background... according to me, it is because of the mask....?? i have tried everything to change the background to white or transparent...

what modification should i make to the sample code to get final image with white or transparent background...


edit retag flag offensive close merge delete


anyone ??/

waqasp gravatar imagewaqasp ( 2013-06-10 04:40:54 -0600 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2013-06-11 05:09:08 -0600

Vladislav Vinogradov gravatar image

Try to set your background before image copying:

Mat res(image.size(), image.type());

// fill background
res.setTo(Scalar::all(255)); // white

// copy foreground
image.copyTo(res, binMask);
edit flag offensive delete link more


Thanks alot my friend... really appreciate your support:)

waqasp gravatar imagewaqasp ( 2013-06-11 05:45:53 -0600 )edit

Question Tools


Asked: 2013-06-09 23:09:10 -0600

Seen: 1,140 times

Last updated: Jun 11 '13