I have applied the following adjustments to the original image:
- resized
- changed the colour scale
- greyscaled
- thresholded
- inverted the colours
This results in the following image
Using tesseract, i'm converting the image to a string but it only seems to recognise the 4.
Code to convert to text -
print (tess.image_to_string(img, config='--psm 6 -c tessedit_char_whitelist="9876543210"'))
4
I then attempted to sharpen using the following code resulting in the next image, but tesseract is still only recognising the 4. Any idea how I can sharpen this further so tesseract recognises this as 40?
kernel = np.array([[0,-1,0],[-1,5,-1],[0,-1,0]])
sharpened = cv2.filter2D(img,-1,kernel)
print (tess.image_to_string(sharpened, config='--psm 6 -c tessedit_char_whitelist="9876543210"'))
4
Alternatively, the original image is the following without any resizing.
Tesseract does pick this up as 40 but I need it to pick up the larger image. Is there a way I can resize but retain the quality/sharpness?
Resizing code -
img = cv2.resize(img,(0,0),fx=5,fy=5)
If you have the possibility to use
ImageMagic
:Output:
Option 2: With
OpenCV
, what you prefer.Output: