在对图像进行阈值处理后,我想将字符与边框分开:
原始图像
接触区域
期望的输出
我正在使用 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