OpenCV for OCR: How to compute thresholding levels for gray image OCR

后端 未结 3 1832
無奈伤痛
無奈伤痛 2020-12-10 00:03

I\'m trying to prepare images for OCR, and so far here is what I\'ve done using info from Extracting text OpenCV

From the resulting image I use the contours that hav

3条回答
  •  眼角桃花
    2020-12-10 00:48

    I've tried to maximize the distance between the minimum and the maximum color of one channel and then inverted the colors. (See Code)

    img1 = cv2.imread('img.png')
    img_reverted = img1.copy()
    
    for i in range(3):
      tmp = (img1[:, :, i] - img1[:, :, i].min()) / img1[:, :, i].max()
      tmp = tmp * 255
      tmp = -1 * tmp + 255
      img_reverted[:, :, i] = tmp.astype('uint8');
    

    The results are quite good. (See images)

    Original image:

    Reverted image:

提交回复
热议问题