小编use*_*657的帖子

使用 OpenCV 从图像中检测和提取签名

我正在导入附加的图像。导入图像后,我想删除水平线,检测签名然后提取它,在签名周围创建矩形,裁剪矩形并保存。

我正在努力将签名的整个区域识别为一个轮廓或一组轮廓。

我已经尝试过findcontour各种方法来检测签名区域。请参考下面的代码。

Python脚本:

imagePath

#read image
image = cv2.imread(imagePath,cv2.COLOR_BGR2RGB)

#Convert to greyscale
gray = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY) # grayscale

#Apply threshold
ret,thresh1 = cv2.threshold(gray, 0, 255,cv2.THRESH_OTSU|cv2.THRESH_BINARY_INV)

plt.imshow(thresh1,cmap = 'gray')


#preprocessing
rect_kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (15,15))
dilation = cv2.dilate(thresh1, rect_kernel, iterations = 1)
plt.imshow(dilation,cmap = 'gray')


#Detect contours
contours, hierarchy = cv2.findContours(dilation, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)
contours[0]

height, width, _ = image.shape
min_x, min_y = width, height
max_x = max_y = 0   
for contour, hier in zip(contours, hierarchy):
    (x,y,w,h) = cv2.boundingRect(contour)
    min_x, max_x …
Run Code Online (Sandbox Code Playgroud)

python opencv image-processing signature contour

1
推荐指数
1
解决办法
7400
查看次数

标签 统计

contour ×1

image-processing ×1

opencv ×1

python ×1

signature ×1