Issue
I am using OCR for extracting text and its co-ordinates(bounding boxes) from the image.image_to_string is working all fine but image_to_data outputs the error and it is required for extracting the bounding box of the texts. Any idea why this may be happening? I am using windows 10 for this.
import pytesseract
import cv2
pytesseract.pytesseract.tesseract_cmd = 'C:/Users/Anwer/AppData/Local/Tesseract-OCR/tesseract.exe'
from PIL import Image
from pytesseract import image_to_data
img = cv2.imread('C:/Users/Anwer/Desktop/Density Plot.png', 1)
cv2.imwrite("Graph.jpeg",img)
img=Image.open('Graph.jpeg')
d=image_to_data(img,output_type=Output.DICT)
n_boxes = len(d['level'])
for i in range(n_boxes):
(x, y, w, h) = (d['left'][i], d['top'][i], d['width'][i], d['height'][i])
cv2.rectangle(img, (x, y), (x + w, y + h), (0, 255, 0), 2)
cv2.imshow('img', img)
cv2.waitKey(0)
I expect the result to output me bounding boxes co-ordinates but the image_to_data function is not being imported. Infact no function other than image_to_string is being imported.
Solution
Okay I got the issue fixed by myself. I had a tesseract version of 4.0. I uninstalled it and then installed the older tesseract version of 3.05.02. After that,everything seemed to work fine. Also, once doing this please uninstall and install the pytesseract also.
Answered By - Saad Anwar
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.