i'm trying to setup a simple OCR with python, I'm now doing tests. I use notepad++, Python 3.10.1, PIP, Pillow, pytesseract. This is my code :
import pytesseract
import numpy
from PIL import Image, ImageEnhance, ImageFilter
pytesseract.pytesseract.tesseract_cmd = 'Lib/site-packages/pytesseract/pytesseract.py'
im = Image.open(r"C:\Users\Leonid\AppData\Local\Programs\Python\Python310\Lib\site-packages\pytesseract\test.jpg") # Ouverture du fichier image
# Filtrage (augmentation du contraste)
im = im.filter(ImageFilter.MedianFilter())
enhancer = ImageEnhance.Contrast(im)
im = enhancer.enhance(2)
im = im.convert('1')
# Lancement de la procédure de reconnaissance
text = pytesseract.image_to_string(im)
print(text)
When I execute the code, i get this error :
Traceback (most recent call last):
File "C:\Users\Leonid\Desktop\Python\test.py", line 15, in <module>
text = pytesseract.image_to_string(im)
File "C:\Users\Leonid\AppData\Local\Programs\Python\Python310\lib\site-packages\pytesseract\pytesseract.py", line 416, in image_to_string
return {
File "C:\Users\Leonid\AppData\Local\Programs\Python\Python310\lib\site-packages\pytesseract\pytesseract.py", line 419, in <lambda>
Output.STRING: lambda: run_and_get_output(*args),
File "C:\Users\Leonid\AppData\Local\Programs\Python\Python310\lib\site-packages\pytesseract\pytesseract.py", line 286, in run_and_get_output
run_tesseract(**kwargs)
File "C:\Users\Leonid\AppData\Local\Programs\Python\Python310\lib\site-packages\pytesseract\pytesseract.py", line 257, in run_tesseract
raise e
File "C:\Users\Leonid\AppData\Local\Programs\Python\Python310\lib\site-packages\pytesseract\pytesseract.py", line 254, in run_tesseract
proc = subprocess.Popen(cmd_args, **subprocess_args())
File "C:\Users\Leonid\AppData\Local\Programs\Python\Python310\lib\subprocess.py", line 966, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "C:\Users\Leonid\AppData\Local\Programs\Python\Python310\lib\subprocess.py", line 1435, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
OSError: [WinError 193] %1 n’est pas une application Win32 valide
I tried to install numpy cause i've seen on forums that it solves the problem, and import it ("Import numpy" , line 2). But it still don't work.
What can cause this error and how to fix it?