andrewssobral / bgslibrary

A C++ Background Subtraction Library with wrappers for Python, MATLAB, Java and GUI on QT

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Many of the algorithms not available under OpenCV 4.x

leavittx opened this issue · comments

I wonder why over 20 algorithms (DPAdaptiveMedian/MultiLayer/KDE among them) are only available under OpenCV 2.x/3.x. I'm using Python bindings for bgs

Hi @leavittx , yes, in fact, I need to adapt some algorithms to work on OpenCV 4.x due to removal of old APIs. I'm close to finish this work, I will let you update when I've done. Thanks.

Thanks, can't wait for getting it to work!

for now what is the best example to run in opencv 4 of BGS using a base frame to get background for subsequent ones?

Hi @andrewssobral , I just managed to build and install the library for OpenCV 4.5.3 but I'm having the same issue that many algorithms don't seem to be part of the module. Did something incorrect happen or is the full implementation into OpenCV 4.x still pending? Thanks for your help!

Hello @leavittx @TheMasterRoot @simon-hauser
Sorry for my absence, I had to put the bgslibrary in standby for a long time.
Yes, unfortunately, compiling the current version of the bgslibrary with OpenCV 4.x don't support all algorithms yet.
I need to spend some time for code refactoring, bug fixes and improvements.
I'm planning to dedicate some time to bgslibrary by the end of this year (in december probably).

@TheMasterRoot
When you say "using a base frame to get background for subsequent ones" you mean the user set a specific image to be the background reference before doing the background/foreground separation?
The algorithm StaticFrameDifference do that automatically using the first video frame as a background reference before computing the foreground detection for the next frames.

Hi @andrewssobral . I apologize for poking you again :P. Just wondered if you had the time to add the full OpenCV 4.x support? I wanted to use a new OpenCV version for my project, but please let me know if you feel like this is taking you longer, then I will try downgrading to an OpenCV 3.x version to get all the algorithms. cheers, and thanks for your work!

Hello @simon-hauser sorry for my late reply,
I think this will take 1 month at least due to my limited availability.

Hi @andrewssobral . Thanks for your reply. I downgraded to OpenCV 3.4 and could successfully compile the library, however I ran into the same issue as in #174 where for some algorithms I get a (-5:Bad argument) error (I'm on win10). Your reply there was that you found the problem on the Python side.
I'd really love to use the full library, preferrably on windows. I will now try to proceed with a Virtual Machine and compile it under linux. If you manage to find some time, I would be most delighted to try again on windows in case you'd do progress either for the OpenCV 4.x support or a #174 fix. cheers

Hello @simon-hauser @TheMasterRoot @leavittx , sorry for my delayed feedback to you.
For info, I just released a new version of the BGSLibrary, now v3.1.0.
I tested it on Windows, Mac and Linux, both compiling the C++ library on OpenCV 3.4.7, 3.4.16 and 4.6.0.
I also tested its respective Python wrapper and GT user interface.
Here's the updated steps to install it on Windows:
https://github.com/andrewssobral/bgslibrary/wiki/Installation-instructions---Windows#how-to-compile-on-windows-10--msvs2019--opencv-347
I also updated the Python package on PyPi: https://pypi.org/project/pybgs/3.1.0.post0/
And created a few docker files to build BGSLibrary with OpenCV 3.4.7, 3.4.16 and 4.6.0: https://github.com/andrewssobral/docker/tree/master/bgslibrary
I also updated the list of supported algorithm for each OpenCV version:
https://github.com/andrewssobral/bgslibrary/wiki/List-of-available-algorithms
Unfortunately only a few algorithms works with OpenCV >= 4, a very big work should be done to convert some algorithms to OpenCV 4.
By the way, everything is working for me, could you please check in your side if this new version fix your issues?
Thanks in advance,
Andrews

Compile with OpenCV 4 (also compiled from source) and can run 16/17 of the algorithms listed on the info page - MyBGS is not available from what I can tell. Can you let me know what is required to convert the remaining algorithms and in what priority? I could give you a hand doing it. Ideally starting with the most promising!

Hi @KhanMechAI ,

Unfortunately, many algorithms are still implemented using legacy code. I've compiled a list of available algorithms for each version of OpenCV, which you can find here: https://github.com/andrewssobral/bgslibrary/wiki/List-of-available-algorithms.

If you're interested, I would love your help in converting/migrating some of these algorithms to OpenCV4. One of my favorite algorithms is MultiLayer, which is only available for OpenCV version <= 3.4.7.

Additionally, I would like to push for the conversion of the DP* algorithms (DPAdaptiveMedian, DPEigenbackground, DPGrimsonGMM, DPMean, DPPratiMediod, DPTexture, DPWrenGA, and DPZivkovicAGMM) to OpenCV4. These algorithms share the same base class, but a significant amount of code refactoring is required.

Let me know if you're interested in collaborating on this project.

Yep more than happy to collaborate on it. I'll start with the multilayer. If you can point me to a good example of the refactoring from one of the other algorithms I can get started. Or if you have any other tips, please let me know

I've been doing some testing. Setup is

  • Mac OS M1 Venura 13.1
  • OpenCV 4.6 (homebrew)
  • BGSLibrary 3.2.0
  • C++ only (not python bindings)

The following algorithms (not already in the included algorithms list for OpenCV 4.X) work on the Demo.cpp:

  • FuzzyChoquetIntegral
  • FuzzySugenoIntegral
  • IndependentMultimodal *
  • KDE
  • LBAdaptiveSOM
  • LBFuzzyAdaptiveSOM
  • LBFuzzyGaussian
  • LBSimpleGaussian
  • VueMeter

*Worked for a short time before memory error

The remaining algorithms will need refactoring largely due to legacy opencv functions and the usage of IplImage instead of cv::Mat. So if @andrewssobral or anyone else has advice on migrating from IplImage to cv::Mat that would be great, the other functions shouldnt be that hard. But hopefully we can push out a few more algorithms.

I've got a fork here that I'm using to test changes.

Also one of the changes I've made is to rename the src folder and all references too it to bgslibrary according the Canonical Project Structure. So when the library is built it can be imported with #include <bgslibrary/algorithms/algorithm.h>. Bit of a breaking change, but I was having nightmares about conflicts with other source directories.

Hello @KhanMechAI , thank you for your insights!

I agree that the large legacy code is the main challenge. Although it's better to migrate to cv::Mat, OpenCV 4.x still supports IplImage. You can find some conversion examples on this Stack Overflow thread: https://stackoverflow.com/questions/15925084/conversion-from-iplimage-to-cvmat

The biggest issue lies in the missing functions that are no longer available or have changed from OpenCV 3.4.7 to OpenCV 4. That's why I've added several pragmas to the source code to restrict usage to OpenCV 2 and 3.

Concerning:

FuzzyChoquetIntegral
FuzzySugenoIntegral
IndependentMultimodal *
KDE
LBAdaptiveSOM
LBFuzzyAdaptiveSOM
LBFuzzyGaussian
LBSimpleGaussian
VueMeter

I'll double-check on other operating systems (Windows, Linux, and Mac [Intel]) to ensure everything runs smoothly.

I agree that we should rename the src folder and update all references to it as bgslibrary. Perhaps it's best to create an initial pull request for this change, and once it's merged, we can proceed with migrating the algorithms to OpenCV 4. What do you think?

Thank you

Hey @andrewssobral yep that sounds like a plan! I'll cherry pick the renaming and open a PR.

Perfect, thank you @KhanMechAI , please let me know when it's ready for merge.
I launched some automated workflows on #219 but they are failing.

/__w/bgslibrary/bgslibrary/wrapper/python/bgslibrary_module.cpp:7:10: fatal error: ../../src/algorithms/algorithms.h: No such file or directory
    7 | #include "../../src/algorithms/algorithms.h"
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

We still need to fix some paths.

Great so all merged for that one, I'll submit a PR for the algorithms I've had success with too

Also, how can I contribute to the wiki? I'd like to update the "How to integrate into your project" document

Great so all merged for that one, I'll submit a PR for the algorithms I've had success with too

Great, thanks a lot!
If you agree you can start with the ones you checked that are already compatible with OpenCV 4.6, as you stated before:
What do you think?

The following algorithms (not already in the included algorithms list for OpenCV 4.X) work on the Demo.cpp:
FuzzyChoquetIntegral
FuzzySugenoIntegral
IndependentMultimodal *
KDE
LBAdaptiveSOM
LBFuzzyAdaptiveSOM
LBFuzzyGaussian
LBSimpleGaussian
VueMeter

Also, how can I contribute to the wiki? I'd like to update the "How to integrate into your project" document

Unfortunately, it appears that only the repository owner has permission to modify the Wiki page, which is not ideal. :-(

If you prefer, you can send me a Markdown text, and I copy and paste to the corresponding Wiki page, what do you think? I am open if you have any suggestion.

Thank you

Great so all merged for that one, I'll submit a PR for the algorithms I've had success with too

Great, thanks a lot! If you agree you can start with the ones you checked that are already compatible with OpenCV 4.6, as you stated before: What do you think?

The following algorithms (not already in the included algorithms list for OpenCV 4.X) work on the Demo.cpp:
FuzzyChoquetIntegral
FuzzySugenoIntegral
IndependentMultimodal *
KDE
LBAdaptiveSOM
LBFuzzyAdaptiveSOM
LBFuzzyGaussian
LBSimpleGaussian
VueMeter

@KhanMechAI please ignore this message. I just enabled the 9 algorithms you cited in this commit d21861b