python - 使用 OpenCV 删除部分图像

标签 python opencv bitwise-operators mask

我有一个图像,我想简单地使用 OpenCV 删除(或屏蔽)它的一部分。这是我的原始图像:

enter image description here

我想通过这个图像蒙版删除其中心的圆圈:

enter image description here

我在我的代码中使用这个命令,从我阅读的教程中应该可以正常工作,并在原始图像的中心涂黑一个圆圈:

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

但我得到的结果是下面的图像,实际上它没有删除 mask 部分,而是反转了黑白:

enter image description here


如果您能帮助我找到一种方法来正确掩盖(或删除)我想要的部分,我将不胜感激。
谢谢

最佳答案

试试这个:

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

enter image description here

关于python - 使用 OpenCV 删除部分图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45965333/

相关文章:

javascript - 如何使用查表和异或来计算二进制中的 1?

python - QGraphicsView 开始时尺寸错误

python - 将 Openpyxl 与现有工作簿一起使用的 Pandas Excel Writer

Python递归查找 parent 的儿子

c++ - 如何在没有 Python 调试库的情况下在 Debug模式下使用 Cmake/Visual Studio 构建 OpenCV

javascript - | 是什么意思?运营商做什么?

javascript - 为什么在 javascript 中, `2 << -1` 是零而不是一?

Python IRC 机器人帮助

c++ - 如何使用 OpenCV 检测视频中的方 block ?

c++ - 错误: 'varName' was not declared in this scope