OpenCV2 Python createBackgroundSubtractor module not found










17














I am trying to use cv2.createBackgroundSubtractorMOG2 () method in Python. I have tried both on my Mac and on my Raspberry Pi, and get the same error when running the following line of code:



fgbg = cv2.createBackgroundSubtractorMOG2()


The code I am using is taken from https://github.com/abidrahmank/OpenCV2-Python-Tutorials/blob/master/source/py_tutorials/py_video/py_bg_subtraction/py_bg_subtraction.rst



I get the following error when running this code:




fgbg = cv2.createBackgroundSubtractorMOG2()
AttributeError: 'module' object has no attribute 'createBackgroundSubtractorMOG2'




I can't seem to use any of the createBackgroundSubtractor methods.



I have been trying to solve this for the past day, but I have had no luck searching online, as there is limited support for cv2 on Python.



Thanks in advance










share|improve this question





















  • Which version of OpenCV binding are you using?
    – jabaldonedo
    Sep 10 '13 at 14:31










  • I'm using OpenCV 2.4.6, which looks like the latest OpenCV version with Python 2.7.5
    – user2765323
    Sep 10 '13 at 14:33







  • 1




    That's strange because it should have been added in the last version (I haven't already checked it). However you can still use cv2.BackgroundSubtractorMOG() instead of cv2.createBackgroundSubtractorMOG2()
    – jabaldonedo
    Sep 10 '13 at 14:48






  • 1




    code.opencv.org/issues/2812#note-5
    – berak
    Sep 10 '13 at 14:53










  • Great thanks, that makes sense, and cv2.BackgroundSubtractorMOG() is working. Do you have any idea when this will be resolved?
    – user2765323
    Sep 10 '13 at 15:04
















17














I am trying to use cv2.createBackgroundSubtractorMOG2 () method in Python. I have tried both on my Mac and on my Raspberry Pi, and get the same error when running the following line of code:



fgbg = cv2.createBackgroundSubtractorMOG2()


The code I am using is taken from https://github.com/abidrahmank/OpenCV2-Python-Tutorials/blob/master/source/py_tutorials/py_video/py_bg_subtraction/py_bg_subtraction.rst



I get the following error when running this code:




fgbg = cv2.createBackgroundSubtractorMOG2()
AttributeError: 'module' object has no attribute 'createBackgroundSubtractorMOG2'




I can't seem to use any of the createBackgroundSubtractor methods.



I have been trying to solve this for the past day, but I have had no luck searching online, as there is limited support for cv2 on Python.



Thanks in advance










share|improve this question





















  • Which version of OpenCV binding are you using?
    – jabaldonedo
    Sep 10 '13 at 14:31










  • I'm using OpenCV 2.4.6, which looks like the latest OpenCV version with Python 2.7.5
    – user2765323
    Sep 10 '13 at 14:33







  • 1




    That's strange because it should have been added in the last version (I haven't already checked it). However you can still use cv2.BackgroundSubtractorMOG() instead of cv2.createBackgroundSubtractorMOG2()
    – jabaldonedo
    Sep 10 '13 at 14:48






  • 1




    code.opencv.org/issues/2812#note-5
    – berak
    Sep 10 '13 at 14:53










  • Great thanks, that makes sense, and cv2.BackgroundSubtractorMOG() is working. Do you have any idea when this will be resolved?
    – user2765323
    Sep 10 '13 at 15:04














17












17








17


4





I am trying to use cv2.createBackgroundSubtractorMOG2 () method in Python. I have tried both on my Mac and on my Raspberry Pi, and get the same error when running the following line of code:



fgbg = cv2.createBackgroundSubtractorMOG2()


The code I am using is taken from https://github.com/abidrahmank/OpenCV2-Python-Tutorials/blob/master/source/py_tutorials/py_video/py_bg_subtraction/py_bg_subtraction.rst



I get the following error when running this code:




fgbg = cv2.createBackgroundSubtractorMOG2()
AttributeError: 'module' object has no attribute 'createBackgroundSubtractorMOG2'




I can't seem to use any of the createBackgroundSubtractor methods.



I have been trying to solve this for the past day, but I have had no luck searching online, as there is limited support for cv2 on Python.



Thanks in advance










share|improve this question













I am trying to use cv2.createBackgroundSubtractorMOG2 () method in Python. I have tried both on my Mac and on my Raspberry Pi, and get the same error when running the following line of code:



fgbg = cv2.createBackgroundSubtractorMOG2()


The code I am using is taken from https://github.com/abidrahmank/OpenCV2-Python-Tutorials/blob/master/source/py_tutorials/py_video/py_bg_subtraction/py_bg_subtraction.rst



I get the following error when running this code:




fgbg = cv2.createBackgroundSubtractorMOG2()
AttributeError: 'module' object has no attribute 'createBackgroundSubtractorMOG2'




I can't seem to use any of the createBackgroundSubtractor methods.



I have been trying to solve this for the past day, but I have had no luck searching online, as there is limited support for cv2 on Python.



Thanks in advance







python opencv background-subtraction






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Sep 10 '13 at 14:25









user2765323user2765323

153118




153118











  • Which version of OpenCV binding are you using?
    – jabaldonedo
    Sep 10 '13 at 14:31










  • I'm using OpenCV 2.4.6, which looks like the latest OpenCV version with Python 2.7.5
    – user2765323
    Sep 10 '13 at 14:33







  • 1




    That's strange because it should have been added in the last version (I haven't already checked it). However you can still use cv2.BackgroundSubtractorMOG() instead of cv2.createBackgroundSubtractorMOG2()
    – jabaldonedo
    Sep 10 '13 at 14:48






  • 1




    code.opencv.org/issues/2812#note-5
    – berak
    Sep 10 '13 at 14:53










  • Great thanks, that makes sense, and cv2.BackgroundSubtractorMOG() is working. Do you have any idea when this will be resolved?
    – user2765323
    Sep 10 '13 at 15:04

















  • Which version of OpenCV binding are you using?
    – jabaldonedo
    Sep 10 '13 at 14:31










  • I'm using OpenCV 2.4.6, which looks like the latest OpenCV version with Python 2.7.5
    – user2765323
    Sep 10 '13 at 14:33







  • 1




    That's strange because it should have been added in the last version (I haven't already checked it). However you can still use cv2.BackgroundSubtractorMOG() instead of cv2.createBackgroundSubtractorMOG2()
    – jabaldonedo
    Sep 10 '13 at 14:48






  • 1




    code.opencv.org/issues/2812#note-5
    – berak
    Sep 10 '13 at 14:53










  • Great thanks, that makes sense, and cv2.BackgroundSubtractorMOG() is working. Do you have any idea when this will be resolved?
    – user2765323
    Sep 10 '13 at 15:04
















Which version of OpenCV binding are you using?
– jabaldonedo
Sep 10 '13 at 14:31




Which version of OpenCV binding are you using?
– jabaldonedo
Sep 10 '13 at 14:31












I'm using OpenCV 2.4.6, which looks like the latest OpenCV version with Python 2.7.5
– user2765323
Sep 10 '13 at 14:33





I'm using OpenCV 2.4.6, which looks like the latest OpenCV version with Python 2.7.5
– user2765323
Sep 10 '13 at 14:33





1




1




That's strange because it should have been added in the last version (I haven't already checked it). However you can still use cv2.BackgroundSubtractorMOG() instead of cv2.createBackgroundSubtractorMOG2()
– jabaldonedo
Sep 10 '13 at 14:48




That's strange because it should have been added in the last version (I haven't already checked it). However you can still use cv2.BackgroundSubtractorMOG() instead of cv2.createBackgroundSubtractorMOG2()
– jabaldonedo
Sep 10 '13 at 14:48




1




1




code.opencv.org/issues/2812#note-5
– berak
Sep 10 '13 at 14:53




code.opencv.org/issues/2812#note-5
– berak
Sep 10 '13 at 14:53












Great thanks, that makes sense, and cv2.BackgroundSubtractorMOG() is working. Do you have any idea when this will be resolved?
– user2765323
Sep 10 '13 at 15:04





Great thanks, that makes sense, and cv2.BackgroundSubtractorMOG() is working. Do you have any idea when this will be resolved?
– user2765323
Sep 10 '13 at 15:04













7 Answers
7






active

oldest

votes


















31














Replace the create.... with



fgbg = cv2.BackgroundSubtractorMOG()






share|improve this answer




























    12














    cv2.createbackgroundSubstractor() works in cv 3.0 for 2.4.x use cv2.BackgroundSubstractor()






    share|improve this answer






















    • IMO this is not an answer but a comment.
      – Hello World
      Jun 16 '14 at 17:11


















    4














    Thanks for the comments all. It seems that createBackgroundSubtractorMOG2() hasn't been added to OpenCV 2.4, but it is present in master branch, which can be compiled from github.



    I am finding that cv2.BackgroundSubtractor() is working for what I need at the moment.



    See http://code.opencv.org/issues/2812#note-5 for more details.






    share|improve this answer




























      4














      I'm using



      >>> import cv2
      >>> cv2.__version__
      >>> 3.2.0


      and python 2.7.12. While I tried to use cv2.createBackgroundSubtractorMOG() I received the same error message (also tried without "create..."). But I was surprised when I discovered cv2.createBackgroundSubtractorKNN() with the same functionality instead ... and the test code works :)
      2 days I was confused and couldn't find where the problem is.






      share|improve this answer






























        1














        I'm using OpenCV-python 2.4.9, and Python2.7.8.



        In my environment, cv2.BackgroundSubtracorMOG and cv2.BackgroundSubtractorMOG2 are available.



        You can find out what attributes are available by using "help(cv2)" in your python shell.



        BackgroundSubtractorMOG(...)
        BackgroundSubtractorMOG([history, nmixtures, backgroundRatio[, noiseSigma]]) -> <BackgroundSubtractorMOG object>

        BackgroundSubtractorMOG2(...)
        BackgroundSubtractorMOG2([history, varThreshold[, bShadowDetection]]) -> <BackgroundSubtractorMOG2 object>





        share|improve this answer




























          1














          >>> import cv2
          >>> cv2.__version__
          >>> 3.2.0
          >>>bg_model = cv2.BackgroundSubtractorMOG2(0, 10)
          Traceback (most recent call last):
          File "/home/manivannan/pythonexamle/opencv/Samples/hand-gesture-recognition-opencv/HandRecognition.py", line 233, in <module>
          bg_model = cv2.BackgroundSubtractorMOG2(0, 10)
          AttributeError: 'module' object has no attribute 'BackgroundSubtractorMOG2'
          >>>bg_model = cv2.createBackgroundSubtractorMOG2(0, 10)


          Use createBackgroundSubtractorMOG2 instead of BackgroundSubtractorMOG2
          It's Working






          share|improve this answer




























            1














            According to https://docs.opencv.org/master/db/d5c/tutorial_py_bg_subtraction.html
            You should use cv.bgsegm.createBackgroundSubtractorMOG()



            I tested it on 3.4.0-dev and it worked.



            Example Code:



            import numpy as np
            import cv2 as cv
            cap = cv.VideoCapture('vtest.avi')
            fgbg = cv.bgsegm.createBackgroundSubtractorMOG()
            while(1):
            ret, frame = cap.read()
            fgmask = fgbg.apply(frame)
            cv.imshow('frame',fgmask)
            k = cv.waitKey(30) & 0xff
            if k == 27:
            break
            cap.release()
            cv.destroyAllWindows()





            share|improve this answer



















              protected by Community Nov 12 '18 at 7:49



              Thank you for your interest in this question.
              Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).



              Would you like to answer one of these unanswered questions instead?














              7 Answers
              7






              active

              oldest

              votes








              7 Answers
              7






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              31














              Replace the create.... with



              fgbg = cv2.BackgroundSubtractorMOG()






              share|improve this answer

























                31














                Replace the create.... with



                fgbg = cv2.BackgroundSubtractorMOG()






                share|improve this answer























                  31












                  31








                  31






                  Replace the create.... with



                  fgbg = cv2.BackgroundSubtractorMOG()






                  share|improve this answer












                  Replace the create.... with



                  fgbg = cv2.BackgroundSubtractorMOG()







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Dec 30 '13 at 21:03









                  user2897775user2897775

                  65958




                  65958























                      12














                      cv2.createbackgroundSubstractor() works in cv 3.0 for 2.4.x use cv2.BackgroundSubstractor()






                      share|improve this answer






















                      • IMO this is not an answer but a comment.
                        – Hello World
                        Jun 16 '14 at 17:11















                      12














                      cv2.createbackgroundSubstractor() works in cv 3.0 for 2.4.x use cv2.BackgroundSubstractor()






                      share|improve this answer






















                      • IMO this is not an answer but a comment.
                        – Hello World
                        Jun 16 '14 at 17:11













                      12












                      12








                      12






                      cv2.createbackgroundSubstractor() works in cv 3.0 for 2.4.x use cv2.BackgroundSubstractor()






                      share|improve this answer














                      cv2.createbackgroundSubstractor() works in cv 3.0 for 2.4.x use cv2.BackgroundSubstractor()







                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      edited Jun 16 '14 at 17:32









                      toniedzwiedz

                      12.6k85493




                      12.6k85493










                      answered Jun 16 '14 at 16:44









                      furyfury

                      12615




                      12615











                      • IMO this is not an answer but a comment.
                        – Hello World
                        Jun 16 '14 at 17:11
















                      • IMO this is not an answer but a comment.
                        – Hello World
                        Jun 16 '14 at 17:11















                      IMO this is not an answer but a comment.
                      – Hello World
                      Jun 16 '14 at 17:11




                      IMO this is not an answer but a comment.
                      – Hello World
                      Jun 16 '14 at 17:11











                      4














                      Thanks for the comments all. It seems that createBackgroundSubtractorMOG2() hasn't been added to OpenCV 2.4, but it is present in master branch, which can be compiled from github.



                      I am finding that cv2.BackgroundSubtractor() is working for what I need at the moment.



                      See http://code.opencv.org/issues/2812#note-5 for more details.






                      share|improve this answer

























                        4














                        Thanks for the comments all. It seems that createBackgroundSubtractorMOG2() hasn't been added to OpenCV 2.4, but it is present in master branch, which can be compiled from github.



                        I am finding that cv2.BackgroundSubtractor() is working for what I need at the moment.



                        See http://code.opencv.org/issues/2812#note-5 for more details.






                        share|improve this answer























                          4












                          4








                          4






                          Thanks for the comments all. It seems that createBackgroundSubtractorMOG2() hasn't been added to OpenCV 2.4, but it is present in master branch, which can be compiled from github.



                          I am finding that cv2.BackgroundSubtractor() is working for what I need at the moment.



                          See http://code.opencv.org/issues/2812#note-5 for more details.






                          share|improve this answer












                          Thanks for the comments all. It seems that createBackgroundSubtractorMOG2() hasn't been added to OpenCV 2.4, but it is present in master branch, which can be compiled from github.



                          I am finding that cv2.BackgroundSubtractor() is working for what I need at the moment.



                          See http://code.opencv.org/issues/2812#note-5 for more details.







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Sep 12 '13 at 15:54









                          user2765323user2765323

                          153118




                          153118





















                              4














                              I'm using



                              >>> import cv2
                              >>> cv2.__version__
                              >>> 3.2.0


                              and python 2.7.12. While I tried to use cv2.createBackgroundSubtractorMOG() I received the same error message (also tried without "create..."). But I was surprised when I discovered cv2.createBackgroundSubtractorKNN() with the same functionality instead ... and the test code works :)
                              2 days I was confused and couldn't find where the problem is.






                              share|improve this answer



























                                4














                                I'm using



                                >>> import cv2
                                >>> cv2.__version__
                                >>> 3.2.0


                                and python 2.7.12. While I tried to use cv2.createBackgroundSubtractorMOG() I received the same error message (also tried without "create..."). But I was surprised when I discovered cv2.createBackgroundSubtractorKNN() with the same functionality instead ... and the test code works :)
                                2 days I was confused and couldn't find where the problem is.






                                share|improve this answer

























                                  4












                                  4








                                  4






                                  I'm using



                                  >>> import cv2
                                  >>> cv2.__version__
                                  >>> 3.2.0


                                  and python 2.7.12. While I tried to use cv2.createBackgroundSubtractorMOG() I received the same error message (also tried without "create..."). But I was surprised when I discovered cv2.createBackgroundSubtractorKNN() with the same functionality instead ... and the test code works :)
                                  2 days I was confused and couldn't find where the problem is.






                                  share|improve this answer














                                  I'm using



                                  >>> import cv2
                                  >>> cv2.__version__
                                  >>> 3.2.0


                                  and python 2.7.12. While I tried to use cv2.createBackgroundSubtractorMOG() I received the same error message (also tried without "create..."). But I was surprised when I discovered cv2.createBackgroundSubtractorKNN() with the same functionality instead ... and the test code works :)
                                  2 days I was confused and couldn't find where the problem is.







                                  share|improve this answer














                                  share|improve this answer



                                  share|improve this answer








                                  edited Oct 12 '17 at 14:01

























                                  answered Mar 31 '17 at 20:15









                                  Ievgen S.Ievgen S.

                                  765




                                  765





















                                      1














                                      I'm using OpenCV-python 2.4.9, and Python2.7.8.



                                      In my environment, cv2.BackgroundSubtracorMOG and cv2.BackgroundSubtractorMOG2 are available.



                                      You can find out what attributes are available by using "help(cv2)" in your python shell.



                                      BackgroundSubtractorMOG(...)
                                      BackgroundSubtractorMOG([history, nmixtures, backgroundRatio[, noiseSigma]]) -> <BackgroundSubtractorMOG object>

                                      BackgroundSubtractorMOG2(...)
                                      BackgroundSubtractorMOG2([history, varThreshold[, bShadowDetection]]) -> <BackgroundSubtractorMOG2 object>





                                      share|improve this answer

























                                        1














                                        I'm using OpenCV-python 2.4.9, and Python2.7.8.



                                        In my environment, cv2.BackgroundSubtracorMOG and cv2.BackgroundSubtractorMOG2 are available.



                                        You can find out what attributes are available by using "help(cv2)" in your python shell.



                                        BackgroundSubtractorMOG(...)
                                        BackgroundSubtractorMOG([history, nmixtures, backgroundRatio[, noiseSigma]]) -> <BackgroundSubtractorMOG object>

                                        BackgroundSubtractorMOG2(...)
                                        BackgroundSubtractorMOG2([history, varThreshold[, bShadowDetection]]) -> <BackgroundSubtractorMOG2 object>





                                        share|improve this answer























                                          1












                                          1








                                          1






                                          I'm using OpenCV-python 2.4.9, and Python2.7.8.



                                          In my environment, cv2.BackgroundSubtracorMOG and cv2.BackgroundSubtractorMOG2 are available.



                                          You can find out what attributes are available by using "help(cv2)" in your python shell.



                                          BackgroundSubtractorMOG(...)
                                          BackgroundSubtractorMOG([history, nmixtures, backgroundRatio[, noiseSigma]]) -> <BackgroundSubtractorMOG object>

                                          BackgroundSubtractorMOG2(...)
                                          BackgroundSubtractorMOG2([history, varThreshold[, bShadowDetection]]) -> <BackgroundSubtractorMOG2 object>





                                          share|improve this answer












                                          I'm using OpenCV-python 2.4.9, and Python2.7.8.



                                          In my environment, cv2.BackgroundSubtracorMOG and cv2.BackgroundSubtractorMOG2 are available.



                                          You can find out what attributes are available by using "help(cv2)" in your python shell.



                                          BackgroundSubtractorMOG(...)
                                          BackgroundSubtractorMOG([history, nmixtures, backgroundRatio[, noiseSigma]]) -> <BackgroundSubtractorMOG object>

                                          BackgroundSubtractorMOG2(...)
                                          BackgroundSubtractorMOG2([history, varThreshold[, bShadowDetection]]) -> <BackgroundSubtractorMOG2 object>






                                          share|improve this answer












                                          share|improve this answer



                                          share|improve this answer










                                          answered Oct 19 '14 at 4:16









                                          watawata

                                          111




                                          111





















                                              1














                                              >>> import cv2
                                              >>> cv2.__version__
                                              >>> 3.2.0
                                              >>>bg_model = cv2.BackgroundSubtractorMOG2(0, 10)
                                              Traceback (most recent call last):
                                              File "/home/manivannan/pythonexamle/opencv/Samples/hand-gesture-recognition-opencv/HandRecognition.py", line 233, in <module>
                                              bg_model = cv2.BackgroundSubtractorMOG2(0, 10)
                                              AttributeError: 'module' object has no attribute 'BackgroundSubtractorMOG2'
                                              >>>bg_model = cv2.createBackgroundSubtractorMOG2(0, 10)


                                              Use createBackgroundSubtractorMOG2 instead of BackgroundSubtractorMOG2
                                              It's Working






                                              share|improve this answer

























                                                1














                                                >>> import cv2
                                                >>> cv2.__version__
                                                >>> 3.2.0
                                                >>>bg_model = cv2.BackgroundSubtractorMOG2(0, 10)
                                                Traceback (most recent call last):
                                                File "/home/manivannan/pythonexamle/opencv/Samples/hand-gesture-recognition-opencv/HandRecognition.py", line 233, in <module>
                                                bg_model = cv2.BackgroundSubtractorMOG2(0, 10)
                                                AttributeError: 'module' object has no attribute 'BackgroundSubtractorMOG2'
                                                >>>bg_model = cv2.createBackgroundSubtractorMOG2(0, 10)


                                                Use createBackgroundSubtractorMOG2 instead of BackgroundSubtractorMOG2
                                                It's Working






                                                share|improve this answer























                                                  1












                                                  1








                                                  1






                                                  >>> import cv2
                                                  >>> cv2.__version__
                                                  >>> 3.2.0
                                                  >>>bg_model = cv2.BackgroundSubtractorMOG2(0, 10)
                                                  Traceback (most recent call last):
                                                  File "/home/manivannan/pythonexamle/opencv/Samples/hand-gesture-recognition-opencv/HandRecognition.py", line 233, in <module>
                                                  bg_model = cv2.BackgroundSubtractorMOG2(0, 10)
                                                  AttributeError: 'module' object has no attribute 'BackgroundSubtractorMOG2'
                                                  >>>bg_model = cv2.createBackgroundSubtractorMOG2(0, 10)


                                                  Use createBackgroundSubtractorMOG2 instead of BackgroundSubtractorMOG2
                                                  It's Working






                                                  share|improve this answer












                                                  >>> import cv2
                                                  >>> cv2.__version__
                                                  >>> 3.2.0
                                                  >>>bg_model = cv2.BackgroundSubtractorMOG2(0, 10)
                                                  Traceback (most recent call last):
                                                  File "/home/manivannan/pythonexamle/opencv/Samples/hand-gesture-recognition-opencv/HandRecognition.py", line 233, in <module>
                                                  bg_model = cv2.BackgroundSubtractorMOG2(0, 10)
                                                  AttributeError: 'module' object has no attribute 'BackgroundSubtractorMOG2'
                                                  >>>bg_model = cv2.createBackgroundSubtractorMOG2(0, 10)


                                                  Use createBackgroundSubtractorMOG2 instead of BackgroundSubtractorMOG2
                                                  It's Working







                                                  share|improve this answer












                                                  share|improve this answer



                                                  share|improve this answer










                                                  answered Sep 4 '17 at 17:14









                                                  Manivannan MurugavelManivannan Murugavel

                                                  35027




                                                  35027





















                                                      1














                                                      According to https://docs.opencv.org/master/db/d5c/tutorial_py_bg_subtraction.html
                                                      You should use cv.bgsegm.createBackgroundSubtractorMOG()



                                                      I tested it on 3.4.0-dev and it worked.



                                                      Example Code:



                                                      import numpy as np
                                                      import cv2 as cv
                                                      cap = cv.VideoCapture('vtest.avi')
                                                      fgbg = cv.bgsegm.createBackgroundSubtractorMOG()
                                                      while(1):
                                                      ret, frame = cap.read()
                                                      fgmask = fgbg.apply(frame)
                                                      cv.imshow('frame',fgmask)
                                                      k = cv.waitKey(30) & 0xff
                                                      if k == 27:
                                                      break
                                                      cap.release()
                                                      cv.destroyAllWindows()





                                                      share|improve this answer

























                                                        1














                                                        According to https://docs.opencv.org/master/db/d5c/tutorial_py_bg_subtraction.html
                                                        You should use cv.bgsegm.createBackgroundSubtractorMOG()



                                                        I tested it on 3.4.0-dev and it worked.



                                                        Example Code:



                                                        import numpy as np
                                                        import cv2 as cv
                                                        cap = cv.VideoCapture('vtest.avi')
                                                        fgbg = cv.bgsegm.createBackgroundSubtractorMOG()
                                                        while(1):
                                                        ret, frame = cap.read()
                                                        fgmask = fgbg.apply(frame)
                                                        cv.imshow('frame',fgmask)
                                                        k = cv.waitKey(30) & 0xff
                                                        if k == 27:
                                                        break
                                                        cap.release()
                                                        cv.destroyAllWindows()





                                                        share|improve this answer























                                                          1












                                                          1








                                                          1






                                                          According to https://docs.opencv.org/master/db/d5c/tutorial_py_bg_subtraction.html
                                                          You should use cv.bgsegm.createBackgroundSubtractorMOG()



                                                          I tested it on 3.4.0-dev and it worked.



                                                          Example Code:



                                                          import numpy as np
                                                          import cv2 as cv
                                                          cap = cv.VideoCapture('vtest.avi')
                                                          fgbg = cv.bgsegm.createBackgroundSubtractorMOG()
                                                          while(1):
                                                          ret, frame = cap.read()
                                                          fgmask = fgbg.apply(frame)
                                                          cv.imshow('frame',fgmask)
                                                          k = cv.waitKey(30) & 0xff
                                                          if k == 27:
                                                          break
                                                          cap.release()
                                                          cv.destroyAllWindows()





                                                          share|improve this answer












                                                          According to https://docs.opencv.org/master/db/d5c/tutorial_py_bg_subtraction.html
                                                          You should use cv.bgsegm.createBackgroundSubtractorMOG()



                                                          I tested it on 3.4.0-dev and it worked.



                                                          Example Code:



                                                          import numpy as np
                                                          import cv2 as cv
                                                          cap = cv.VideoCapture('vtest.avi')
                                                          fgbg = cv.bgsegm.createBackgroundSubtractorMOG()
                                                          while(1):
                                                          ret, frame = cap.read()
                                                          fgmask = fgbg.apply(frame)
                                                          cv.imshow('frame',fgmask)
                                                          k = cv.waitKey(30) & 0xff
                                                          if k == 27:
                                                          break
                                                          cap.release()
                                                          cv.destroyAllWindows()






                                                          share|improve this answer












                                                          share|improve this answer



                                                          share|improve this answer










                                                          answered Jan 9 '18 at 23:24









                                                          Qin HeyangQin Heyang

                                                          963




                                                          963















                                                              protected by Community Nov 12 '18 at 7:49



                                                              Thank you for your interest in this question.
                                                              Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).



                                                              Would you like to answer one of these unanswered questions instead?



                                                              Popular posts from this blog

                                                              Kleinkühnau

                                                              Makov (Slowakei)

                                                              Deutsches Schauspielhaus