gpt4 book ai didi

opencv - 如何从纸上提取这6个符号(签名)(opencv)

转载 作者:太空宇宙 更新时间:2023-11-03 20:57:58 38 4
gpt4 key购买 nike

我有一张图片:

an image

我正在尝试一个一个地提取符号。我尝试了 findContours() 但我得到了很多内部轮廓。有什么办法吗?

最佳答案

在查找轮廓时始终确保感兴趣的区域为白色。在这种情况下,将图像转换为灰度后,应用倒置二进制阈值,使签名为白色。执行此操作后,findContours() 将轻松找到所有签名。

代码:

以下是在python中的实现:

import cv2
image = cv2.imread(r'C:\Users\Jackson\Desktop\sign.jpg')

#--- Image was too big hence I resized it ---
image = cv2.resize(image, (0, 0), fx = 0.5, fy = 0.5)

#--- Converting image to grayscale ---
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

#--- Performing inverted binary threshold ---
retval, thresh_gray = cv2.threshold(gray, 0, 255, type = cv2.THRESH_BINARY_INV | cv2.THRESH_OTSU)

cv2.imshow('sign_thresh_gray', thresh_gray)

enter image description here

#--- finding contours ---
image, contours, hierarchy = cv2.findContours(thresh_gray,cv2.RETR_EXTERNAL, \
cv2.CHAIN_APPROX_SIMPLE)

for i, c in enumerate(contours):
if cv2.contourArea(c) > 100:
x, y, w, h = cv2.boundingRect(c)
roi = image[y :y + h, x : x + w ]
cv2.imshow('sign_{}.jpg'.format(i), roi)
cv2.waitKey()

cv2.destroyAllWindows()

结果:

这里我有一些提取的签名。

enter image description here

enter image description here

enter image description here

关于opencv - 如何从纸上提取这6个符号(签名)(opencv),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51091865/

38 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com