from PIL import Image
from pytesser import *
image_file = 'D:\plate.jpg'
im = Image.open(image_file)
text = image_to_string(im)
text = image_file_to_string(image_file)
text = image_file_to_string(image_file, graceful_errors=True)
print "=====output=======\n"
print text
it gets me error that
C:\Users\KEN\Anaconda2\python.exe C:/Users/KENIL/PycharmProjects/plate/ocr.py
Traceback (most recent call last):
File "C:/Users/KEN/PycharmProjects/plate/ocr.py", line 2, in <module>
from pytesser import *
File "C:\Users\KEN\PycharmProjects\plate\pytesser.py", line 6, in <module>
import Image
ImportError: No module named Image
even though i have installed ananconda properly as well as pillow screenshot of package installed
The code you posted doesn't have the error. From the error message it seems that the error is in the module pytesser.py, where you probably use Image (in line 6 :-) ) without importing it.
Related
Till 1 hour back my opencv code was working perfectly fine. it could run my script without error. but I don't know why some time back suddenly it started giving me this error:
AttributeError: partially initialized module 'cv2' has no attribute 'imread' (most likely due to a circular import)
Traceback (most recent call last):
File "FACEDETECTION.PY", line 1, in <module>
import cv2
File "C:\Users\Lenovo\anaconda3\envs\CAM\lib\site-packages\cv2\__init__.py", line 5, in <module>
from .cv2 import *
ImportError: numpy.core.multiarray failed to import
So what could be the error?
update: Here is my code-
import cv2
import pytesseract
pytesseract.pytesseract.tesseract_cmd = "C:\\Program Files (x86)\\Tesseract-OCR\\tesseract.exe"
path = "text.png"
img = cv2.imread(path)
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
text = pytesseract.image_to_string(img)
print(text)
cv2.imshow("name", img)
cv2.waitKey(7000)
I used the Tifffile module's imshow () method to display the tiff image in Python 3.5.2.
The code is as follows:
import tifffile as tiff
IM_ID = '6120_2_2'
im_rgb = tiff.imread('/home/roy/image&csv/image/{}.tif'.format(IM_ID)).transpose([1, 2, 0])
im_size = im_rgb.shape[:2]
tiff.imshow(im_rgb)
But there is an error:
Traceback (most recent call last):
File "/home/roy/PycharmProjects/CSV2Ploy/csv2ploy.py", line 49, in <module>
tiff.imshow(im_rgb)
File "/usr/local/lib/python3.5/dist-packages/tifffile/tifffile.py", line 6349, in imshow
pyplot = sys.modules['matplotlib.pyplot']
KeyError: 'matplotlib.pyplot'
I think it must be my development environment missing the matplotlib.pyplot module. So I checked the matplotlib directory, but found that the directory does have pyplot.py file.
The terminal queries the pyplot.py file
I have a lot of information on the Internet, but most are import matplotlib.pyplot problems, some people can help me solve this problem?
I'm trying to write an OCR script with Python (2.7, Windows OS) to get text from images. First I've downloaded PyTesser and extracted it to Python27/Lib/site-packages as 'pytesser' and I've installed tesseract with pip install tesseract . Then I wrote the following script as self.py:
from PIL import Image
from pytesser.pytesser import *
image_file = 'C:/Users/blabla/test.png'
im = Image.open(image_file)
text = image_to_string(im)
text = image_file_to_string(image_file)
text = image_file_to_string(image_file, graceful_errors=True)
print text
But I'm getting the following error:
Traceback (most recent call last):
File "C:/Users/blabla/self.py", line 7, in <module>
text = image_file_to_string(image_file)
File "C:\Python27\lib\site-packages\pytesser\pytesser.py", line 44, in image_file_to_string
call_tesseract(filename, scratch_text_name_root)
File "C:\Python27\lib\site-packages\pytesser\pytesser.py", line 24, in call_tesseract
errors.check_for_errors()
File "C:\Python27\lib\site-packages\pytesser\errors.py", line 10, in check_for_errors
inf = file(logfile)
IOError: [Errno 2] No such file or directory: 'tesseract.log'
And yes, there's no 'tesseract.log' file anywhere. What should I do? How should I solve this problem?
Thank you in advance.
Note: I've changed the line tesseract_exe_name from pytesser.py from tesseract to C:/Python27/Lib/site-packages/pytesser/tesseract but it doesn't work.
Edit: Alright, I've just runned teseract.exe that is in 'pytesser' and it created the 'tesseract.log' file but I'm still getting same error.
I've changed the line from def check_for_errors(logfile = "tesseract.log"): to def check_for_errors(logfile = "C:/Python27/Lib/site-packages/pytesser/tesseract.log"): in ../pytesser/errors.py and it worked.
I am using only PIL then it's work properly when I use pytesser then it doesn't work properly .What can i do for it?
from PIL import Image
from pytesser import *
image_file = Image.open("vote.jpg")
im = Image.open(image_file)
text = image_to_string(im)
print text
Traceback (most recent call last):
File "C:/Users/Tanvir/Desktop/py thon hand/hala.py", line 4, in <module>
image_file = Image.open("vote.jpg")
File "C:\Pythons27\lib\site-packages\PIL\Image.py", line 2286, in open
% (filename if filename else fp))
IOError: cannot identify image file 'vote.jpg'
I am find this solution .It was problem with PIL so at first I have to uninstall this PIL module then again install it and job done Every thing is okay.
I'm using a Raspicam with the SimpleCV framework, when I work on the SimpleCV Shell everything work well. When i work with Python script I have some problems.
When I launch a python script like this:
from SimpleCV import *
cam = Camera(0)
screen = cam.getImage().rotate(180)
screen.save("Code/SimpleCV/SimpleCV/app/screen2.jpg")
everything work.
But when i set the format 1280X1024 with a code like this:
from SimpleCV import *
cam = Camera(0, {"width":1280, "height":1024})
screen = cam.getImage().rotate(180)
screen.save("Code/SimpleCV/SimpleCV/app/screen2.jpg")
I receive this error:
ERROR:
Traceback (most recent call last):
File "Code/SimpleCV/SimpleCV/app/getimm.py", line 5, in <module>
cam.getImage().save("Code/SimpleCV/SimpleCV/app/screen2.jpg")
File "/home/pi/Code/SimpleCV/SimpleCV/Camera.py", line 618, in getImage
cv.GrabFrame(self.capture)
TypeError: Expected CvCapture for argument 'capture'
Thanks