首页 > 解决方案 > opencv python 七段数字检测与ocr

问题描述

我的算法是

rgb -> gray -> blur -> 二值化(用于纠正背景的不均匀性)-> dilate -> otsu ->morphologyEX

 gray = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)
    blurred = cv2.GaussianBlur(gray, (3, 3), 0)
    se = cv2.getStructuringElement(cv2.MORPH_RECT, (10, 10))
    bg = cv2.morphologyEx(blurred, cv2.MORPH_DILATE, se)
    out_gray = cv2.divide(blurred, bg, scale=255)
    out_binary = cv2.threshold(out_gray, 0, 255, cv2.THRESH_BINARY_INV | cv2.THRESH_OTSU)[1]

    # kernel = np.ones((2, 2), np.uint8)
    kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (1, 3))
    result = cv2.morphologyEx(out_binary, cv2.MORPH_CLOSE, kernel)

输入图像 算法输出

我想输出 [3 0 3 8 6 7 0 8 1]

标签: pythonopencvocrtesseractopencv-python

解决方案


推荐阅读