Reputation: 1
This is the image in the code above and nothing is outputed
I am using pytesseract and opencv to recognize the text on license plate, however alot of times when i run the code below no text is outputted for the images i use
import cv2
import imutils
import numpy as np
import pytesseract as tess
tess.pytesseract.tesseract_cmd =r'C:\Users\raul__000\AppData\Local\Tesseract-OCR\tesseract.exe'
# read image file
img = cv2.imread("Plate_images/plate14.jpg")
cv2.imshow("Image", img)
cv2.waitKey(0)
# RGB to Gray scale conversion
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
cv2.imshow("1 - Grayscale Conversion", gray)
cv2.waitKey(0)
# Noise removal with iterative bilateral filter(removes noise while preserving edges)
gray = cv2.bilateralFilter(gray, 11, 17, 17)
cv2.imshow("2 - Bilateral Filter", gray)
cv2.waitKey(0)
# thresholding the grayscale image
gray = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)[1]
cv2.imshow("3 - Thresh Filter", gray)
cv2.waitKey(0)
# Dilation adds pixels to the boundaries of objects in an image
kernel = np.ones((5,5),np.uint8)
gray = cv2.dilate(gray, kernel, iterations = 1)
cv2.imshow("4 - dilation Filter", gray)
cv2.waitKey(0)
# use tesseract to convert image to string
text = tess.image_to_string(gray, lang="eng", config='--psm 6')
print(text)
This is the image in the code above and nothing is outputed
Upvotes: 0
Views: 1057
Reputation: 1551
Your 4th step is removing all the text from the image
You should be able to see that when using cv2.imshow("4 - dilation Filter", gray)
If you remove the third step and run tesseract you should see output.
Upvotes: 1