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

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.

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.

wx Module misses attribute ArtProvider

I am adapting a model in SUMO and try to run a file (sumopy_gui.py).
When doing so I get the following error message:
AttributeError: module 'wx' has no attribute 'ArtProvider_GetBitmap'
I tried to update wx in the cmd line, reinstalling it, but I don't find a reason why wx shouldn't have this module. All the other modules seem to be working for now.
Can someone help me please?
Thanks
If you are using wxPython 4, then you want to use wx.ArtProvider.GetBitmap. Previous versions (i.e. Classic) used the old ArtProvider_GetBitmap.
A good place to check for these kinds of differences is the following:
https://wxpython.org/Phoenix/docs/html/classic_vs_phoenix.html
I also recommend reading the Migration Guide from Classic to Phoenix:
https://wxpython.org/Phoenix/docs/html/MigrationGuide.html

Error in prediction using sknn.mlp

I use Anaconda on a Windows 10 laptop with Python 2.7 and Spark 2.1. Built a deep learning model using Sknn.mlp package. I have completed the model. When I try to predict using the predict function, it throws an error. I run the same code on my Mac and it works just fine. Wondering what is wrong with my windows packages.
'NoneType' object is not callable
I verified input data. It is numpy.array and it does not have null value. Its dimension is same as training one and all attributed are the same. Not sure what it can be.
I don't work with Python on Windows, so this answer will be very vague, but maybe it will guide you in the right direction. Sometimes there are cross-platform errors due to one module still not being updated for the OS, frequently when another related module gets an update. I recall something happened to me with a django application which required somebody more familiar with Windows to fix it for me.
Maybe you could try with an environment using older versions of your modules until you find the culprit.
I finally solved the problem on windows. Here is the solution in case you face it.
The Theano package was faulty. I installed the latest version from github and then it threw another error as below:
RuntimeError: To use MKL 2018 with Theano you MUST set "MKL_THREADING_LAYER=GNU" in your environment.
In order to solve this, I created a variable named MKL_Threading_Layer under user environment variable and passed GNU. Reset the kernel and it was working.
Hope it helps!

pack individual .jpg image files into RecordIO (.rec) files

I'm trying to go through the MXNET tutorial (https://statist-bhfz.github.io/cats_dogs_finetune), but have trouble making the RecordIO ".rec" files used to process the pictures.
I have tried the suggested approach:
python C:/mxnet-20170203/tools/im2rec.py --list=1 --recursive=1 --train-ratio=0.8 cats_dogs train_pad_224x224
python C:/mxnet-20170203/tools/im2rec.py --num-thread=4 --pass-through=1 cats_dogs_train.lst train_pad_224x224
python C:/mxnet-20170203/tools/im2rec.py --num-thread=4 --pass-through=1 cats_dogs_val.lst train_pad_224x224
But i get the error: "AttributeError: 'module' object has no attribute 'MXIndexedRecordIO'"
when doing so.
Is there a way to generate the ".rec" files in R directly? And if not, how do i get pass the error?
Thanks.
Kr,
Daniel
The error you are getting seems related to the fact that you are trying to use a newer version of im2rec.py than the one that came with your installed version of mxnet, hence the missing modules.
try using the im2rec.py script located in your own mxnet installation folder, somewhere like this python2.7/site-packages/mxnet/tools/im2rec.py
Also note that if you upgrade your version of mxnet, the syntax of im2rec has changed to:
im2rec.py --list --recursive --train-ratio=0.8 cats_dogs train_pad_224x224

music21 --> simplifyMultipleEnharmonics not available?

I'm trying to use the function pitch.simplifyMultipleEnharmonics(...): http://web.mit.edu/music21/doc/moduleReference/modulePitch.html#functions
but at line:
print music21.pitch.simplifyEnharmonics([pitch.Pitch('G3'),
pitch.Pitch('C-4'),
pitch.Pitch('D4')])
I get the error:
>>> 'module' object has no attribute 'simplifyMultipleEnharmonics'
... I'm using the latest version of music21 (just pip installed again).
... Is this function available only in an older version of music21?
Thanks very much for any help!
It's a new function for v3 which is the GitHub master branch so it's not in any of the releases yet. Sorry. Versioned docs are on the priority list to prevent problems like this.

Categories