Removing parts of the image with OpenCV

柔情痞子 提交于 2019-12-12 18:08:36

问题


I have an image and I want to simply remove(or mask) parts of it with OpenCV. this is my original image :



And I want to remove a circle on its center via this image mask :



I use this command in my code which from the tutorials I read should work and black out a circle in the center of my original image :

img = cv2.bitwise_not(imgOriginal,imgOriginal,mask=imgMask)

but the result I get is the image below, in fact instead of removing the masked parts, it just inverts blacks and whites:


I'll appreciate if you can help me on finding a way to properly mask(or remove) the parts I want.
Thanks


回答1:


Try this:

//given source, mask and destination Mat images with same size
cv::subtract(img, mask, dst);




回答2:


Try to set pixels to the background color using a mask, like this:

img.setTo(Scalar::all(0),mask);


来源:https://stackoverflow.com/questions/45965333/removing-parts-of-the-image-with-opencv

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!