andrewssobral / bgslibrary

A C++ Background Subtraction Library with wrappers for Python, MATLAB, Java and GUI on QT
MIT License
2.19k stars 740 forks source link

Bad argument while use bgs with python3 #174

Open LjwPanda opened 4 years ago

LjwPanda commented 4 years ago

my platform is win10 use python3.7 and bgs2.0 bgs compiled with opencv3.4.5 I got error RuntimeError: OpenCV(3.4.5) C:\build\3_4_winpack-build-win64-vc14\opencv\modules\core\src\array.cpp:1246: error: (-5:Bad argument) Array should be CvMat or IplImage in function 'cvGetSize' in a lot of model,such as MultiCue ,LBMixtureOfGaussians and so on

what is my problem?

andrewssobral commented 4 years ago

Hi @LjwPanda , thanks for reporting this issue. Unfortunately I could not reproduce your error on my local environment. From my side, I used:

OpenCV 3.4.5
Python 3.7.2
CMake 3.16
Visual Studio 14 2015 Win64
Windows 10 Pro
...

Please see my logs below:

andre@DELL-M4700 E:\GitHub_Andrews\bgslibrary\build_win_ocv3
> cmake -DOpenCV_DIR=E:\OpenCV\opencv-3.4.5\build -DBGS_PYTHON_SUPPORT=ON -DBGS_CORE_STATIC=ON -G "Visual Studio 14 2015 Win64" ..
-- Selecting Windows SDK version 10.0.14393.0 to target Windows 10.0.18363.
-- The C compiler identification is MSVC 19.0.24215.1
-- The CXX compiler identification is MSVC 19.0.24215.1
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/x86_amd64/cl.exe
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/x86_amd64/cl.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/x86_amd64/cl.exe
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/x86_amd64/cl.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
--
-- BGS_PYTHON_SUPPORT: ON
-- BGS_PYTHON_ONLY:    OFF
-- BGS_CORE_STATIC:    ON
-- PYTHON VERSION: 3
-- OpenCV ARCH: x64
-- OpenCV RUNTIME: vc14
-- OpenCV STATIC: ON
-- Found OpenCV: E:/OpenCV/opencv-3.4.5/build (found version "3.4.5")
-- Found OpenCV 3.4.5 in E:/OpenCV/opencv-3.4.5/build/x64/vc14/lib
-- You might need to add E:\OpenCV\opencv-3.4.5\build\x64\vc14\bin to your PATH to be able to run your applications.
--
-- OpenCV library status:
--     version: 3.4.5
--     libraries: opencv_calib3d;opencv_core;opencv_dnn;opencv_features2d;opencv_flann;opencv_highgui;opencv_imgcodecs;opencv_imgproc;opencv_ml;opencv_objdetect;opencv_photo;opencv_shape;opencv_stitching;opencv_superres;opencv_video;opencv_videoio;opencv_videostab;opencv_world
--     include path: E:/OpenCV/opencv-3.4.5/build/include;E:/OpenCV/opencv-3.4.5/build/include/opencv

-- Found PythonInterp: C:/Python37/python.exe (found suitable version "3.7.2", minimum required is "3")
-- Found PythonLibs: C:/Python37/libs/Python37.lib
-- pybind11 v2.3.dev1
--
-- Python library status:
--     executable: C:/Python37/python.exe
--     library:
--     include path: C:/Python37/include
-- NUMPY_INCLUDE_DIR: C:\Python37\lib\site-packages\numpy\core\include

-- Bulding bgslibrary_core STATIC
-- You might need to add E:/GitHub_Andrews/bgslibrary/build_win_ocv3 to your PATH to be able to run your applications.
-- > set PATH=%PATH%;E:/GitHub_Andrews/bgslibrary/build_win_ocv3

-- Configuring done
-- Generating done
-- Build files have been written to: E:/GitHub_Andrews/bgslibrary/build_win_ocv3

andre@DELL-M4700 E:\GitHub_Andrews\bgslibrary\build_win_ocv3
> call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools\vsvars32.bat"

andre@DELL-M4700 E:\GitHub_Andrews\bgslibrary\build_win_ocv3
> devenv bgslibrary.sln

After compilation, it worked successfully with an input video, as you can see below:

andre@DELL-M4700 E:\GitHub_Andrews\bgslibrary
> build_win_ocv3\bgslibrary.exe -uf -fn=dataset/video.avi
---------------------------------------------
Background Subtraction Library
https://github.com/andrewssobral/bgslibrary
This software is under the MIT License
---------------------------------------------
Using OpenCV version 3.4.5
+VideoAnalysis()
use_file:    1
filename:    dataset/video.avi
use_camera:  0
cameraIndex: 0
use_comp:    0
frameToStop: 0
imgref:
+VideoCapture()
+FrameProcessor()
+FrameDifference()
Openning: dataset/video.avi
OK
input->fps:30
input->width:640
input->height:360
loopDelay:33.3333
Press 'ESC' to stop...
Processing finished, enter:
R - Repeat
Q - Quit
-VideoAnalysis()
-VideoCapture()
-FrameProcessor()
-FrameDifference()

andre@DELL-M4700 E:\GitHub_Andrews\bgslibrary
andrewssobral commented 4 years ago

Hi @LjwPanda I found the problem, it is on Python side, I am investigating...

andrewssobral commented 2 years ago

Hi @LjwPanda , sorry for my delayed feedback to you. For info, I just released a new version of the BGSLibrary, now v3.1.0. I fixed several issues concerning the different OpenCV versions. 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. Everything is working for me, could you please check in your side if this new version fix your issues? Thanks in advance, Andrews