Using various methods I have changed an image captcha to look somewhat like this
However while using Pytesseract OCR, the package is unable to identify any character and I think it is due to the line above the letters.
script.py
cv2.imwrite(filename, imgOP)
text = pytesseract.image_to_string(Image.open(filename))
Output in the console for the image is none
However when tried with another image (given below) I got the output as
PGKQKf
Which is wrong again because of the line above the letter T
I have used various techniques to clean the images such as erosion, dilation and also Probabilistic Hough Transform (result given below)
#Hough Line Transform
img = cv2.imread('Output1.png')
edges = cv2.Canny(img, 1000, 1500)
minLineLength = 0
maxLineGap = 10000000000
lines = cv2.HoughLinesP(edges, 1, np.pi / 180, 15, minLineLength, maxLineGap)
for x in range(0, len(lines)):
for x1, y1, x2, y2 in lines[x]:
cv2.line(img, (x1, y1), (x2, y2), (255, 255, 255), 2)
cv2.imwrite('houghlines3.jpg', img)
where the image after transformation looks somewhat like this
Any other combination of values of minLineLength and maxLineGap do not work.
How should one proceed forward? I had checked on various techniques to make Tesseract more accurate however I am confused as to which one should I use.
Other than Tesseract are there any other techniques that could be applied to get the desired the results.
I had thought of creating a mask, where using an online tool I had converted the image into 0 and 1 given below. However how to go about it and use it for identifying the characters ?