微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用opencv检测水印

如何解决使用opencv检测水印

我想在下图中使用opencv在“已删除”一词周围画一个框,并找到坐标。

enter image description here

我从以下代码获得了上图:

kernel = np.ones((3,3),np.uint8)
dilation = cv2.dilate(img,kernel,iterations =1)
plt.imshow(dilation)

原始图片是:

This is the original image

解决方法

以您已经编写的代码为基础,您需要反转结果并应用findContours()

inv_img = cv2.bitwise_not(dilation)
contours,hierarchy = cv2.findContours(gray_in,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
for cnt in contours:
  rect = cv2.minAreaRect(cnt)
  box = cv2.cv.BoxPoints(rect) # cv2.boxPoints(rect) for OpenCV 3.x
  box = np.int0(box)
  cv2.drawContours(im,[box],(0,255),2)

您需要查看哪个框更好,哪个轮廓最合适。 这个答案会有所帮助: Python OpenCV Box2D

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。