Extract digit from noisy image
I want to extract text from an image taken by mobile phone camera. First I try to convert the image to greyscale by using this code:
imgg = Image.open('originale.jpg').convert('LA')
Second i try to threshold the grey image to get image with only black and white with this code ::
retval, threshold = cv2.threshold(grayscaled, 0, 255, cv2.THRESH_BINARY | cv2.THRESH_OTSU)
cv2.imwrite("threshold.png", threshold)
Third i try to extract text with pytesseract but i have not the correct result with this code.
result5 = pytesseract.image_to_string(Image.open("threshold.png"))
This is the image which I want to extract digits number for example:
My expected output is: 111 2 11 4 1 23 2 3
.
and this is my image :
And this is my full code:
import cv2
import numpy as np
import pytesseract
from PIL import Image
img = cv2.imread('originale.jpg')
grayscaled = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
retval, threshold = cv2.threshold(grayscaled, 0, 255, cv2.THRESH_BINARY | cv2.THRESH_OTSU)
cv2.imwrite("threshold.png", threshold)
result = pytesseract.image_to_string(Image.open("threshold.png"))
print(result)