【问题标题】:Detecting watermark using opencv使用opencv检测水印
【发布时间】:2020-12-24 06:59:27
【问题描述】:

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

我从下面的代码中得到了上图:

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

原图为:

【问题讨论】:

  • 反转图像,使文本在黑色背景上显示为白色。然后得到轮廓并通过区域过滤去除小的轮廓。然后从 cv2.minAreaRect() 中获取旋转后的边界框。见docs.opencv.org/4.1.1/d3/dc0/…
  • 你能给我一个示例代码吗?我无法对其进行编码。 ` imagem = cv2.bitwise_not(dilation) imagem = cv2.cvtColor(imagem, cv2.COLOR_RGB2GRAY) _,contours, hierarchy = cv2.findContours(imagem, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE) cv2.drawContours(imagem, contours, - 1, (0,255,0), 3) ` 我黑屏了
  • 请看下面的答案。

标签: python opencv watermark opencv-drawcontour


【解决方案1】:

在您已经编写的代码的基础上,您需要反转结果并应用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,(0,0,255),2)

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-11-05
    • 2021-11-17
    • 1970-01-01
    • 1970-01-01
    • 2011-09-15
    • 2023-01-08
    • 1970-01-01
    • 2015-11-14
    相关资源
    最近更新 更多