0

I am using python 2.7 with OpenCV and PIL Running on windows 10

I am trying to get an image written with cv2.imwrite() like follow Code:

  x={{"Some Process On an Image "}}
  #now saving the effects on real image
  cv2.imwrite("temp.png", x) 

now I am trying to get the text from the same image with pytesseract and need to open the image with the PIL library within another calss becuase the pytesseract doesnt deal with cv2 images

from PIL import Image
import pytesseract
import cv2

if __name__ == '__main__':

     url= Image.open("temp.png")
     cv2.waitKey(200)
     text=pytesseract.image_to_string(url)
     print text
     cv2.waitKey(0)

and Gave Me this Error:

    Traceback (most recent call last):
  File "C:\Users\Elie MA\Documents\NetBeansProjects\tesser\src\new_module.py", line 9, in <module>
    text=pytesseract.image_to_string(url)
  File "build\bdist.win32\egg\pytesseract\pytesseract.py", line 161, in image_to_string
  File "build\bdist.win32\egg\pytesseract\pytesseract.py", line 94, in run_tesseract
  File "c:\Python27\lib\subprocess.py", line 711, in __init__
    errread, errwrite)
  File "c:\Python27\lib\subprocess.py", line 948, in _execute_child
    startupinfo)
WindowsError: [Error 2] The system cannot find the file specified

why I cant get the image ? is there any access rights or something ? It can be showed with this Code:

  url="temp.png"
  cv2.imshow("temp_photo",url)

I want to know why PIL cannot get the image ?

With the knowledge that this image can be opened with photo viewer also So Any one can Help Me?

Jeru Luke
  • 20,118
  • 13
  • 80
  • 87
Mohammed Ali
  • 1,117
  • 1
  • 16
  • 31
  • You can [convert between numpy and PIL images](http://stackoverflow.com/a/1095878/3962537) without having to go through a file. Otherwise, some issue with current path getting changed? What if you use an absolute path for the file name? – Dan Mašek May 15 '16 at 18:40
  • What's the entire backtrace you get with that error? Could this be a [duplicate of this question](http://stackoverflow.com/questions/35131304/pytesseract-error-message-windowserror-error-2-the-system-cannot-find-the-fi)? – Dan Mašek May 15 '16 at 18:52
  • Yeah, you're mixing things up because you both open the image and invoke tesseract in one statement. This is a problem with pytesseract being unable to run the tesseract binary. Definitely a duplicate. – Dan Mašek May 15 '16 at 18:58
  • Please update your question with 1) the complete script (so we can see what's on line 25), and 2) those backtraces, properly formatted, so they are readable? Then clean up all those excess comments, this is becoming a bit of a mess. But the error is again coming from the place where you invoke tesseract, not from where you open the image. – Dan Mašek May 15 '16 at 19:11
  • Ok, so now it should be clear that the problem is with pytesseract unable to finding the tesseract binary, and not PIL. – Dan Mašek May 15 '16 at 19:26

0 Answers0