Ask Your Question
0

adding extra attributes without upsetting my setup

asked 2015-01-16 06:52:06 -0600

reggie gravatar image

I'm trying to work through this but have found out via the python shell command help(cv2) that I havent got the BackgroundSubtractorMOG and BackgroundSubtractorMOG2 attributes available in my build.

It took me ages to get opencv compiled and working, so i'm very nervous of re-compiling it and adding the extra attributes.

1) is there a safe way to install these extra attributes without upsetting my setup? 2) how can I do this, easy steps please, as I'm a beginner!

edit retag flag offensive close merge delete

Comments

opencv2.4 or 3.0 ? (the usage of BackgroundSubtractorMOG etc is a bit different)

berak gravatar imageberak ( 2015-01-16 06:56:20 -0600 )edit

2.4.2 is my open CV version

reggie gravatar imagereggie ( 2015-01-16 07:55:42 -0600 )edit

no idea, if 2.4.2 even has it for python (and the py_tutorials are all about opencv3.0, too)

berak gravatar imageberak ( 2015-01-16 08:15:58 -0600 )edit

Can I not try these examples with my version of open CV?

reggie gravatar imagereggie ( 2015-01-16 08:48:25 -0600 )edit

The python tutorials can only be ran with the 3.0 version of OpenCV.

StevenPuttemans gravatar imageStevenPuttemans ( 2015-01-17 06:06:53 -0600 )edit
1

Forgive my ignorance, but how can I tell if some code is opencv2 or opencv3?

This states:

This guide is mainly focused on OpenCV 3.x version (although most of the tutorials will work with OpenCV 2.x also).

reggie gravatar imagereggie ( 2015-01-21 07:53:16 -0600 )edit

Where did you download it. If you build OpenCV yourself then you can go to your folder and do a git branch in the folder where you cloned the repo. If not then you can see where you downloaded your version.

StevenPuttemans gravatar imageStevenPuttemans ( 2015-01-21 08:13:33 -0600 )edit
1

python also has cv2.__version__ , but, ofc, this, as well as the idea above will only tell the version installed on your machine, not the version some arbitrary code was programmed for.

berak gravatar imageberak ( 2015-01-21 08:16:56 -0600 )edit

Quite right berak, about "only tell the version installed on my machine". I take it there is now way of telling if if some sample code has been written for openCV2 or 3?

reggie gravatar imagereggie ( 2015-01-21 13:01:01 -0600 )edit

hmm, there's always some small hints, like if it's using cv2.cv, it must be 2.4 (no more possible in 3.0), or constants which changed(CV_AA <-->LINE_AA), or the way, e.g. SIFT is used

berak gravatar imageberak ( 2015-01-21 13:05:27 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
2

answered 2015-01-16 07:34:52 -0600

berak gravatar image
  • with opencv3, you will have to get a BackgroundSubtractorKNN or BackgroundSubtractorMOG2 like this:

    cv2.createBackgroundSubtractorKNN([, history[, dist2Threshold[, detectShadows]]])    
    cv2.createBackgroundSubtractorMOG2([, history[, varThreshold[, detectShadows]]])
    

  • createBackgroundSubtractorGMG and createBackgroundSubtractorMOG were moved to the bgsegm module in opencv_contrib repo:

      cv2.bgsegm.createBackgroundSubtractorGMG([, initializationFrames[, decisionThreshold]]) 
      cv2.bgsegm.createBackgroundSubtractorMOG([, history[, nmixtures[, backgroundRatio[,noiseSigma]]]])
    
edit flag offensive delete link more

Comments

when I use fgbg = cv2.bgsegm.createBackgroundSubtractorMOG() I get error

 AttributeError: 'module' object has no attribute 'bgsegm'
warning: Error opening file (../../modules/highgui/src/cap_ffmpeg_impl.hpp:545)

and the same for fgbg = cv2.bgsegm.createBackgroundSubtractorGMG()

Other than replacing this line with your lines of code, I'm not sure what to do.

reggie gravatar imagereggie ( 2015-01-16 08:05:20 -0600 )edit

^^ answer was about opencv3..

berak gravatar imageberak ( 2015-01-16 08:13:37 -0600 )edit

Sorry I missed that

reggie gravatar imagereggie ( 2015-01-16 08:45:48 -0600 )edit

It is not even working in opencv3. can anyone provide me a solution with how can I use createBackgroundSubtractorMOG()?

Imtiazz gravatar imageImtiazz ( 2015-10-19 07:37:52 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2015-01-16 06:52:06 -0600

Seen: 1,109 times

Last updated: Jan 16 '15