Search code examples
python-2.7opencvimage-processingocrpytesser

Python Ocr Licence Plate Recognition


I tried converting the image into gray with adaptive threshold and Thesh_Binary_Inv

gray = cv2.cvtColor(img1,cv2.COLOR_BGR2GRAY)
adapt1 = cv2.adaptiveThreshold(gray,130,cv2.ADAPTIVE_THRESH_GAUSSIAN_C,cv2.THRESH_BINARY_INV,153,40)

and trying to get the license plate using pytesser but got some random values as output

can anyone help me out with extracting text from images and where to find tutorial on how to train using kmeans or any other algorithm


Solution

  • When extracting text from the image try looking at the images as if you were trying to see the text as clearly as possible. My Professor used to say: if human can see it, computer can see it too. What you want to do is basically perform basic preprocessing algorithms like contrast enhancement, color space conversion if needed, etc. What you want to acquire before thresholding is an image as crisp as possible, where there is no doubt about the characters and where the edge between the character and the white background is as apparent as possible.

    You need to experiment with the thresholding operation. At the beginning I recommend using the simple, fixed threshold function with a trackbar, so that you don't have to rerun the code everytime you want to change the value. You can find the code on here, on my GitHub repo. Of course that's only one of the steps. You still need to find the area that's of interest to you and the characters. What you want to look at for those steps is probably contour finding.

    The training part will be even trickier. There is a beautiful entry-level tutorial on K-means here but I would guess that you're not really sure what to do with it. I'm not sure what to recommend here, as Machine Learning might be a little too hard for you before you got the basics. Anyway, if I were to do it, I'd probably go for Deep Learning but you need to know that the testing data and how you prepare it will be crucial in the process. Here's a very simple tutorial, that might give you an idea of what's going on.

    Raaj, please remember that if you expect people to put effort into helping you, it's good manners to first put effort into asking. You have to explain better what did you try, where did you look, what results you got and what do you expect from us. Images, I'd say, are a must in your case and you didn't even bother to provide those. Good luck!