0

I am using pytesseract to extract text from an image.


from PIL import Image
from pytesseract import image_to_string, image_to_boxes, image_to_data


img = Image.open('device.png')

print(image_to_boxes(img))

print(image_to_data(img))

print(image_to_string(img))

This is my image and i want to extract data from the image. enter image description here

I have started with the above code and output from the first two print statements is:

~ 0 0 0 0 0
level   page_num        block_num       par_num line_num        word_num        left    top     width   height  conf    text
1       1       0       0       0       0       0       0       1027    742     -1      
2       1       1       0       0       0       0       0       0       742     -1      
3       1       1       1       0       0       0       0       0       742     -1      
4       1       1       1       1       0       0       0       0       742     -1      
5       1       1       1       1       1       0       0       0       742     95

The third print statement doesn't give output or rather a null output. I am confused if I am going wrong somewhere? Is this the correct way to use OCR to extract text from image

chink
  • 1,505
  • 3
  • 28
  • 70
  • You need to crop the text from the image then run tesseract to convert it to text. It will not simply convert all text in the image when it has noisy background. – jose_bacoy Jun 18 '19 at 14:51
  • Thanks @âńōŋŷXmoůŜ. can you help with anything on how to crop the text from image? – chink Jun 18 '19 at 15:08
  • you can use crop_rectangle = (20, 320, 400, 400) cropped_im = img.crop(crop_rectangle) – ProgSMI Feb 23 '20 at 20:20

0 Answers0