python - 阈值处理后将字符与边框分开

标签 python opencv image-processing image-thresholding automatic-license-plate-recognition

我想在对图像进行阈值处理后将字符与边框分开:

原图

Original Image

触摸区域

Touching areas

期望的输出

Desired Output

我正在使用 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/

相关文章:

opencv - 视频处理中改变fps的问题有哪些?

opencv - Opencv可以写flv格式吗?

python - 用 numpy tensordot 进行张量乘法

python - 如何在python中动态创建类的实例?

python - 在 panda 数据框中插入值

opencv createsamples没有错误,但是没有找到样本

image-processing - 我可以修改图像的像素值吗?

python - 从python中的多个线程读取单个文件

image - 如何选择图像插值方法? (Emgu/OpenCV)

python - 哪个 SSIM 是正确的 : skimage.metrics.structural_similarity()?