1 year ago

#265654

test-img

satyam pawar

Detecting numbers from image of different lighting condition using tesseract OCR, Python

the problem for this image with different light condition:- Img_1

worked for this morning image:- Img_2

I am trying to extract numbers from the video by using Tesseract OCR & Python . in that video, there is a train available on each train there is a number plate that I will be detected by using YOLO. once I got the plate I'm preprocessing it & extract no from the plate. I am able to extract it but if there is a different light condition or there is night in the video then my preprocessing will not work properly. so I wanted a Genral purpose Logic to preprocess images in a such way that it'll work for all images, not for some. I have attached some images for the trial. in the CODE I have extracted only part of the plate manually then pass it to getText(image) to perform preprocessing & extract no

def getText(img):

    # color threshold
    thresh = otsu_thresholding(img)
    gray = get_grayscale(thresh)
    gray[gray != 0] = 255

    # second way
    thresh_2 = adaptive_thresholding(get_grayscale(img), method=1)
 
    cv2.imshow("img", img)
    cv2.imshow("Thresh", thresh)
    cv2.imshow("Thresh_2", thresh_2)
    cv2.imshow("Gray", gray)

    data = pytesseract.image_to_string(gray, lang='eng', config='--psm 6 -c tessedit_char_whitelist=0123456789')
    data_2 = pytesseract.image_to_string(thresh_2, lang='eng', config='--psm 6 -c tessedit_char_whitelist=0123456789')
    return data, data_2

Can anyone help me in pre-processing the images before feeding them to tesseract?

python

opencv

python-tesseract

image-preprocessing

0 Answers

Your Answer

Accepted video resources