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.
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.
I installed opencv-python on ubuntu wsl, after setting up a venv using virtualenvwrapper (I use wsl in visual studio code).
When running this code (which appears in one of the articles of this OCR guide:
import argparse
import cv2
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--image", required=True)
args = vars(ap.parse_args())
image = cv2.imread(args["image"])
cv2.imshow("I", image)
with this command on teminal:
python script.py --image temp.png
I get:
qt.qpa.xcb: could not connect to display
qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "/home/ben123/.local/bin/.virtualenvs/ocr_venv/lib/python3.8/site-packages/cv2/qt/plugins" even though it was found.
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.
Available platform plugins are: xcb.
The interpreter in vscode is the correct one (the one of the venv), and when I type pip list I get
Package Version
------------- --------
numpy 1.22.2
opencv-python 4.5.5.62
pip 22.0.3
setuptools 60.6.0
wheel 0.37.1
Would appreciate any help at this point, since I spent so much time and didn't get nowhere.
Things I tried:
following this guide to install it. Gave the same error.
following an older guide from this site, was much more complicated and didn't work as well.
uninstalling opencv-python and installing opencv-python again/ opencv-python-contrib/ opencv-python-headless/ opencv-python-contrib-headless (only one of them at a time)
following this thread because it has similar problem
literally reset my wsl several times just to make sure I don't have multiple pythons/ opencv versions that mess this up.
tried installing (to a wsl venv) opencv directly with the official documentation
Tried to give up on wsl completely and install opencv using anaconda but even that didn't work.
Just delete cv2.imshow from your code. Your OS is without graphics and can't display image
I had the same error in a completely different context.
Found that the problem was a PyQt5 installation in my virtual environment.
Check if you have a PyQt in the path
/home/ben123/.local/bin/.virtualenvs/ocr_venv/lib/python3.8/site-packages/
if so, remove it
$ pip uninstall <PyQT package installed>
example:
$ pip uninstall PyQt5
Then reinstall opencv-python
$ pip uninstall opencv-python
$ pip install opencv-python
Hope that works!
To display graphical information about wsl, you should configure x11 related content.
eg: You can use MobaXterm for graphical display.
Uninstalling opencv and installing similar headless version worked for me.
$ pip install opencv-python-headless
Error Trace:
ImportError: /lib/arm-linux-gnueabihf/libc.so.6: version `GLIBC_2.33' not found (required by /home/pi/.local/lib/python3.7/site-packages/grpc/_cython/cygrpc.cpython-37m-arm-linux-gnueabihf.so)
Scenario:
I'm using google cloud vision api to detect text in images. The program works fine on laptop but gives the above mentioned error when ran in raspberry pi. I've searched a lot but couldn't find any working solution. I'd really appreciate if any one could let me know how to solve this.
Uninstalling grpcio and grpcio-status (mine had version 1.46.3 installed for both) and installing version 1.44.0 solved it for me:
pip uninstall grpcio
pip uninstall grpcio-status
pip install grpcio==1.44.0 --no-binary=grpcio
pip install grpcio-tools==1.44.0 --no-binary=grpcio-tools
You can check your installed versions with pip list.
Note: installing grpcio and grpcio-status takes a really long time. About 15 to 20 minutes each.
Originally posted here: https://groups.google.com/g/grpc-io/c/vjbL3IdZ2Vk/m/EcKSeD4eAgAJ
GLIBC and the kernel of the OS go hand-in-hand; you basically need a newer version of your OS, if you need a more recent GLIBC
the version of the GLIBC can be quickly found out with the following command:
ldd --version
Have you tried building glibc 2.33+ alongside the glibc that come in raspberry pi? Something along this answer and comments to use buildroot
Code:
import easyocr
reader = easyocr.Reader(['en'])
result = reader.readtext('R.png')
Output:
CUDA not available - defaulting to CPU. Note: This module is much faster with a GPU.
cv2.error: Unknown C++ exception from OpenCV code
I would truly appreciate any support!
The new version of OpenCV has some issues. Uninstall the newer version of OpenCV and install the older one using:
pip install opencv-python==4.5.4.60
install letest version of opnecv
pip install opencv-python==4.5.4.60
During the installation phase, I get this, "Unable to find vcvarsall.bat" error. The installation process did complete, though. However, I was unable to see the shell on my desktop (I am using windows) and neither was I able to open it manually. I scoured the internet for the error but was unable to find any solution for this case.
The installation process is through a superpack that downloads Python 2.7
SimpleCV is not receiving much love in the past few years, and most of it's code don't got upgrade like the libraries it depends on.
The problem you got is the Superpack trying to compile an older version of OpenCV.
When running the Superpack, you should have seen and redtext error, and if you try to run a code it should show you something like this:
File "C:\Python27\lib\site-packages\SimpleCV\base.py", line 59, in <module>
raise ImportError("Cannot load OpenCV library which is required by SimpleCV")
ImportError: Cannot load OpenCV library which is required by SimpleCV
There are a few paths you can try from there:
1. You can try to install Microsoft Visual C++ Compiler for Python 2.7
Uninstall everything SuperPack installed in your PC or it may not work
It may fixes some other uses when using pip.
Now you have to install SimpleCV again.
2. Try to install OpenCV(2.3) on your own:
You can use pip for it, just remember to chose 32bits to keep compatibility with (Super Pack)
Just run on CMD
pip install OpenCV or python -m pip install OpenCV
3. Give up on SuperPack and install everything on your own.
You can try this guide
https://github.com/sightmachine/SimpleCV#windows-7vista
Or use pip for all dependencies
numpy (Numpy+MKL make sure to install this one first)
scipy
PIL
ipython
svgwrite
pygame==1.9.1release
OpenCV
You can find a useful list of wheels here
http://www.lfd.uci.edu/~gohlke/pythonlibs/#opencv
Sources:
https://blogs.msdn.microsoft.com/pythonengineering/2016/04/11/unable-to-find-vcvarsall-bat/
http://www.lfd.uci.edu/~gohlke/pythonlibs/#opencv
https://github.com/sightmachine/SimpleCV#windows-7vista