BackgroundSubtractorCNT is in OpenCV 3.3.0

the impossible code - fastest background subtraction

Although BackgroundSubtractorCNT is in OpenCv 3.3.0, future features and improvements will be added in the offline project.

Proudly announcing that BackgroundSubtractorCNT is in OpenCV

The guys at OpenCV decided to incorporate the original code of BackgroundSubtractorCNT into opencv_contrib-3.3.0.

Although I didn’t motivate this (see here), I’m pretty glad they found it useful enough to take it in.


You can potentially use the original BackgroundSubtractorCNT project with opencv_conrib-3.3.0. This will only be beneficial if and when the BackgroundSubtractorCNT project will advance faster in development.

If you’re going to do that, then:

  • For using the code from the BackgroundSubtractorCNT project, you should be okay as long as you’re:
    • Not “using namespace cv::bgsubcnt;
    • Are using the cv::bgsubcnt namespace explicitly, as in cv::bgsubcnt::createBackgroundSubtractorCNT(…).
  • For using the code from the opencv_contrib-3.3.0, use it as you would use any other of their BackgroundSubtractor classes.

Future development

Currently BackgroundSubtractorCNT  is maintained as a project of its own. Future development of features and improvements will happen in this offline project.


Whichever code you’re going to use (same code – different progress), the best documentation is currently available at the official site.

Until next time,

Sagi Zeevi

A software developer brain surgeon ... if software only had a brain. An electronics hobbyist heart surgeon ... if electronics only had a heart.

You may also like...

7 Responses

  1. JaeWoong says:

    Hi I am a student. How can I use this BGS in pyhton OpenCV 3.3.0

  2. JaeWoong says:

    thanks your job. but
    There isn’t cv2.createBackgroundSubtractorCNT() or cv2.bgsegm.BackgroundSubtractorCNT()
    I found all of the modules in cv2 but there isn’t
    Would you please imform how can I do it in OpenCV 3.3.0_contrib,python? not ‘import bgsubcnt’

    • Sagi Zeevi says:

      This worked for me just yesterday, on Windows10 after installing opencv_contrib with pip:
      python -c “import cv2; fgbg = cv2.bgsegm.createBackgroundSubtractorCNT(); print(fgbg)”

      Note that I’m not directly responsible for the code inserted into opencv_contrib, nor for the pip package of it, if you install with pip.

  3. Galileo says:

    Hi, Thanks you for the great work. CNT is very fast and gives excellent results on static background videos. Do you have any ideas to make it even better for dynamic background such as lighting?

    I do not find any document describing the algorithm. Could you please share it? Thank you.

    • Sagi Zeevi says:


      I have some ideas on improving it in some areas, but I’m currently too occupied to pursue them and I’m not yet sure if to try and monetize these ideas (cheaply monetize – few bucks – don’t worry)…
      I didn’t share the algorithm documentation, but you can understand it good enough for tuning it here.

Leave a Reply

Scroll Up