python - 如何在签名上创建边界框并忽略文本区域
问题描述
我正在从图像中检测手写签名。我需要检测签名然后提取它,在签名周围创建矩形,裁剪矩形并保存它。
我正在努力将签名的整个区域识别为一个轮廓或一组轮廓。因为我正在处理这种图像。 https://raw.githubusercontent.com/ahmetozlu/signature_extractor/master/inputs/in2.jpg 或者也处理灰度背景图像。我使用下面的代码,它会创建小盒子。关于如何解决这个问题的任何建议?
import cv2
import uuid
image = cv2.imread('img.png')
img = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)
cv2.threshold(img,0,255,cv2.THRESH_BINARY+cv2.THRESH_OTSU,img)
cv2.bitwise_not(img,img)
rect_kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (3, 5))
img = cv2.morphologyEx(img, cv2.MORPH_CLOSE, rect_kernel)
contours, hier = cv2.findContours(img, cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_NONE)
count=0
id = uuid.uuid4()
if len(contours) != 0:
for c in contours:
x,y,w,h = cv2.boundingRect(c)
filename = '{0}{1}{2}.{3}'.format('D:\users\outputs/',id, count, "jpg")
position='{0},{1}'.format(x, y)
print("Coordinates of the Signatures:" ,position)
print(filename)
count += 1
print(count)
if(h>70):
cv2.rectangle(image,(x,y),(x+w,y+h),(0,0,255),1)
roi = image[y:y+h, x:x+w]
cv2.imwrite(filename, roi)
# roi2 = image[y:y + h, x:x + w]
cv2.imwrite('D:\users\outputs/Result.jpg', image)
cv2.waitKey(0)
解决方案
推荐阅读
- r - 我们能否将回归方程与 R2 和 p 值巧妙地对齐?
- javascript - 当 props 准备好时使用 ref
- asp.net-mvc-4 - 上传到plesk后的asp.net web应用程序数据库连接问题
- sql - 错误:查询在 postgres 中没有结果数据的目的地
- youtrack - 在 YouTrack 中恢复已删除的工作流程
- c++ - C++:如何在不使用算法库中的排序函数的情况下按字母顺序排列字符串向量
- python - 从 word 文件中提取表格并将每个表格保存为一个单独的数据框,该数据框应具有相应 word 文件的名称
- python - 如何在 Plotly (Python) 中自定义日期时间刻度
- chromium - 用VS2017在Windows10上单独搭建Chromium Network stack
- java - 没有使用 Selenium 加载网页