I m trying to use image_to_osd function of tesseract but I got this error for python 3.6, but when I test the same script in an other environment with python 3.8 it works !!, is there any configuration for python 3.6 or anything to do ?
angle_rotated_image = re.search('(?<=Rotate: )\d+',pytesseract.image_to_osd(rotated)).group(0)
error:
angle_rotated_image = re.search('(?<=Rotate: )\d+',pytesseract.image_to_osd(rotated)).group(0)
File "C:\Users\username\AppData\Roaming\Python\Python36\site-packages\pytesseract\pytesseract.py", line 543, in image_to_osd
}[output_type]()
File "C:\Users\username\AppData\Roaming\Python\Python36\site-packages\pytesseract\pytesseract.py", line 542, in <lambda>
Output.STRING: lambda: run_and_get_output(*args),
File "C:\Users\username\AppData\Roaming\Python\Python36\site-packages\pytesseract\pytesseract.py", line 287, in run_and_get_output
run_tesseract(**kwargs)
File "C:\Users\username\AppData\Roaming\Python\Python36\site-packages\pytesseract\pytesseract.py", line 263, in run_tesseract
raise TesseractError(proc.returncode, get_errors(error_string))
pytesseract.pytesseract.TesseractError: (1, 'Tesseract Open Source OCR Engine v5.0.0.20190623 with Leptonica Warning: Invalid resolution 0 dpi. Using 70 instead. Estimating resolution as 163 Warning. Invalid resolution 0 dpi. Using 70 instead. Too few characters. Skipping this page Error during processing.')
I ran into a similar problem when trying to determine rotation of a given document and trying to use pytesseract's image_to_osd(). It was working fine for me on MacOS with tesseract 4.1.1, but it wouldn't work on Windows with tesseract 5.0.0-alpha. After reading through many threads on the topic related to the OP's error and trying various things like passing --dpi and -c min_chararacters_to_try= with no success, I finally tried using a different version of tesseract on Windows, which finally solved my problem.
Status of image_to_osd():
(PASS) OS MacOS; tesseract 4.1.1; pytesseract 0.3.0; Python 3.6.5
(PASS) OS Windows; tesseract 4.1.0; pytesseract 0.3.0; Python 3.6.5
(FAIL) OS Windows; tesseract 5.0.0; pytesseract 0.3.0; Python 3.6.5
I think pytesseract 0.3.7 will probably work too, but I didn't test it.
Note that you can still get OP's error with this, but from what I tested it's much more reasonable now, e.g., with blank pages.
Related
For the past several weeks I have been using videowriter.write() and it has been working fine. I needed to give the program to several coworkers that have random python installations so I packaged it up in pyinstaller, which I have used successfully on other projects.
Almost everything seems to be working fine when run under pyinstaller, I can read images, capture images from the camera, show them on the screen, and write out individual images. The problem is that when I use videowriter.write() somewhere down in the bowels of the code it crashes, complaining that the images have the incorrect size. This only happens when running under pyinstaller, not when running it directly from python.
Below is a portion of the code that I extracted with a generated test image. A coworker tried to run the same example, using his copy of opencv, python, and pyinstaller and his executable seems to work. I spent the last several days trying to duplicate that setup but I don't get the same results. I have completely removed python 3 (I have a copy of 2.7 that is specifically for other tests), cleared the pip cache, cleared environment variables, and made sure all the python directories were removed prior to re-installation. I have tried python back to 3.7, different versions of opencv 4.1 through current, and all behave the same way. I have also tried using a virtual environment and setting up the core python sitting in Program Files.
The current version of opencv_videoio_ffmpeg is: opencv_videoio_ffmpeg420_64.dll.
The version that my coworker used successfully is opencv_ffmpeg410_64.dll
While it doesn't seem to make much difference, the command I have been using to build the executable is:
pyinstaller videowriter_test.py --onefile
I have also tried it without the --onefile option, it works the same but its a little harder to find the executable.
The python installation has the following installed: opencv-python, opencv-contrib-python, imutils, pynput, keyboard, virtualenv, pyinstaller. These were all installed using pip.
pyinstaller stats:
129 INFO: PyInstaller: 3.6
129 INFO: Python: 3.7.7
131 INFO: Platform: Windows-10-10.0.18362-SP0
133 INFO: wrote C:\Users\tbray\Desktop\MyProjects\Python3\Play\videowriter\videowriter_test.spec
137 INFO: UPX is not available. 139 INFO: Extending PYTHONPATH with paths
The test code:
import traceback
import cv2
import numpy as np
import imutils
# the rest are just there to make sure pyinstaller includes the same modules
# as my regular code
import copy
import platform
import pathlib
import select
import argparse
import warnings
import datetime
import json
import time
if __name__ == '__main__':
w = 640
h = 480
currentVideoLogFilename = "test.avi"
print(os.getenv('temppath'))
try:
print("Attempting to open Video Log:", currentVideoLogFilename)
video_log_file = cv2.VideoWriter(currentVideoLogFilename,
cv2.VideoWriter_fourcc('M', 'J', 'P', 'G'), 30, (w, h),True)
print("Open Success")
except:
traceback.print_exc()
print("Test Image Shape:", w, h)
image = np.zeros((w, h, 3))
try:
video_log_file.write(image)
except:
traceback.print_exc()
print("Completed")
video_log_file.release()
print("file closed/released")
sys.exit(0)
If I run the using idle or pyCharm, I get this result:
================== RESTART: C:\Users\tbray\Desktop\MyProjects\Python3\Play\videowriter\videowriter_test.py ==================
None
Attempting to open Video Log: test.avi
Open Success
Test Image Shape: 640 480
Completed
file closed/released
>>>
if I run it from the virtual environment I get:
C:\Users\tbray\Desktop\MyProjects\Python3\Play\videowriter\dist>videowriter_test.exe
None
Attempting to open Video Log: test.avi
[ERROR:0] global C:\projects\opencv-python\opencv\modules\videoio\src\cap.cpp (415) cv::VideoWriter::open VIDEOIO(CV_IMAGES): raised OpenCV exception:
OpenCV(4.2.0) C:\projects\opencv-python\opencv\modules\videoio\src\cap_images.cpp:253: error: (-5:Bad argument) CAP_IMAGES: can't find starting number (in the name of file): test.avi in function 'cv::icvExtractPattern'
Open Success
Test Image Shape: 640 480
Traceback (most recent call last):
File "videowriter_test.py", line 39, in <module>
cv2.error: OpenCV(4.2.0) C:\projects\opencv-python\opencv\modules\videoio\src\cap_mjpeg_encoder.cpp:476: error: (-215:Assertion failed) imgWidth == frameWidth && imgHeight == frameHeight && channels == 3 in function 'cv::mjpeg::MotionJpegWriter::write'
Completed
file closed/released
One interesting note is what I assume is the temp directory that is referenced in the first error message. I have no idea where the directory comes from and what happens to it, it is missing when I go looking for it.
Any suggestions?
I am running Python 3.6 in Spyder/Anaconda, I am trying to use enchant. I installed pyenchant using
pip install pyenchant
I also installed aspell using
sudo apt-get install aspell-en
I am executing in Python:
import enchant
print("The dict is", enchant.list_languages())
slownik = enchant.Dict("en_US")
I keep getting an error:
File
"/home/grzegorz/anaconda3/lib/python3.6/site-packages/enchant/init.py",
line 562, in init
_EnchantObject.init(self)
File
"/home/grzegorz/anaconda3/lib/python3.6/site-packages/enchant/init.py",
line 168, in init
self._init_this()
File
"/home/grzegorz/anaconda3/lib/python3.6/site-packages/enchant/init.py",
line 569, in _init_this
this = self._broker._request_dict_data(self.tag)
File
"/home/grzegorz/anaconda3/lib/python3.6/site-packages/enchant/init.py",
line 310, in _request_dict_data
self._raise_error(eStr % (tag,),DictNotFoundError)
File
"/home/grzegorz/anaconda3/lib/python3.6/site-packages/enchant/init.py",
line 258, in _raise_error
raise eclass(default)
DictNotFoundError: Dictionary for language 'en_US' could not be found
And the printout is:
The dict is []
so no dictionaries are being loaded. It seems that enchant does not know where the aspell dictionaries are located.
I tried numerous variations of
enchant.set_param("enchant.aspell.dictionary.path","/aspell") enchant.set_param("enchant.myspell.dictionary.path","/usr/bin/aspell")
What may be relevant: this simple code worked before I upgraded to Ubuntu 17.10 (from 17.4), so I somehow got enchant to work then, but it was long ago and I cannot recreate what I did differently when installing enchant back then. I have also updated Spyder to the latest version, one of those operations clearly caused the code to break. I was updating Spyder in the past and it did not cause any problems, so I am suspecting that during the system update something important got deleted/moved.
I found answers for people with similar issues on MacOS, but the answers I found do not work on Ubuntu.
Any help would be greatly appreciated.
Temporary solution - downgrade to Python 3.5. It seems that pyenchant 1.6.11 is not Python 3.6 compatible and that it only tries to import Hspel (Hebrew) library when used with Python 3.6. I would love to be able to use the newest Python, so the issue is not resolved, but that is the best (and only) solution so far.
Python 3.5 on Windows 10, 32-bit box; all I want to do is run this:
import quandl
import pandas as pd
import html5lib
import lxml
# retrieve web page with list of 50 states
fiddy_states = pd.read_html('https://simple.wikipedia.or /wiki/List_of_U.S._states')
But for the life of me I can't seem to get a properly installed lxml, which is required by pd.read_html. Following advice from several online sources I have MinGW installed in my system and I have also added the following to C:\Python35-32\Lib\distutils\distutils.cfg:
[build]
compiler=mingw32
I have MinGW installed and included in PATH. I have tried installing lxml using both pip3 as well as the binaries found at Unofficial Windows Binaries for Python Extension Packages.
Here's all installed packages:
['beautifulsoup4==4.4.1', 'cffi==1.6.0', 'cryptography==1.3.2', 'cycler==0.10.0', 'cython==0.24', 'html5lib==0.9999999', 'idna==2.1', 'inflection==0.3.1', 'lxml==3.4.4', 'matplotlib==1.5.1', 'more-itertools==2.2', 'ndg-httpsclient==0.4.0', 'numpy==1.11.0', 'pandas-datareader==0.2.1', 'pandas==0.18.1', 'pip==8.1.2', 'pyasn1==0.1.9', 'pycparser==2.14', 'pyopenssl==16.0.0', 'pyparsing==2.1.4', 'python-dateutil==2.5.3', 'pytz==2016.4', 'quandl==3.0.1', 'requests-file==1.4', 'requests==2.10.0', 'scikit-learn==0.17.1', 'setuptools==18.2', 'six==1.10.0']
As shown above, lxml==3.4.4 appears to be installed, however when I try to run the line containing pd.read_html I get the following error message:
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "C:\Users\Jose Manuel\AppData\Local\Programs\Python\Python35-32 \lib\site-packages\pandas\io\html.py", line 874, in read_html
parse_dates, tupleize_cols, thousands, attrs, encoding)
File "C:\Users\Jose Manuel\AppData\Local\Programs\Python\Python35-32\lib\site-packages\pandas\io\html.py", line 726, in _parse
parser = _parser_dispatch(flav)
File "C:\Users\Jose Manuel\AppData\Local\Programs\Python\Python35-32\lib\site-packages\pandas\io\html.py", line 685, in _parser_dispatch
raise ImportError("lxml not found, please install it")
ImportError: lxml not found, please install itenter code here
Your help is very much appreciated
I have been struggling with this today. I found, elsewhere on stackoverflow.com, this two-part and quick solution, which resulted in python no longer complaining when I tried to use lxml:
go to this repository and download a version which matches your Python installation (the version number, and 32- vs 64-bit. I use Python 3.5.1 64-bit, installed on Windows 10, so on that page, I chose lxml-3.6.0-cp35-cp35m-win_amd64.whl. You say you have 32-bit Python, so use a version that matches that (like lxml-3.6.0-cp35-cp35m-win32.whl.
My download directory is d:\Downloads. Python must be in your PATH environment variable for the next step to work. Use a command like the following, changing "D:\Downloads" to the pathname to your download directory. Then, at a DOS prompt, type:
python -m pip install "D:\Downloads\lxml-3.6.0-cp35-cp35m-win_amd64.whl" lxml-3.6.0-cp35-cp35m-win_amd64.whl
I am attempting to develop a component for 64 bit Redhawk that uses a 32 bit Python binary, but am not sure how to configure Redhawk use 32 bit Python instead of 64 bit Python when running this particular component. The reason I need to use 32 bit Python is because I am using a library (PyVisa, http://pyvisa.readthedocs.org/en/latest/) that only works with 32 bit Python (see https://decibel.ni.com/content/docs/DOC-2928).
I am using PyVisa to control lab equipment (i.e. Agilent signal generators) in order to a calibrate a receiver. I understand this may seem like a odd use of Redhawk, but tuning sig gens to a certain freq and power level is very similar to operations that need to be performed when controlling a receiver/transmitter as well.
I would rather not install 32 bit CentOS just to develop and test this 1 component and I'm assuming it will be equally troublesome to simultaneously install 32 bit and 64 bit Redhawk rpms on my system.
I have already installed 32 bit Python simultaneously with 64 bit Python on my system and have manually renamed the 32 bit Python binary to be "python_32" and placed it on the path (/usr/bin/). I tried to force Redhawk to use the 32 bit Python executable by changing the shebang at the top of my implementation file to
#!/usr/bin/env python_32
However, it didn't work, so then I tried
#!/usr/bin/python_32
which also didn't work.
See example below for a skeleton implementation, with all the boilerplate imports and function defs removed for clarity.
#!/usr/bin/python_32
import visa
def process(self):
sg = visa.instrument("TCPIP::10.2.8.236")
print sg.ask("*IDN?")
return NORMAL
Each time I attempt to launch a simple waveform containing this component, I receive the error below. This is the same error I receive when trying to use the PyVisa libary in 64 bit Python, which is why I think Redhawk is ignoring my shebang statements specifying the path to 32 bit Python.
OSError: /usr/local/vxipnp/linux/bin/libvisa.so.7: wrong ELF class: ELFCLASS32
Traceback (most recent call last):
File "/var/redhawk/sdr/dev/.DevMgr_orion/GPP_orion/components/sendSCPI/python/sendSCPI.py", line 9, in <module>
import visa
File "/usr/lib/python2.6/site-packages/PyVISA-1.5.dev0.dev-py2.6.egg/visa.py", line 237, in <module>
resource_manager = ResourceManager()
File "/usr/lib/python2.6/site-packages/PyVISA-1.5.dev0.dev-py2.6.egg/vpp43.py", line 85, in __new__
it.init(*args, **kwds)
File "/usr/lib/python2.6/site-packages/PyVISA-1.5.dev0.dev-py2.6.egg/visa.py", line 230, in init
self.session = self.vi = vpp43.open_default_resource_manager()
File "/usr/lib/python2.6/site-packages/PyVISA-1.5.dev0.dev-py2.6.egg/vpp43.py", line 788, in open_default_resource_manager
visa_library().viOpenDefaultRM(byref(session))
File "/usr/lib/python2.6/site-packages/PyVISA-1.5.dev0.dev-py2.6.egg/vpp43.py", line 162, in __call__
self.load_library()
File "/usr/lib/python2.6/site-packages/PyVISA-1.5.dev0.dev-py2.6.egg/vpp43.py", line 131, in load_library
self.__lib = self.__cdecl_lib = cdll.LoadLibrary(path)
File "/usr/lib64/python2.6/ctypes/__init__.py", line 431, in LoadLibrary
return self._dlltype(name)
File "/usr/lib64/python2.6/ctypes/__init__.py", line 353, in __init__
self._handle = _dlopen(self._name, mode)
OSError: /usr/local/vxipnp/linux/bin/libvisa.so.7: wrong ELF class: ELFCLASS32
For reference I am running Redhawk version 1.9.0. x64 on CentOS 6.4 x64.
If there is a better way to control my lab equipment through Redhawk, I'm open to that too.
The <entrypoint> in the component.spd.xml file can be changed to point to a script instead of the component's .py file. This is useful for doing things like setting environment variables for a single component or redirecting to a different program.
Consider this:
Change <entrypoint>python/myComponent.py</entrypoint> to <entrypoint>python/myScript.sh</entrypoint>
Create a script called myScript.sh in the python folder.
Populate myScript.sh with something like:
export PYTHONPATH=$PYTHONPATH # add/change PYTHONPATH (or other environment variables) here
/usr/bin/python_32 python/myComponent.py $*
chmod +x myScript.sh
Modify your autotools files so that the script gets installed correctly (or just copy it by hand)
This approach gives you a little more control over how myComponent.py gets run.
I'm pretty new to Qt, Python and their combinations. I'm currently writing a QGIS plugin in python (I used QtCreator 2.1 (Qt Designer 4.7) to generate a .ui-file and am now trying to use it for a Quantum GIS plugin that's written in Python 2.5 (and running in the Quantum GIS Python 2.5 console)).
I am running into trouble when loading the ui-file dynamically when the program runs the loadUi() function. What throws me off is that the error occurs outside my script. Does that mean, I'm passing something wrong into it? Where does the error come in? Any hints on what could be wrong?
code_dir = os.path.dirname(os.path.abspath(__file__))
self.ui = loadUi(os.path.join(code_dir, "Ui_myfile.ui"), self)
This is the Error Code I am getting (minus the first paragraph):
File "C:/Dokumente und Einstellungen/name.name/.qgis/python/plugins\myfile\myfile_gui.py", line 42, in __ init __
self.ui = loadUi(os.path.join(code_dir, "Ui_myfile.ui"), self)
File "C:\PROGRA~1\QUANTU~1\apps\Python25\lib\site-packages\PyQt4\uic__init__.py", line 112, in loadUi
return DynamicUILoader().loadUi(uifile, baseinstance)
File "C:\PROGRA~1\QUANTU~1\apps\Python25\lib\site-packages\PyQt4\uic\Loader\loader.py", line 21, in loadUi
return self.parse(filename)
File "C:\PROGRA~1\QUANTU~1\apps\Python25\lib\site-packages\PyQt4\uic\uiparser.py", line 768, in parse
actor(elem)
File "C:\PROGRA~1\QUANTU~1\apps\Python25\lib\site-packages\PyQt4\uic\uiparser.py", line 616, in createUserInterface
self.traverseWidgetTree(elem)
File "C:\PROGRA~1\QUANTU~1\apps\Python25\lib\site-packages\PyQt4\uic\uiparser.py", line 594, in traverseWidgetTree
handler(self, child)
File "C:\PROGRA~1\QUANTU~1\apps\Python25\lib\site-packages\PyQt4\uic\uiparser.py", line 233, in createWidget
topwidget.setCentralWidget(widget)
SystemError: error return without exception set
I'm not sure of what could be causing this precise problem, but using .ui files directly has never worked well for me - instead I compile them to python code using pyuic4 (should be in your path if your PyQt4 site-packages are correctly configured. The syntax is along the lines of :-
pyuic4 -o <python output> -x <uic input>
-: resource files can similarly be converted to (not so human-readable) python using :-
pyrrc4 -o <python output> <qrc input>
-: You can then import that python file as a module, not to mention that reading its code can give you clues on how to fiddle with the layout at runtime.
The other upside of this is that you are not having to parse xml at runtime - importing a python module is far quicker and you are not likely to change the ui anywhere near as often as you run the script. If you do find yourself in this situation you can just create a batch to run these before your script/application.
This is the method I use in conjunction with pyInstaller to deploy scripts that will 'just run' on XP, Vista and Windows 7 without modification, and I generate the python modules just before compiling with pyInstaller, so it can be a real time saver.