module 'cv2' has no attribute 'createThinPlateSplineShapeTransformer' - python

I'm trying to use the Thin plate shape transformer function.
tps = cv2.createThinPlateSplineShapeTransformer()
However, this error is shown:
module 'cv2' has no attribute 'createThinPlateSplineShapeTransformer'.
I have installed contrib using:
pip install opencv-contrib-python
but the problem is still unsolved. I use opencv 4.5.4 and python 3.8.5

See this issue: https://github.com/opencv/opencv-python/issues/177
It appears that that method has been moved out of the base package. So, you need to install OpenCV with contrib modules. For details, please open the link above.

I fixed this problem using the following commands.
pip uninstall opencv-contrib-python
pip install opencv-contrib-python

Related

Cannot find module cv2 even if it's installed

I encountered a problem where I have installed opencv in my anaconda environment using this command:
pip install opencv-contrib-python
But for some reason when I enter into my environment using python and error occurs stating: 'No module named cv2', has someone encountered a similar problem, thanks.
To use cv2, you need to install opencv-python, not the contrib. You can do it by pip install opencv-python.

module 'cv2.cv2' has no attribute 'xfeatures2d' and module 'cv2.cv2' has no attribute 'SIFT'

My python version = 3.7.4
cv2 version= 4.2.0
These are my version on python and open cv, Im trying to use SIFT function and I got the famous error module cv2.cv2' has no attribute 'SIFT', so I tried pip install opencv-contrib-python and also python -m pip install --user opencv-contrib-python, and I changed detector=cv2.SIFT() to detector=cv2.xfeatures2d.SIFT_create() and the error just changed to AttributeError: module 'cv2.cv2' has no attribute 'xfeatures2d'
I Tried with similar questions that I found, but are not working for me, I dont find a recent question, thats why Im opening this new because maybe as the version were different it could be the reason doesnt work for me
What else could I do?
SIFT and SURF are proprietary, patented algorithms. You'd need to compile OpenCV and OpenCV-contrib from source, with non-free packages enabled, building the python libraries. I wasn't able to get this working so I used pip to find an older version (3.4.2) that did not remove the non-free libraries. I may have had to roll back python but I'm not sure. I am using python 3.6.8

OpenCV LBPH Face Recognizer Attribute Error: no module 'face'

trying to execute:
recognizer = cv2.face.LBPHFaceRecognizer_create()
however i am getting back error:
AttributeError: 'module' object has no attribute 'faces'
I have looked at previous posts and i have tried every solution. ( I tried reinstalling opencv-contrib-python, tried a different recognizer function)
I am not sure why this is occurring or if there is a workaround?
Trying to follow the code from this tutorial on Github:
Try to see help
Open python on the terminal:
python
or
python3
and type:
import cv2
help(cv2.face)
See the command as in the image
you can find more details there.
If not, try cv2 .__ version__
And see if the function is available for your opencv version. Mine is 4.1.0.
According to one remark, the modulo faces is only available in opencv-contrib. So it will only work if you have installed opencv with the contrib libraries.
You can try installing opencv like this:
python -m pip install opencv-contrib-python
or
pip install opencv-contrib-python
These two commands install opencv with the comprib compiled together.
Trying to help.

AttributeError: module 'cv2' has no attribute 'imread'

(i'm on mac os 10.8.5)
I'm using Python 3 (through jupyter notebook) and trying to import cv2
I did import cv2 succefully, but when I type im_g = cv2.imread("smallgray.png", 0) I get this error:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-7-5eb2880672d2> in <module>()
----> 1 im_g = cv2.imread("smallgray.png", 0)
AttributeError: module 'cv2' has no attribute 'imread'
I also checked dir(cv2) and I get:
['__doc__', '__loader__', '__name__', '__package__', '__path__', '__spec__'
I guess a lot of functions are missing...
Is it due to a wrong opencv installation ?
Actually I struggled a lot to get opencv and I guess I installed it 'too many times' and different ways via Terminal. (brew, pip)
Should I uninstall opencv and start over ? How can I do this properly ?
Thx in advance
It might be the case that you installed it in the wrong way. In my case as well, I installed OpenCV wrongly so I uninstalled it completely then reinstalled it which caused it to work.
Please notice the sequence of uninstalling and installing:
Uninstall:
pip uninstall opencv-python
pip uninstall opencv-contrib-python
Install:
pip install opencv-contrib-python
pip install opencv-python
I was have this problem too, and i solved it, the problem was been in i named my script cv2.py, i'm just rename it to something else.
Reader's problem could be, that a wrong library (cv2 package) has been installed.
I installed opencv-python3 instead of opencv-python for example.
So in case you have PyCharm IDE, go to File->Settings->Project: *->Python Interpreter and see what you have listed there:
Make sure, you have installed opencv-python.
If you have also other similar names, it should be fine - in my case it works.
This might happen if you have named one of your files as 'cv2.py'. So when you 'import cv2', the system accesses your file instead of the actual library. So try renaming cv2.py' to any other name and your code should work fine.
I had the same issue, this turned out to solve the problem:
from cv2 import cv2
im_g=cv2.imread("smallgray.png", 0)
print(im_g)
Check:
brew list | grep opencv
If it doesn't installed then try:
brew install opencv
it works with me:
pip install opencv-python
pip install opencv-contrib-python
source : https://pypi.org/project/opencv-python/
Do cv2.cv2.imread()
This should work in most of the cases. Also, take a look here.
I faced Similar issue,On Ubuntu
I had installed open-cv using the comand:
sudo pip3 install opencv-python3
I Uninstalled opencv, By:
sudo pip3 uninstall opencv-python3
Then reinstalled it Using the following Code:
pip3 install opencv-python
I also faced this problem.
And get a solution by changing the current cv2.py to cv.py(You can name whatever you like except the name of packages in use).
Little Explanations
Saving the current working file as the name of cv2.py, when we try to run the file it imports the current file with import cv2 statement, not actual cv2 module. This whole thing is causing this whole Error.
The main problem is that you have your file or folder named "cv2", it is not permitted in Python. The way to solve is change the name and then your code will be run
The same issue has recently appeared within my code and had no idea of what's happening. Tried different methods such as uninstalling opencv-python.
Coming to the naming of the file that I am working with, I definitely had no problem that might cause a collapse with the name of the library.
I have deleted the opencv-python, cleaned all of the package-related caches, and then reinstalled the opencv-python and opencv-contrib-python. Now, it is working fine and I can say that no issues have appeared yet.
P.S I am using Arch Linux. If you wonder about how to clear caches, try looking at this source. I hope it helps. Keep learning and exploring, thanks!
I personally had to uninstall all previous installations dealing with opencv :
pip uninstall opencv-python
pip uninstall opencv-contrib-python
pip uninstall opencv-contrib-python-headless
Then I deleted all files that had to do with opencv too in site-package
after the uninstallation, files related to opencv like opencv_contrib_python-4.6.0.66.dist-info remained and caused errors.
Once all these files were deleted I reinstalled opencv:
pip install opencv-python
now it works for me
using cv2 on vscode
i was having this problem but nothing worked. Turns out that i named my file as "cv2.py" so it was importing itself
"Generally, the Python Circular Import problem occurs when you accidentally name your working file the same as the module name and those modules depend on each other. This way the python opens the same file which causes a circular loop and eventually throws an error."
Perhaps you have just installed opencv-contrib-python and not opencv-python.
Try this out, it worked for me-
First uninstall:
pip uninstall opencv-python
pip uninstall opencv-contrib-python
then install:
pip install opencv-contrib-python==3.4.2.16
pip install opencv-python==3.4.2.16
You can refer here.

No Module named "sklearn"

I am trying to import 'sklearn' using Python 3.4.3 on a Raspberry Pi 3 running Raspian.
I downloaded microconda3, which includes all the necessary modules to use scikit.
However, when I attempt to import 'sklearn' in IDLE, I receive an error stating that there is no module named 'sklearn'.
Try starting fresh and reinstall all of the necessary modules through miniconda3. Maybe the scikit-learn included on that install did not work.
You can then try
sudo apt-get install python3-scipy python3-sklearn
You can install the module with the following command using pip:
pip install -U scikit-learn.
See: Scikit-learn Docs

Categories

Resources