Using PyTesseract method pytesseract.image_to_osd
I find the error quoted before:
FileNotFoundError: [Errno 2] No such file or directory: 'D:\...........\AppData\Local\Temp\tess_467d8rol.osd'
This is the code I am using:
# import the necessary packages
import argparse
import imutils
import cv2
import pytesseract
from pytesseract import Output
# construct the argument parser and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--image", type=str, default="img.png",
help="path to the input image")
args = vars(ap.parse_args())
# load the image and show it
image = cv2.imread(args["image"])
cv2.imshow("Original", image)
# Here, I can have the info that I want
# In this case I want to know if my image is rotated, if so, what is the angle of rotation.
results = pytesseract.image_to_osd(image, output_type=Output.DICT, config="--psm 4 --dpi 300")
print(results)
# use our imutils function to rotate an image 180 degrees
rotated = imutils.rotate(image, 180)
cv2.imshow("Rotated by 180 Degrees", rotated)
cv2.waitKey(0)
Just to notice that if I do not use the configuration of "--dpi 300" I receive the following error as well:
pytesseract.pytesseract.TesseractError: (1, 'UZN file D:\Usuarios\wrodriguez\AppData\Local\Temp\tess_l9s298s0 loaded.
Estimating resolution as 295 UZN file D:\Usuarios\wrodriguez\AppData\Local\Temp\tess_l9s298s0 loaded.
Warning. Invalid resolution 0 dpi. Using 70 instead. Too few characters. Skipping this page Error during processing.')
NOTE: These are the versions I am using:
python
= "^3.10"pytesseract
= "^0.3.9"imutils
= "^0.5.4"opencv-contrib-python
= "^4.6.0"opencv-python
= "^4.6.0"
Why am I using both opencv-contrib-python
and opencv-pyhon
? Because it is still not clear to me what are the differences between them. And the problem is not there, even though I am sure that using both is not correct.