sagi-z / BackgroundSubtractorCNT

A very fast background subtraction implementation for OpenCV 3.1.0 and above
Other
117 stars 28 forks source link

Build error in WSL #15

Closed gasparramoa closed 3 years ago

gasparramoa commented 3 years ago

Hello, I'm using WSL (Windows subsystem Linux), I have OpenCV installed correctly but I am not able to install the python wrapper.

I'm using Python 3.8.5 I'm using OpenCV 4.4.0 (Maybe that's because of this?)

I can successfully do the cmake .. command but I cannot go further than that.

These are the commands that I used: cmake -DBUILD_SHARED_LIBS=ON -DPYTHON_EXTENSION=ON -DCMAKE_BUILD_TYPE=DEBUG -DPYTHON=/usr/bin/python3 .. output:

OpenCV_LIB_DIR is: OpenCV_LIBS_NATIVE is: 'opencv_calib3d','opencv_core','opencv_dnn','opencv_features2d','opencv_flann','opencv_gapi','opencv_highgui','opencv_imgcodecs','opencv_imgproc','opencv_ml','opencv_objdetect','opencv_photo','opencv_stitching','opencv_video','opencv_videoio' OpenCV_LIB_DIR_NATIVE is: OpenCV_INCLUDE_DIRS_NATIVE is: '/usr/local/include/opencv4' CMAKE_CURRENT_SOURCE_DIR_NATIVE is: /mnt/c/wsl-gaspar/FingerRec/BackgroundSubtractorCNT/python BGSUBCNT_INCLUDE_DIR_NATIVE is: /mnt/c/wsl-gaspar/FingerRec/BackgroundSubtractorCNT PYTHON_PREFIX is '/usr' PYTHON_SITE_DIR is 'lib/python3.8/dist-packages' -- Configuring done -- Generating done -- Build files have been written to: /mnt/c/wsl-gaspar/FingerRec/BackgroundSubtractorCNT/build

and them I simply do: make output:

[ 40%] Built target bgsubcnt [ 80%] Built target demo [100%] Generating build/timestamp running install running build running build_py copying /mnt/c/wsl-gaspar/FingerRec/BackgroundSubtractorCNT/python/bgsubcnt.py -> build/lib.linux-x86_64-3.8 running build_ext building '_bgsubcnt' extension swigging /mnt/c/wsl-gaspar/FingerRec/BackgroundSubtractorCNT/python/bgsubcnt.i to /mnt/c/wsl-gaspar/FingerRec/BackgroundSubtractorCNT/python/bgsubcnt_wrap.cpp swig -python -c++ -builtin -I/mnt/c/wsl-gaspar/FingerRec/BackgroundSubtractorCNT/python -o /mnt/c/wsl-gaspar/FingerRec/BackgroundSubtractorCNT/python/bgsubcnt_wrap.cpp /mnt/c/wsl-gaspar/FingerRec/BackgroundSubtractorCNT/python/bgsubcnt.i x86_64-linux-gnu-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/mnt/c/wsl-gaspar/FingerRec/BackgroundSubtractorCNT -I/home/gaspar/.local/lib/python3.8/site-packages/numpy/core/include -I/usr/local/include/opencv4 -I/usr/include/python3.8 -c /mnt/c/wsl-gaspar/FingerRec/BackgroundSubtractorCNT/python/opencv_swig_python.cpp -o build/temp.linux-x86_64-3.8/mnt/c/wsl-gaspar/FingerRec/BackgroundSubtractorCNT/python/opencv_swig_python.o /mnt/c/wsl-gaspar/FingerRec/BackgroundSubtractorCNT/python/opencv_swig_python.cpp: In member function ‘cv::UMatData NumpyAllocator::allocate(int, const int, int, void, size_t, int, cv::UMatUsageFlags) const’: /mnt/c/wsl-gaspar/FingerRec/BackgroundSubtractorCNT/python/opencv_swig_python.cpp:121:75: error: invalid conversion from ‘int’ to ‘cv::AccessFlag’ [-fpermissive] 121 return stdAllocator->allocate(dims0, sizes, type, data, step, flags, usageFlags); ^~~~~
int
In file included from /usr/local/include/opencv4/opencv2/core.hpp:59, from /usr/local/include/opencv4/opencv2/opencv.hpp:52, from /mnt/c/wsl-gaspar/FingerRec/BackgroundSubtractorCNT/python/opencv_swig_python.h:4, from /mnt/c/wsl-gaspar/FingerRec/BackgroundSubtractorCNT/python/opencv_swig_python.cpp:1: /usr/local/include/opencv4/opencv2/core/mat.hpp:476:69: note: initializing argument 6 of ‘virtual cv::UMatData cv::MatAllocator::allocate(int, const int, int, void, size_t, cv::AccessFlag, cv::UMatUsageFlags) const’ 476 void data, size_t step, AccessFlag flags, UMatUsageFlags usageFlags) const = 0; ~~~^~~~~ /mnt/c/wsl-gaspar/FingerRec/BackgroundSubtractorCNT/python/opencv_swig_python.cpp: In member function ‘bool NumpyAllocator::allocate(cv::UMatData*, int, cv::UMatUsageFlags) const’: /mnt/c/wsl-gaspar/FingerRec/BackgroundSubtractorCNT/python/opencv_swig_python.cpp:146:42: error: invalid conversion from ‘int’ to ‘cv::AccessFlag’ [-fpermissive] 146 return stdAllocator->allocate(u, accessFlags, usageFlags); ^~~
int

In file included from /usr/local/include/opencv4/opencv2/core.hpp:59, from /usr/local/include/opencv4/opencv2/opencv.hpp:52, from /mnt/c/wsl-gaspar/FingerRec/BackgroundSubtractorCNT/python/opencv_swig_python.h:4, from /mnt/c/wsl-gaspar/FingerRec/BackgroundSubtractorCNT/python/opencv_swig_python.cpp:1: /usr/local/include/opencv4/opencv2/core/mat.hpp:477:54: note: initializing argument 2 of ‘virtual bool cv::MatAllocator::allocate(cv::UMatData, cv::AccessFlag, cv::UMatUsageFlags) const’ 477 | virtual bool allocate(UMatData data, AccessFlag accessflags, UMatUsageFlags usageFlags) const = 0; | ~~~^~~ /mnt/c/wsl-gaspar/FingerRec/BackgroundSubtractorCNT/python/opencv_swig_python.cpp: At global scope: /mnt/c/wsl-gaspar/FingerRec/BackgroundSubtractorCNT/python/opencv_swig_python.cpp:167:23: error: cannot declare variable ‘g_numpyAllocator’ to be of abstract type ‘NumpyAllocator’ 167 | static NumpyAllocator g_numpyAllocator; | ^~~~ /mnt/c/wsl-gaspar/FingerRec/BackgroundSubtractorCNT/python/opencv_swig_python.cpp:96:7: note: because the following virtual functions are pure within ‘NumpyAllocator’: 96 | class NumpyAllocator : public MatAllocator | ^~~~~~ In file included from /usr/local/include/opencv4/opencv2/core.hpp:59, from /usr/local/include/opencv4/opencv2/opencv.hpp:52, from /mnt/c/wsl-gaspar/FingerRec/BackgroundSubtractorCNT/python/opencv_swig_python.h:4, from /mnt/c/wsl-gaspar/FingerRec/BackgroundSubtractorCNT/python/opencv_swig_python.cpp:1: /usr/local/include/opencv4/opencv2/core/mat.hpp:475:23: note: ‘virtual cv::UMatData cv::MatAllocator::allocate(int, const int, int, void, size_t, cv::AccessFlag, cv::UMatUsageFlags) const’ 475 | virtual UMatData allocate(int dims, const int sizes, int type, | ^~~~ /usr/local/include/opencv4/opencv2/core/mat.hpp:477:18: note: ‘virtual bool cv::MatAllocator::allocate(cv::UMatData, cv::AccessFlag, cv::UMatUsageFlags) const’ 477 | virtual bool allocate(UMatData data, AccessFlag accessflags, UMatUsageFlags usageFlags) const = 0; | ^~~~ error: command 'x86_64-linux-gnu-gcc' failed with exit status 1 make[2]: [python/CMakeFiles/bgsubcnt_python.dir/build.make:65: python/build/timestamp] Error 1 make[1]: [CMakeFiles/Makefile2:152: python/CMakeFiles/bgsubcnt_python.dir/all] Error 2 make: *** [Makefile:152: all] Error 2

Thanks in advance!

Gaspar

sagi-z commented 3 years ago

Hi, Is there a specific reason you are building this yourself? If there is no specific reason for that then please use the code which was integrated into OpenCV

gasparramoa commented 3 years ago

Hello @sagi-z,

I'm building it because if I use the method in python3 I get this error: File "algorithm.py", line 93, in <module> fgbg = cv2.createBackgroundSubtractorCNT() AttributeError: module 'cv2.cv2' has no attribute 'createBackgroundSubtractorCNT'

For what I learn, in python you have to do import bgsubcnt but you can only have access to this library if you build using the git repo right ?

Maybe I am doing something wrong that is missing me. I am using OpenCV 4.4.0 but I also have a virtual environment with OpenCV 4.5.1-pre.

sagi-z commented 3 years ago
  1. Make sure you have opencv-contrib installed.
  2. Then this should work (take note to use the bgsem module):
    fgbg = cv2.bgsegm.createBackgroundSubtractorCNT()