I was working on a project on facial recognition using asift, which does PCA whitening before it processes the image. One of my friends downloaded a code and gave it to me for execution, so we have something to start with. But however, on execution, I got an error, which said -
AttributeError: module 'cv2' has no attribute 'PCAComputeVar'
On Googling, I found that PCAComputeVar is supported mainly in opencv 2. However, I couldn't find anything in opencv 3. I don't want to downgrade to opencv 2, because there are some features supported only in opencv 3.
Is there any method by which I can access opencv 2 libraries from opencv3? If not, atleast is there any function in opencv 3, which does something similar to this?
According to their 3.2 documentation, it was renamed to cv2.PCACompute().
More details on the parameters can be found here.
Related
I have a problem. I can't solve this problem for 5 days.
My task is to develop a plug-in for Autodesk Fusion 360 in python (CAD). The client wants to take a contour based on a photo and obtain a code to control the robot based on it.
I want to use the openCV library. Fusion 360 install my own version of python, I can't change it. I installed opencv-contrib-python, I also have media features in windows.
I still have a problem:
ImportError: DLL load failed while importing cv2: The specified module could not be found.
What else can I try?
Maybe there is another way to get contours from a photo?
Maybe using a different library or with ready-made functions from gitgub?
I get an attribute error if I use the function:
def faceDetection():
if results.detections:
for detection in results.detection:
print(id, detection)
AttributeError: type object 'SolutionOutputs' has no attribute
'detections'
is the error I get if I try running, specifically it calls it on the results.detections: line
it works fine in this youtube tutorial
at 1:43:56
I don't really know how to read the github code but here's the link
I do have
mpFD = mp.solutions.face_detection # FD = face_detection
fD = mpFD.FaceDetection()
defined before the function already.
Is this an issue with my code or is it something else?
This error depends on the Python version you are using. You need to use the version minimum Python 3.9 but most probably you are using Python 3.6.
It would be better to create an environment with conda by specifying Python version and install mediapipe in there and try to run your code again. The error will disappear.
Here is an example how to establish environment to run mediapipe examples.
It wasn't a problem with the mediapipe library, but I hadn't initialized results as the faceDetections solutions, but I had results as a value for the hands solution module.
I'm new to OpenCV and trying to use SIFT and SURF for a project.
On my laptop I have OpenCV version= 4.5.1.48 and also added OpenCV-contrib-python of version 4.5.1.48
currently the problem I'm facing is the error I'm getting after following the documentation SIFT works perfectly after following documentation but SURF isn't working and giving me error for following codes
code 1
surf = cv.xfeatures2d.SURF_create()
AttributeError: module 'cv2.cv2' has no attribute 'xfeatures2d'
code 2
surf = cv2.SURF_create()
AttributeError: module 'cv2.cv2' has no attribute 'SURF_create'
After reading many answers on Stack overflow I changed version of OpenCV and did many things but nothing is working for me
I'm new to this please someone guide me through this
I read about the patent expiring too but nothing is working in my case pls tell me if im wrong somewhere
Thanks in advance
OpenCV version= 4.5.1.48
this is probably from pypi, and does not contain any "nonfree" code
(SURF is still patented, if you absolutely need that, you have to build from src (with contrib modules), using the OPENCV_ENABLE_NONFREE=ON cmake flag)
however, since the SIFT patent expired last year, use that instead
sift = cv2.SIFT_create() # it's in main, no more xfeatures2d
btw, dont install both opencv-python, and opencv-contrib-python, only the latter (else the former will "shadow" it, and you cannot use contrib modules. this is the reason for AttributeError: module 'cv2.cv2' has no attribute 'xfeatures2d')
For patent reasons, opencv 4.5.1.48 does not include the whole algorithm
You can use Python3.6 (or Python3.7 maybe OK) and install opencv-pyhton==3.4.2.16 and opencv-contrib-python==3.4.2.16, then you can use the function that:
surf = cv2.xfeatures2d.SURF_create()
or
sift = cv2.xfeatures2d.SIFT_create()
I am trying to follow the tutorial given in:
https://opencv-python-tutroals.readthedocs.org/en/latest/py_tutorials/py_video/py_bg_subtraction/py_bg_subtraction.html
While trying the third example (BackgroundSubtractorGMG) I get this error:
AttributeError: 'module' object has no attribute 'createBackgroundSubtractorGMG'
I got the same error for the earlier examples. But I followed the explanation given in this post. some how, the same trick did not work here.
If there is some one who has managed to solve it, please help me out.
Using Python 2.7.3 & opencv 2.4.6.1 on Ubuntu 12.04
In OpenCV 3.0.0-dev, you have to compile with the contrib repos and then it's in the bgsegm sub-module. I.e. just call cv2.bgsegm.createBackgroundSubtractorGMG()
cv2.bgsegm.createBackgroundSubtractorGMG()
cv2.createBackgroundSubtractorMOG2()
cv2.bgsegm.createBackgroundSubtractorMOG(),
**this worked for me **
oh dear, that's another one of those stories ...
with 2.4.6, you only can use BackgroundSubtractorMOG from python. (full stop)
as of 2.4.8, it seems, the BackgroundSubtractorMOG2 problem got fixed, but the BackgroundSubtractorGMG is still missing.
with both versions, you use a plain constructor to create one.
in 3.0 (master), they changed the syntax, you now have to call 'createBackgroundSubtractorGMG', 'createBackgroundSubtractorMOG2' and such (that's what your tutorial might be refering to). but now you can use all 3 versions at least.
so in any way, if you want to use BackgroundSubtractorMOG2 , you'll have to update to 2.4.8, if you need BackgroundSubtractorGMG, you'll need 3.0 (which is 'bleeding edge' in a way, but the new interface has the far better control over the params needed, imho).
bgsegm was in contrib module of opencv, but after the update I am not sure.
But still,
if you have not built contrib module:
pip install opencv-contrib-python
Make sure no console is running that has imported cv2 while you execute your installing process.
Run the cmd as Administration
It worked for me.
I'm getting this error when trying to use cv.ExtractSURF:
cv2.error: OpenCV was built without SURF support
I found the solution for c++ in this topic:
OpenCV SURF function is not implemented
but how can I use it in python ?
---Edit---
When I try to run the example find_obj.py which uses cv2.SURF(800) I get the following error:
AttributeError: 'module' object has no attribute 'SURF'
It seems that some functions are moved to "nonfree" module and that module is removed from the latest OpenCV package on FC18. Until this will be resolved, I made downgrade OpenCV library on my 64bit FC18 from version 2.4.3 to version 2.3.1. With downgraded library, all my python code started to work as it worked on FC17. Here is link to my post where I have described complete "downgrade" procedure:
http://www.redips.net/linux/downgrade-opencv-fedora18/
OK this happens because I use Fedora 18 (and I installed it with yum):
http://forums.fedoraforum.org/showthread.php?t=287847