Home > database >  OpenCV For remove watermark
OpenCV For remove watermark

Time:10-15

I am trying cv2.inpaint, if you add watermark by myself, and then use cv2.inpaint, the result is perfect.

But, if I use internet image like below:

Source Image

enter image description here

Watermark image
enter image description here

The result is bad.

Here is the code

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)

CodePudding user response:

It seems that the watermark mask and the watermark in the image are not aligned, you can dilate the mask to compensate for small mis-alignments.

Code with dilate that removes the watermark properly:

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)
  • Related