OpenCV Adaptive Threshold OCR

前端 未结 3 551
北荒
北荒 2020-11-27 03:40

I am using OpenCV to prepare images for OCR from an iPhone camera, and I have been having trouble getting the results I need for an accurate OCR scan. Here is the code I am

3条回答
  •  庸人自扰
    2020-11-27 04:31

    As the light is almost in uniform, and the foreground is easily distinguished with the background. So I think just directly threshold (using OTSU) is ok for OCR. (Almost the same with @Andrey's answer in text regions).


    OpenCV 3 Code in Python:

    #!/usr/bin/python3
    # 2018.01.17 16:41:20 CST
    import cv2
    import numpy as np
    
    img = cv2.imread("ocr.jpg")
    gray = cv2.cvtColor(median, cv2.COLOR_BGR2GRAY)
    th, threshed = cv2.threshold(gray,127,255, cv2.THRESH_BINARY|cv2.THRESH_OTSU)
    print(th)
    
    cv2.imwrite("res.png", threshed)
    

提交回复
热议问题