OpenCV 去除水印
OpenCV For remove watermark
我正在尝试cv2.inpaint
,如果你自己加水印,再用cv2.inpaint
,效果就完美了。
但是,如果我使用如下互联网图片:
源图片
水印图片
结果不好
这是代码
zhihuimage = cv2.imread('../input/zhihumask/OpenCV_11.jpg')
zhihuwatermask = cv2.imread('../input/zhihumask/OpenCV_22.jpg')
# remove watermark with mark
zhihuwatermask = cv2.cvtColor(zhihuwatermask, cv2.COLOR_BGR2GRAY)
zhihuoutput = cv2.inpaint(zhihuimage, zhihuwatermask,3, flags= cv2.INPAINT_NS)
水印蒙版和图像中的水印似乎没有对齐,您可以扩大蒙版以补偿小的未对齐。
使用 dilate 的代码可以正确去除水印:
zhihuimage = cv2.imread('../input/zhihumask/OpenCV_11.jpg')
zhihuwatermask = cv2.imread('../input/zhihumask/OpenCV_22.jpg',cv2.IMREAD_GRAYSCALE)
# remove watermark with mark
dilatekernel = np.ones((5, 5), 'uint8')
zhihuwatermask = cv2.dilate(zhihuwatermask, dilatekernel)
zhihuoutput = cv2.inpaint(zhihuimage, zhihuwatermask, 3, flags=cv2.INPAINT_NS)
我正在尝试cv2.inpaint
,如果你自己加水印,再用cv2.inpaint
,效果就完美了。
但是,如果我使用如下互联网图片:
源图片
水印图片
结果不好
这是代码
zhihuimage = cv2.imread('../input/zhihumask/OpenCV_11.jpg')
zhihuwatermask = cv2.imread('../input/zhihumask/OpenCV_22.jpg')
# remove watermark with mark
zhihuwatermask = cv2.cvtColor(zhihuwatermask, cv2.COLOR_BGR2GRAY)
zhihuoutput = cv2.inpaint(zhihuimage, zhihuwatermask,3, flags= cv2.INPAINT_NS)
水印蒙版和图像中的水印似乎没有对齐,您可以扩大蒙版以补偿小的未对齐。
使用 dilate 的代码可以正确去除水印:
zhihuimage = cv2.imread('../input/zhihumask/OpenCV_11.jpg')
zhihuwatermask = cv2.imread('../input/zhihumask/OpenCV_22.jpg',cv2.IMREAD_GRAYSCALE)
# remove watermark with mark
dilatekernel = np.ones((5, 5), 'uint8')
zhihuwatermask = cv2.dilate(zhihuwatermask, dilatekernel)
zhihuoutput = cv2.inpaint(zhihuimage, zhihuwatermask, 3, flags=cv2.INPAINT_NS)