I'm trying to run a python code on my Raspberry Pi, in which I get from some tutorial. I followed everything there; installed the necessary packages or library in order for me to run the script.
The first one:
sudo apt-get install tesseract-ocr
And I get these following messages.
Reading package lists... Done
Building dependency tree
Reading state information... Done tesseract-ocr is already the newest
version (4.0.0-2).
The following package was automatically installed and is no longer
required: python-colorzero
Use 'sudo apt autoremove' to remove it.
0 upgraded, 0 newly installed, 0 to remove and 1 not upgraded.
Proof here:Screen shot 1
The second one is this:
pip3 install pytesseract
I changed pip to pip3, since I read somewhere that pip is already obsolete. And so, I get these messages:
Looking in indexes: https://pypi.org/simple,
https://www.piwheels.org/simple
Requirement already satisfied: pytesseract in
/usr/local/lib/python3.7/dist-packages (0.3.8)
Requirement already satisfied: Pillow in
/usr/lib/python3/dist-packages (from pytesseract) (5.4.1)
Proof here:Screenshot 2
And lastly, in order for me to run the script. I install this.
pip3 install pillow
Same as the above one, I also used pip3 in installing pillow. So, I get these messages:
Looking in indexes: https://pypi.org/simple,
https://www.piwheels.org/simple
Requirement already satisfied: pillow in
/usr/lib/python3/dist-packages (5.4.1)
Proof here:Screenshot 3
After installing all the necessary requirements, I tried to run this simple script from the tutorial.
import pytesseract
from PIL import Image
import cv2
img = cv2.imread('platen5.jpeg',cv2.IMREAD_COLOR) #Open the image from which charectors has to be recognized
#img = cv2.resize(img, (620,480) ) #resize the image if required
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) #convert to grey to reduce detials
gray = cv2.bilateralFilter(gray, 11, 17, 17) #Blur to reduce noise
original = pytesseract.image_to_string(gray, config='')
#test = (pytesseract.image_to_data(gray, lang=None, config='', nice=0) ) #get confidence level if required
#print(pytesseract.image_to_boxes(gray))
print (original)
Unfortunately, I still get this syntax error thing though. The only thing I changed from the original script is the 'platen5.jpeg', since it is the saved image of a plate number I have on my file.
Here's the error:
Traceback (most recent call last):
File "tut.py", line 1, in
import pytesseract
File "/home/pi/pytesseract/init.py", line 2, in
from .pytesseract import ALTONotSupported
File "/home/pi/pytesseract/pytesseract.py", line 88
f"{tesseract_cmd} is not installed or it's not in your PATH."
SyntaxError: invalid syntax
Proof here: Screenshot 4
I am sorry, I'm kinda new to python, and raspberry pi, so I am very dependent on the tutorials on the internet, so I have no idea in which part I did wrong. Or am I missing something? Or everything from the tutorial are already obsolete so, it doesn't work?
Thanks.
Related
I am trying to get a qrcode with opencv, in order to do this I have the following code:
import cv2
import numpy as np
...
data, bbox,rectifiedImage = qrDecoder.detectAndDecode(frame)
...
The code runs ok, but when detect the QRCode and I want get data, I got this
Library QUIRC is not linked. No decoding is performed. Take it to the OpenCV repository.
I tried with pip install quirc, but doesn't work and I installed opencv with sudo apt-get install python3-opencv.
How can I fix this?
The version of OpenCV you get with the apt package is always fairly old. Additionally, there's no guarantee that all the modules (here: the QR decoder) were given the required dependencies (here: quirc). Installing additional packages wouldn't solve this because OpenCV needs them at build time, before packaging.
To get the most recent version, install it via pip:
$ pip3 install opencv-python
There is the opencv-python package that only contains the main modules, and there is opencv-contrib-python, which additionally contains "contrib" modules. The packages are mutually incompatible, so only install one of them.
My pyautogui program gives me the following error when I do:
position = pyautogui.locateCenterOnScreen(image, confidence=.7)
Error message:
File "C:\Users\ashis\AppData\Local\Programs\Python\Python39\lib\site-packages\pyscreeze\__init__.py", line 144, in wrapper
raise PyScreezeException('The Pillow package is required to use this function.')
pyscreeze.PyScreezeException: The Pillow package is required to use this function.
Other pyautogui functions are working properly only when I do pyautogui.locateCenterOnScreen() gives and error.
I already have pillow properly installed:
Requirement already satisfied: pillow in c:\users\ashis\appdata\local\programs\python\python310\lib\site-packages (9.0.0)
Can anyone help please? I am following a tutorial.
That's a small problem, just update your Pillow package.
pip install Pillow --upgrade
Pillow-4.2.1 was on my system, it upgraded to Pillow-5.1.0 and now everything works just fine.
pip install pyautogui --upgrade
Here, is what worked for me
pip install pyscreeze
then,
import pyscreeze
position = pyscreeze.locateCenterOnScreen(image, confidence=.7)
Thanks,
I am using OpenCV v4.20 and PyCharm IDE. I want to use SIFT algorithm. But I get this error. I looked for solutions of this error on the internet but none of them did help me. Do you know the solution of this error? (With pip I can install at least 3.4.2.16 version of OpenCV)
Here is my error:
Traceback (most recent call last):
File "C:/Users/HP/PycharmProjects/features/featuredetect.py", line 7, in
sift = cv.xfeatures2d_SIFT.create()
cv2.error: OpenCV(4.2.0) C:\projects\opencv-python\opencv_contrib\modules\xfeatures2d\src\sift.cpp:1210: error: (-213:The function/feature is not implemented) This algorithm is patented and is excluded in this configuration; Set OPENCV_ENABLE_NONFREE CMake option and rebuild the library in function 'cv::xfeatures2d::SIFT::create'
Here is my code:
import cv2 as cv
image = cv.imread("the_book_thief.jpg")
gray_image = cv.cvtColor(image,cv.COLOR_BGR2GRAY)
sift = cv.xfeatures2d_SIFT.create()
keyPoints = sift.detect(image,None)
output = cv.drawKeypoints(image,keyPoints,None)
cv.imshow("FEATURES DETECTED",output)
cv.imshow("NORMAL",image)
cv.waitKey(0)
cv.destroyAllWindows()
SIFT's patent has expired in last July. in versions > 4.4, the detector init command has changed to cv2.SIFT_create().
If you're not using opencv's GUI, It's recommended to install the headless version: pip install opencv-python-headless
Unfortunately, according to this Github issue, SIFT no longer available in opencv > 3.4.2. Since you're using OpenCV v4.2.0, it's not included even if you have installed pip install opencv-contrib-python as shown in this post. A work around is to downgrade to any previous OpenCV version that includes SIFT (I believe any version below 3.4.3). I've been successful when downgrading to v3.4.2.16.
pip install opencv-python==3.4.2.16
pip install opencv-contrib-python==3.4.2.16
Using your code with v3.4.2.16, SIFT seems to work
I had the same issue previously. I had tried all methods but finally a very simple method work for me which has already answered by many. However, there is a little change in my approach.
Step 1:
Uninstall the previously install opencv library
pip uninstall opencv-python
Step 2:
Install opencv contrib library due to copyright issue. Here, we are using version 3.4.2.17
pip install opencv-contrib-python==3.4.2.17
opencv contrib library installation error
The above figure shows version 3.4.2.16 not found error. Hence, I tried with version 3.4.2.17. If this version doesn't work, try other versions of 3.4.x.
Step 3:
Then run the following
import cv2
sift = cv2.xfeatures2d.SIFT_create()
That's all. It works for me. I hope it works for you as well.
I had the same issue, after a lot of attempts, I tried installing opencv-contrib-python several times, but it worked just today. Just to be sure I installed both opencv-python and opencv-contrib-python.
pip install opencv-python
And
pip install opencv-contrib-python
The version that installed was 4.4.0.46 for both opencv-python and opencv-contrib-python. In case the later versions don't support it (A few of the previous versions didn't support SIFT, the one from a month ago, the latest opencv-contrib-python patch was released on Nov 2nd, 2020).
The solution to your problem should be installing opencv-contrib-python-nonfree (available via pip).
$ pip install opencv-contrib-python-nonfree
As the error states SIFT is patented and therefore not included into OpenCV for license reasons. It's included in the nonfree part.
I have troubles to install OpenCV3 for Python3.4 in Widnows 10.
I have already installed numpy which seems the first thing to do..
C:\Users\Mourad\Desktop>py -m pip install numpy
Requirement already satisfied: numpy in c:\users\mourad\appdata\local\programs\python\python36\lib\site-packages
Now what I am trying to do is:
C:\Users\Mourad\Desktop>py -m pip install cv2
But it doesn't work:
Collecting cv2
Could not find a version that satisfies the requirement cv2 (from versions: )
No matching distribution found for cv2
EDIT :
This is finnaly the solution that worked for me, after days of trying. You just follow the stpes of this tutorial:
install opencv 3 with python 3 on windows
What I did was first installed numpy then installed opencv-python not cv2 using pip.
Hope it helps.
In StackOverflow opencv documentation, this topic was explained with a step by step guide. Since SO Documentation is retired, there were two links that helped commentators:
OpenCV 3 Python Tutorial for Windows Setup
Install OpenCV 3 with Python 3 on Windows
I have been installing PyautoGui on my WIN10 PC. But I am getting the following error, i have been getting a lot of errors jut to get this far.
i have been reinstalling python so its destination folder is in C:\Python instead of C:\Users\Home\AppData\Local\Programs\Python\Python35-32 mabye thats why ? How do i fix this ?
C:\Python\Scripts>pip.exe install pyautogui Collecting pyautogui
Using cached PyAutoGUI-0.9.33.zip Collecting pymsgbox (from pyautogui)
Using cached PyMsgBox-1.0.3.zip Collecting PyTweening>=1.0.1 (from
pyautogui) Using cached PyTweening-1.0.3.zip Collecting Pillow (from
pyautogui) Using cached Pillow-3.3.1-cp35-cp35m-win32.whl Collecting
pyscreeze (from pyautogui) Using cached PyScreeze-0.1.8.zip
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "", line 1, in
File "C:\Users\Home\AppData\Local\Temp\pip-build-kxm3249e\pyscreeze\setup.py",
line 6, in
version=import('pyscreeze').version,
File "c:\users\home\appdata\local\temp\pip-build-kxm3249e\pyscreeze\pyscreeze__init__.py",
line 21, in
from PIL import Image
ImportError: No module named 'PIL'
Command "python setup.py egg_info" failed with error code 1 in
C:\Users\Home\AppData\Local\Temp\pip-build-kxm3249e\pyscreeze\
I encountered the same error message as you did. This workaround worked for me. Try these steps in order...
Install PyScreeze 0.1.7.
Update PyScreeze to 0.1.8.
Install PyAutoGui.
I hope this helps.
I also encountered the same error (albeit on Ubuntu 14.04). The missing module PIL is named Pillow (As said in this answer). So what I tried was (same in MacOS I think):
sudo pip3 install pillow
That translated to Windows would be:
pip.exe install pillow
Hope this helps you further.
Instead of letting PyautoGUI get all the packages for you.
Install all of them individually. Then, run the pip install --upgrade _packageName_
Then run pip install pyautogui.
Hope this helps.
I'm happy to report that this installation error has been fixed as of version 0.9.34. All you have to do is install or update PyAutoGUI from PyPI.
try
pip uninstall pyautogui
then
pip install pyautogui
There is a possibility that on windows it is not rightly configured on windows path and therefore it cant find the module, to fix this try:
Control Panel \ System and Security \ System
then click: Environment Variables, and double click on path and append the directory you want to use.
full explanation on: https://helpdeskgeek.com/windows-10/add-windows-path-environment-variable/
you can also try:
Cmd:
python -m pip install < module >
git clone https://github.com/USERNAME/REPOSITORY
or
To append to PYTHONPATH:
IDE:
import sys
sys.path.append('< path >')