import cv2
fgbg = cv2.createBackgroundSubtractorMOG()
fgbg1 = cv2.createBackgroundSubtractorGMG()
AttributeError: 'module' object has no attribute 'createBackgroundSubtractorMOG()'
AttributeError: 'module' object has no attribute 'createBackgroundSubtractorMOG()'
Enviroment:
x64 win7
win32 python 2.7.3
opencv 3.0.0-beta
What should I do?
You may be interested in BackgroundSubtractorMOG2, which, although not documented, has a python binding in opencv 3.0.0-beta.
import cv2
fgbg = cv2.createBackgroundSubtractorMOG2(detectShadows=True)
both were moved in 3.0 to the opencv_contrib repo
you will need to build it along with your main opencv repo using cmake. (no prebuild versions of this available) then running the INSTALL project (or make install) will copy your new cv2.pyd to the python folder.
then:
>>> import cv2
>>> cv2.bgsegm.createBackgroundSubtractorMOG # note additional bgsegm namespace !
<built-in function createBackgroundSubtractorMOG>
Use cv2.BackgroundSubtractorMOG()
because cv2.createBackgroundSubtractorMOG2 was replaced in the latest versions of opencv.
Try one of the following solutions:
cv2.bgsegm.createBackgroundSubtractorMOG()
or:
cv2.bgsegm.createBackgroundSubtractorMOG2()
Related
While trying convert caffemodel to mlmodel i cant run my converter-script.py
this is my converter-script.py file :
import coremltools
caffe_model = ('oxford102.caffemodel', 'deploy.prototxt')
labels = 'flower-labels.txt'
models = coremltools.converters.caffe.converts(
caffe_model,
class_labels = labels,
image_input_names = 'data'
)
coreml_model.save('FlowerClassifier.mlmodel')
i run this using virtualenv with python 2.7
and i get this error message :
File "convert-script.py", line 1, in
import coremltools
File "/Users/aji/Documents/Environments/python27/lib/python2.7/site-packages/coremltools/init.py", line 28, in
_root_logger_handlers_backup = _root_logger.handlers.copy()
AttributeError: 'list' object has no attribute 'copy'
Anyone can give me solution?
Use python3 instead of creating and running from a python27 venv.
python3 convert-script.py
worked for me
So the problem here is about coremltools. The most recent version of it works with python 3 and you're doing conversion on python 2.7
The easiest way to solve your problem is to downgrade your coremltools to version, which works with py2.7, you can do it with following command in your terminal:
pip install coremltools=4.0
Then just run script the same way you did it before :)
I have this python code when I run it ,it say
AttributeError: module 'cupy' has no attribute 'cupyx'
code:
# upload matrix and inverse diagonal GPU
A = cp.cupyx.scipy.sparse.csr_matrix(A)
I've installed cupy successfully in docker using
pip install cupy-cuda100
any help will be appreciated, thx
See the discussion in https://github.com/cupy/cupy/issues/2654 and try the following
import cupyx.scipy.sparse
cupyx.scipy.sparse.csr_matrix(A)
The alias cupy.cupyx was unintentionally there in some prereleases, but it has been removed because it is too confusing.
I am trying to import feedparser in Python, and want to call FeedParserDict from the library feedparser, i.e., feedparser.FeedParserDict. But it leads to the following error:
"AttributeError: module 'feedparser' has no attribute 'FeedParserDict'."
Does it mean that "FeedParserDict" is not in the library feedparser (version 5.2.1). I find that "FeedParserDict" is present in previous version of feedparser (i.e., version 3.3). How can I cope with this error?
I've pip install feedparser==5.2.1 and "FeedParserDict" is present in it
import feedparser
print(feedparser.__version__)
print(feedparser.FeedParserDict)
output:
5.2.1
<class 'feedparser.FeedParserDict'>
I need to import serial library in my python project that uses PyQt to build user inteface.
To list all avcailable serial ports I tried to use this command:
import serial
...
def findComPorts(self):
list=serial.tools.list_ports_osx.comports()
port=serial.Serial('...',baudrate=38400)`
but eclipse shows the error: Undefined variable from import: tools
I also tried:
from serial import tools
...
def findComPorts(self):
list=tools.list_ports_osx.comports()
port=serial.Serial('...',baudrate=38400)
but now the error at runtime is: AttributeError: 'module' object has no attribute 'list_ports_osx'
I'm running Eclypse Kepler, Python 2.7, pySerial 2.7 installed via macports
As I try to catch convexity defects in an image with opencv+python, but "python said":
defects = cv2.convexityDefects(cnt,hull)
AttributeError: 'module' object has no attribute 'convexityDefects'
The python script was running under ubuntu 12.04+python 2.7+opencv from repository.
The code was modified from http://opencvpython.blogspot.fr/2012/06/contours-4-ultimate.html
thanks for your help
jean-pat