shimat / opencvsharp

OpenCV wrapper for .NET
Apache License 2.0
5.41k stars 1.15k forks source link

OpenCV3 Linux support: Error compiling OpenCvSharpExtern #377

Closed zandam-xrn closed 4 years ago

zandam-xrn commented 7 years ago

Summary of your issue

I've tried to compile OpenCvSharpExtern on Linux where I've already installed OpenCv3 with Cuda acceleration. I need to maintain OpenCv3 alignment between developement workstation (Windows Visual Studio OpenCv3) with the deployment machine (Linux OpenCv3).

Environment

Linux keypc01 4.9.36-aufs #2 SMP Fri Aug 11 18:11:18 UTC 2017 x86_64 Intel(R) Core(TM) i5-7600K CPU @ 3.80GHz GenuineIntel GNU/Linux.

OpenCv 3.2.0 System GCC 6.4.0 Cuda GCC 5.4.0 Mono 4.8.0.524

What did you do when you faced the problem?

Compiling OpenCvSharpExtern (make).

Output:

In file included from /opencvsharp/src/OpenCvSharpExtern/aruco.h:4:0,
                 from /opencvsharp/src/OpenCvSharpExtern/aruco.cpp:1:
/opencvsharp/src/OpenCvSharpExtern/include_opencv.h:28:32: fatal error: opencv2/tracking.hpp: No such file or directory
 #include <opencv2/tracking.hpp>
                                ^
compilation terminated.
make[2]: *** [OpenCvSharpExtern/CMakeFiles/OpenCvSharpExtern.dir/build.make:63: OpenCvSharpExtern/CMakeFiles/OpenCvSharpExtern.dir/aruco.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:86: OpenCvSharpExtern/CMakeFiles/OpenCvSharpExtern.dir/all] Error 2
make: *** [Makefile:130: all] Error 2
zandam-xrn commented 7 years ago

I moved forward trying to fix this error. The main issue was that the opencv files in my system had a different path, so I edited this file: /Data/Dev01/opencvsharp/opencvsharp/src/OpenCvSharpExtern/include_opencv.h with the right opencv2 files location and this error: /Data/Dev01/opencvsharp/opencvsharp/src/OpenCvSharpExtern/include_opencv.h:28:45: fatal error: /usr/include/opencv2/tracking.hpp: No such file or directory looks like solved.

But then I encountered this error message:

In file included from /opencvsharp/src/OpenCvSharpExtern/aruco.h:4:0,
                 from /opencvsharp/src/OpenCvSharpExtern/aruco.cpp:1:
/opencvsharp/src/OpenCvSharpExtern/include_opencv.h:29:48: fatal error: /usr/include/opencv2/xfeatures2d.hpp: No such file or directory
 #include </usr/include/opencv2/xfeatures2d.hpp>
                                                ^
compilation terminated.
make[2]: *** [OpenCvSharpExtern/CMakeFiles/OpenCvSharpExtern.dir/build.make:63: OpenCvSharpExtern/CMakeFiles/OpenCvSharpExtern.dir/aruco.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:86: OpenCvSharpExtern/CMakeFiles/OpenCvSharpExtern.dir/all] Error 2
make: *** [Makefile:130: all] Error 2

So apparently the previous error on the tracking.hpp file has been solved and the make instruction failed few lines later. Since the opencv2/xfeatures2d.hpp file does not exist in my system I tried to comment out that failing line from the include_opencv.h file and I tried to compile the code again. This time the process reached 76% and then failed with this error:


Scanning dependencies of target OpenCvSharpExtern
[  3%] Building CXX object OpenCvSharpExtern/CMakeFiles/OpenCvSharpExtern.dir/aruco.cpp.o
[  7%] Building CXX object OpenCvSharpExtern/CMakeFiles/OpenCvSharpExtern.dir/bgsegm.cpp.o
[ 11%] Building CXX object OpenCvSharpExtern/CMakeFiles/OpenCvSharpExtern.dir/calib3d.cpp.o
[ 15%] Building CXX object OpenCvSharpExtern/CMakeFiles/OpenCvSharpExtern.dir/core.cpp.o
[ 19%] Building CXX object OpenCvSharpExtern/CMakeFiles/OpenCvSharpExtern.dir/cuda.cpp.o
[ 23%] Building CXX object OpenCvSharpExtern/CMakeFiles/OpenCvSharpExtern.dir/face.cpp.o
[ 26%] Building CXX object OpenCvSharpExtern/CMakeFiles/OpenCvSharpExtern.dir/features2d.cpp.o
[ 30%] Building CXX object OpenCvSharpExtern/CMakeFiles/OpenCvSharpExtern.dir/flann.cpp.o
[ 34%] Building CXX object OpenCvSharpExtern/CMakeFiles/OpenCvSharpExtern.dir/highgui.cpp.o
[ 38%] Building CXX object OpenCvSharpExtern/CMakeFiles/OpenCvSharpExtern.dir/imgcodecs.cpp.o
[ 42%] Building CXX object OpenCvSharpExtern/CMakeFiles/OpenCvSharpExtern.dir/imgproc.cpp.o
[ 46%] Building CXX object OpenCvSharpExtern/CMakeFiles/OpenCvSharpExtern.dir/ml.cpp.o
[ 50%] Building CXX object OpenCvSharpExtern/CMakeFiles/OpenCvSharpExtern.dir/objdetect.cpp.o
[ 53%] Building CXX object OpenCvSharpExtern/CMakeFiles/OpenCvSharpExtern.dir/optflow.cpp.o
[ 57%] Building CXX object OpenCvSharpExtern/CMakeFiles/OpenCvSharpExtern.dir/photo.cpp.o
[ 61%] Building CXX object OpenCvSharpExtern/CMakeFiles/OpenCvSharpExtern.dir/shape.cpp.o
[ 65%] Building CXX object OpenCvSharpExtern/CMakeFiles/OpenCvSharpExtern.dir/std_vector.cpp.o
[ 69%] Building CXX object OpenCvSharpExtern/CMakeFiles/OpenCvSharpExtern.dir/stitching.cpp.o
[ 73%] Building CXX object OpenCvSharpExtern/CMakeFiles/OpenCvSharpExtern.dir/superres.cpp.o
[ 76%] Building CXX object OpenCvSharpExtern/CMakeFiles/OpenCvSharpExtern.dir/tracking.cpp.o
In file included from /usr/include/opencv2/core/core_c.h:48:0,
                 from /usr/include/opencv2/core/utility.hpp:1168,
                 from /usr/include/opencv2/core.hpp:3216,
                 from /usr/include/opencv2/opencv.hpp:52,
                 from /opencvsharp/src/OpenCvSharpExtern/include_opencv.h:12,
                 from /opencvsharp/src/OpenCvSharpExtern/tracking.h:4,
                 from /opencvsharp/src/OpenCvSharpExtern/tracking.cpp:1:
/opencvsharp/src/OpenCvSharpExtern/tracking.h:6:15: error: ‘Tracker’ is not a member of ‘cv’
 CVAPI(cv::Ptr<cv::Tracker>*) tracking_Tracker_create(const char* trackerType)
               ^
/opencvsharp/src/OpenCvSharpExtern/tracking.h:6:15: error: ‘Tracker’ is not a member of ‘cv’
/opencvsharp/src/OpenCvSharpExtern/tracking.h:6:26: error: template argument 1 is invalid
 CVAPI(cv::Ptr<cv::Tracker>*) tracking_Tracker_create(const char* trackerType)
                          ^
In file included from /opencvsharp/src/OpenCvSharpExtern/tracking.cpp:1:0:
/opencvsharp/src/OpenCvSharpExtern/tracking.h: In function ‘int* tracking_Tracker_create(const char*)’:
/opencvsharp/src/OpenCvSharpExtern/tracking.h:9:13: error: ‘Tracker’ is not a member of ‘cv’
     cv::Ptr<cv::Tracker> p = cv::Tracker::create(type);
             ^~
/opencvsharp/src/OpenCvSharpExtern/tracking.h:9:13: error: ‘Tracker’ is not a member of ‘cv’
/opencvsharp/src/OpenCvSharpExtern/tracking.h:9:24: error: template argument 1 is invalid
     cv::Ptr<cv::Tracker> p = cv::Tracker::create(type);
                        ^
/opencvsharp/src/OpenCvSharpExtern/tracking.h:9:34: error: ‘cv::Tracker’ has not been declared
     cv::Ptr<cv::Tracker> p = cv::Tracker::create(type);
                                  ^~~~~~~
/opencvsharp/src/OpenCvSharpExtern/tracking.h:10:24: error: ‘Tracker’ is not a member of ‘cv’
     return new cv::Ptr<cv::Tracker>(p);
                        ^~
/opencvsharp/src/OpenCvSharpExtern/tracking.h:10:24: error: ‘Tracker’ is not a member of ‘cv’
/opencvsharp/src/OpenCvSharpExtern/tracking.h:10:35: error: template argument 1 is invalid
     return new cv::Ptr<cv::Tracker>(p);
                                   ^
/opencvsharp/src/OpenCvSharpExtern/tracking.h: At global scope:
/opencvsharp/src/OpenCvSharpExtern/tracking.h:13:38: warning: ‘tracking_Tracker_init’ initialized and declared ‘extern’
 CVAPI(int) tracking_Tracker_init(cv::Tracker* tracker, const cv::Mat* image, MyCvRect2D boundingBox)
                                      ^~~~~~~
/opencvsharp/src/OpenCvSharpExtern/tracking.h:13:34: error: ‘Tracker’ is not a member of ‘cv’
 CVAPI(int) tracking_Tracker_init(cv::Tracker* tracker, const cv::Mat* image, MyCvRect2D boundingBox)
                                  ^~
/opencvsharp/src/OpenCvSharpExtern/tracking.h:13:47: error: ‘tracker’ was not declared in this scope
 CVAPI(int) tracking_Tracker_init(cv::Tracker* tracker, const cv::Mat* image, MyCvRect2D boundingBox)
                                               ^~~~~~~
/opencvsharp/src/OpenCvSharpExtern/tracking.h:13:56: error: expected primary-expression before ‘const’
 CVAPI(int) tracking_Tracker_init(cv::Tracker* tracker, const cv::Mat* image, MyCvRect2D boundingBox)
                                                        ^~~~~
/opencvsharp/src/OpenCvSharpExtern/tracking.h:13:89: error: expected primary-expression before ‘boundingBox’
 CVAPI(int) tracking_Tracker_init(cv::Tracker* tracker, const cv::Mat* image, MyCvRect2D boundingBox)
                                                                                         ^~~~~~~~~~~
/opencvsharp/src/OpenCvSharpExtern/tracking.h:13:100: error: expression list treated as compound expression in initializer [-fpermissive]
 CVAPI(int) tracking_Tracker_init(cv::Tracker* tracker, const cv::Mat* image, MyCvRect2D boundingBox)
                                                                                                    ^
/opencvsharp/src/OpenCvSharpExtern/tracking.h:19:40: warning: ‘tracking_Tracker_update’ initialized and declared ‘extern’
 CVAPI(int) tracking_Tracker_update(cv::Tracker* tracker, const cv::Mat* image, MyCvRect2D* boundingBox)
                                        ^~~~~~~
/opencvsharp/src/OpenCvSharpExtern/tracking.h:19:36: error: ‘Tracker’ is not a member of ‘cv’
 CVAPI(int) tracking_Tracker_update(cv::Tracker* tracker, const cv::Mat* image, MyCvRect2D* boundingBox)
                                    ^~
/opencvsharp/src/OpenCvSharpExtern/tracking.h:19:49: error: ‘tracker’ was not declared in this scope
 CVAPI(int) tracking_Tracker_update(cv::Tracker* tracker, const cv::Mat* image, MyCvRect2D* boundingBox)
                                                 ^~~~~~~
/opencvsharp/src/OpenCvSharpExtern/tracking.h:19:58: error: expected primary-expression before ‘const’
 CVAPI(int) tracking_Tracker_update(cv::Tracker* tracker, const cv::Mat* image, MyCvRect2D* boundingBox)
                                                          ^~~~~
/opencvsharp/src/OpenCvSharpExtern/tracking.h:19:90: error: expected primary-expression before ‘*’ token
 CVAPI(int) tracking_Tracker_update(cv::Tracker* tracker, const cv::Mat* image, MyCvRect2D* boundingBox)
                                                                                          ^
/opencvsharp/src/OpenCvSharpExtern/tracking.h:19:92: error: ‘boundingBox’ was not declared in this scope
 CVAPI(int) tracking_Tracker_update(cv::Tracker* tracker, const cv::Mat* image, MyCvRect2D* boundingBox)
                                                                                            ^~~~~~~~~~~
/opencvsharp/src/OpenCvSharpExtern/tracking.h:19:103: error: expression list treated as compound expression in initializer [-fpermissive]
 CVAPI(int) tracking_Tracker_update(cv::Tracker* tracker, const cv::Mat* image, MyCvRect2D* boundingBox)
                                                                                                       ^
make[2]: *** [OpenCvSharpExtern/CMakeFiles/OpenCvSharpExtern.dir/build.make:519: OpenCvSharpExtern/CMakeFiles/OpenCvSharpExtern.dir/tracking.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:86: OpenCvSharpExtern/CMakeFiles/OpenCvSharpExtern.dir/all] Error 2
make: *** [Makefile:130: all] Error 2
johncharris commented 7 years ago

I was able to get the extern library to build by building openCV and openCV contrib. In ./src/CMakeLists.txt I had to add two lines for opencvsharp. include_directories("/usr/local/include/") set (CMAKE_CXX_STANDARD 11)

johncharris commented 7 years ago

I haven't tested this since I cleaned it up, but I just installed this on a docker image with dotnetcore 2.0 and these are the steps I went through.

Right at the very end it will say that several of the target didn't build. That's fine since it builds both the dotnetcore1.0 assembly and the netstandard 1.4 assembly.

To use this outside of Docker, sudo will be needed in a few places.

# Get the basic package installation out of the way
apt-get update

apt-get install -y build-essential cmake apt-transport-https
apt-get install -y zlib1g-dev libjpeg-dev libwebp-dev libpng-dev libtiff5-dev libjasper-dev libopenexr-dev libgdal-dev libdc1394-22-dev libavcodec-dev libavformat-dev libswscale-dev libtheora-dev libvorbis-dev libxvidcore-dev libx264-dev yasm libopencore-amrnb-dev libopencore-amrwb-dev libv4l-dev libxine2-dev libtbb-dev libeigen3-dev
apt-get install -y wget unzip curl nano git

#install DotNetCore
cd ~
curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg
mv microsoft.gpg /etc/apt/trusted.gpg.d/microsoft.gpg
sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-ubuntu-xenial-prod xenial main" > /etc/apt/sources.list.d/dotnetdev.list'
apt-get update
apt-get -y install dotnet-sdk-2.0.0

#Download OpenCv
cd ~
wget https://github.com/opencv/opencv/archive/3.2.0.zip
unzip  3.2.0.zip
rm 3.2.0.zip

wget https://github.com/opencv/opencv_contrib/archive/3.2.0.zip
unzip 3.2.0.zip
rm 3.2.0.zip
cd opencv-3.2.0/

#Build and install OpenCv
cmake -DOPENCV_EXTRA_MODULES_PATH=~/opencv_contrib-3.2.0/modules .
make -j5
make install
ldconfig

#download OpenCvSharp
cd ~
git clone https://github.com/shimat/opencvsharp.git

#install the Extern lib.
cd opencvsharp/src
sed -i.bak '5i\
include_directories("/usr/local/include/")\
set (CMAKE_CXX_STANDARD 11)\
' CMakeLists.txt
cmake .
make -j 4
make install

#install Build the c# part of OpenCvSharp
cd ~/opencvsharp/src/OpenCvSharp
dotnet build

mkdir ~/bin/
cp ~/opencvsharp/src/OpenCvSharpExtern/libOpenCvSharpExtern.so ~/bin/
cp ~/opencvsharp/src/OpenCvSharp/bin/Debug/netcoreapp1.0/OpenCvSharp.dll ~/bin/

To use an application with this the csproj needs to be set to x64 <PlatformTarget>x64</PlatformTarget> and the OpenCvSharp.dll and libOpenCvSharpExtern.so need to be copied into the directory with the output executable.

zandam-xrn commented 7 years ago

Thanks for the reply. I'll try your suggestion asap and I'll post the results here.

johncharris commented 7 years ago

I updated the script in my previous comment.

DaEkstrim commented 7 years ago

@johncharris Can your script be used for ARM architecture? I'm asking because I tried your above script and I ran into some error during make namely:

/home/master/src/opencvsharp/src/OpenCvSharpExtern/my_types.h:310:8: error: ‘struct cv::aruco::DetectorParameters’ has no member named ‘doCornerRefinement’; did you mean ‘cornerRefinementMethod’?
     pp.doCornerRefinement = p.doCornerRefinement != 0;
        ^~~~~~~~~~~~~~~~~~
DaEkstrim commented 7 years ago

I believe I know what I did... I installed opencv3.3 and opencvsharp targets 3.2. Correct me if I'm wrong.

Edit: It worked on RPI Raspbian Stretch. Thank you @johncharris
Edit: For future readers, I wrote my notes in this issue: https://github.com/shimat/opencvsharp/issues/388#issuecomment-337953321

MiniKimmy commented 5 years ago

In file included from /home/pi/src/opencvsharp/src/OpenCvSharpExtern/std_vector.h:6:0, from /home/pi/src/opencvsharp/src/OpenCvSharpExtern/std_vector.cpp:1: /home/pi/src/opencvsharp/src/OpenCvSharpExtern/include_opencv.h:24:29: fatal error: opencv2/aruco.hpp: No such file or directory

include <opencv2/aruco.hpp>

                         ^

compilation terminated. In file included from /home/pi/src/opencvsharp/src/OpenCvSharpExtern/flann.h:4:0, from /home/pi/src/opencvsharp/src/OpenCvSharpExtern/flann.cpp:1: /home/pi/src/opencvsharp/src/OpenCvSharpExtern/include_opencv.h:24:29: fatal error: opencv2/aruco.hpp: No such file or directory

include <opencv2/aruco.hpp>

                         ^

compilation terminated. In file included from /home/pi/src/opencvsharp/src/OpenCvSharpExtern/bgsegm.h:4:0, from /home/pi/src/opencvsharp/src/OpenCvSharpExtern/bgsegm.cpp:1: /home/pi/src/opencvsharp/src/OpenCvSharpExtern/include_opencv.h:24:29: fatal error: opencv2/aruco.hpp: No such file or directory

include <opencv2/aruco.hpp>

                         ^

compilation terminated. In file included from /home/pi/src/opencvsharp/src/OpenCvSharpExtern/face.h:6:0, from /home/pi/src/opencvsharp/src/OpenCvSharpExtern/face.cpp:1: /home/pi/src/opencvsharp/src/OpenCvSharpExtern/include_opencv.h:24:29: fatal error: opencv2/aruco.hpp: No such file or directory

include <opencv2/aruco.hpp>

                         ^

compilation terminated.

OpenCvSharpExtern/CMakeFiles/OpenCvSharpExtern.dir/build.make:86: recipe for target 'OpenCvSharpExtern/CMakeFiles/OpenCvSharpExtern.dir/flann.cpp.o' failed make[2]: [OpenCvSharpExtern/CMakeFiles/OpenCvSharpExtern.dir/flann.cpp.o] Error 1 make[2]: Waiting for unfinished jobs.... OpenCvSharpExtern/CMakeFiles/OpenCvSharpExtern.dir/build.make:134: recipe for target 'OpenCvSharpExtern/CMakeFiles/OpenCvSharpExtern.dir/face.cpp.o' failed make[2]: [OpenCvSharpExtern/CMakeFiles/OpenCvSharpExtern.dir/face.cpp.o] Error 1 OpenCvSharpExtern/CMakeFiles/OpenCvSharpExtern.dir/build.make:62: recipe for target 'OpenCvSharpExtern/CMakeFiles/OpenCvSharpExtern.dir/std_vector.cpp.o' failed make[2]: [OpenCvSharpExtern/CMakeFiles/OpenCvSharpExtern.dir/std_vector.cpp.o] Error 1 OpenCvSharpExtern/CMakeFiles/OpenCvSharpExtern.dir/build.make:110: recipe for target 'OpenCvSharpExtern/CMakeFiles/OpenCvSharpExtern.dir/bgsegm.cpp.o' failed make[2]: [OpenCvSharpExtern/CMakeFiles/OpenCvSharpExtern.dir/bgsegm.cpp.o] Error 1 CMakeFiles/Makefile2:85: recipe for target 'OpenCvSharpExtern/CMakeFiles/OpenCvSharpExtern.dir/all' failed make[1]: [OpenCvSharpExtern/CMakeFiles/OpenCvSharpExtern.dir/all] Error 2 Makefile:127: recipe for target 'all' failed make: *** [all] Error 2

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.