error while using FREAK - python

I'm trying to create Descriptor extractor using FREAK. but
at the following line:
freakExtractor = cv2.DescriptorExtractor_create('FREAK')
I get an error saying:
freakExtractor = cv2.DescriptorExtractor_create('FREAK')
AttributeError: 'module' object has no attribute 'DescriptorExtractor_create'
can someone tell me what is the exact problem and why i'm getting this error?
I'm using ubuntu 12.10 with opencv 2.4.3 and python 2.7.

I think,
cv2.DescriptorExtractor_create('FREAK')
is not a part of python interface, just use the latest opencv for that then it will work or you simply can write the code in c++ which is availabe in that version in c++.

Related

How would I deal with an attribute error with mediapipe solutions?

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.

Attribute Error when trying to use numpy.random.choices in Google Colaboratory

I am trying to use numpy.random.choices() to generate some pseudo-random data but am getting the following error message:
AttributeError: module 'numpy.random' has no attribute 'choices'
The existing threads I can find suggest that this is a version issue: it looks like Python must be version 3.6 or higher, and there may be minimum version requirements with NumPy as well. But I am using Python 3.7.12 and NumPy 1.21.5 in my environment and still getting this error. I'm also working in a Google Colaboratory file right now, which may have something to do with the error, but I'm not sure what or why.

AttributeError in PyCharm

Very simply, I cannot get .format to work in my code. For Example, when I write:
print("abc{0}def".format("x"))
I end up with the following error:
print("abc{0}def".format("x"))
AttributeError: 'str' object has no attribute 'format'
I am just beginning to learn Python and I am getting this error in PyCharm Community Edition 5.0.3
It is interfering with my assignments and my professor has no idea what the issue is.
By switching my Python Interpreter in settings I was able to switch PyCharm from version 2 to version 3, which solved all of the issues.

python-opencv AttributeError: 'module' object has no attribute 'createBackgroundSubtractorGMG'

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.

SURF not bound in opencv-python?

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

Categories