我想在对图像进行阈值处理后将字符与边框分开:
原图
触摸区域
期望的输出
我正在使用 python 和 OpenCV 进行阈值处理。预先感谢您的帮助。
这是设定阈值的部分代码
def threshold_image(img):
gray_img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
resized_img = cv2.resize(gray_img
, None
, fx=5.0
, fy=5.0
, interpolation=cv2.INTER_CUBIC)
resized_img = cv2.GaussianBlur(resized_img,(5,5),0)#(5,5)
equalized_img = cv2.equalizeHist(resized_img)
# height of the image
alto = int(resized_img.shape[0]) # shape[0] = rows
# width of the image
ancho = int(resized_img.shape[1]) # shape[1] = cols
reduced = cv2.cvtColor(reduce_colors(cv2.cvtColor(equalized_img, cv2.COLOR_GRAY2BGR), 6), cv2.COLOR_BGR2GRAY)
ret, mask = cv2.threshold(reduced, 110, 255, cv2.THRESH_BINARY)#64
cv2.imwrite('licence_plate_mask.png', mask)
return mask
最佳答案
您可以申请 erosion对 mask 进行操作以断开所选区域。
在腐 eclipse 时你应该小心不要断开“H”,你可以改变你的内核来最大程度地影响垂直形状。
您可以阅读更多关于数学形态学运算符的信息 here .
关于python - 阈值处理后将字符与边框分开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52612012/