hybridgroup / gocv

Go package for computer vision using OpenCV 4 and beyond. Includes support for DNN, CUDA, and OpenCV Contrib.
https://gocv.io
Other
6.54k stars 862 forks source link

Can I use go CV with a self-compiled OpenCV? #975

Open bryanmcgrane opened 2 years ago

bryanmcgrane commented 2 years ago

Hello! I would like to use Go CV with my minimal version of open CV.

Description

I don't require all of extra features in OpenCV, like the DNN or GUI libraries. They tend to bloat my docker image. So I've compiled OpenCV in my Docker image with the following flags

RUN curl -Lo opencv.zip https://github.com/opencv/opencv/archive/${OPENCV_VERSION}.zip && \
            unzip -q opencv.zip && \
            curl -Lo opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/${OPENCV_VERSION}.zip && \
            unzip -q opencv_contrib.zip && \
            rm opencv.zip opencv_contrib.zip && \
            cd opencv-${OPENCV_VERSION} && \
            mkdir build && cd build && \
            cmake -D CMAKE_BUILD_TYPE=RELEASE \
                  -D WITH_IPP=OFF \
                  -D WITH_OPENGL=OFF \
                  -D WITH_QT=OFF \
                  -D CMAKE_INSTALL_PREFIX=/usr/local \
                  -D OPENCV_ENABLE_NONFREE=ON \
                  -D WITH_JASPER=OFF \
                  -D WITH_TBB=ON \
                  -D WITH_OPENVINO=NO \
                  -D BUILD_DOCS=OFF \
                  -D BUILD_EXAMPLES=OFF \
                  -D BUILD_TESTS=OFF \
                  -D BUILD_PERF_TESTS=OFF \
                  -D BUILD_opencv_java=NO \
                  -D BUILD_opencv_gapi=NO \
                  -D BUILD_opencv_python=NO \
                  -D BUILD_opencv_python2=NO \
                  -D BUILD_opencv_python3=NO \
                  -D BUILD_opencv_superres=OFF \
                  -D BUILD_opencv_stitching=OFF \
                  -D BUILD_opencv_highgui=OFF \
                  -D BUILD_opencv_optflow=OFF \
                  -D BUILD_opencv_dnn=ON \
                  -D WITH_1394=OFF \
                  -D WITH_GTK=OFF \
                  -D WITH_PROTOBUF=OFF \
                  -D OPENCV_DNN_OPENCL=OFF \
                  -D BUILD_PROTOBUF=OFF \
                  -D WITH_ANDROID_MEDIANDK=OFF \
                  -D OPENCV_GENERATE_PKGCONFIG=ON .. && \
            make -j $(nproc --all) && \
            make preinstall && make install && ldconfig && \
            cd / && rm -rf opencv*

The issue I'm running into when I try to compile my go project with GoCV is that I am missing header files like:

#23 22.02 # gocv.io/x/gocv
#23 22.02 In file included from dnn.cpp:1:
#23 22.02 dnn.h:8:10: fatal error: opencv2/dnn.hpp: No such file or directory
#23 22.02     8 | #include <opencv2/dnn.hpp>
#23 22.02       |          ^~~~~~~~~~~~~~~~~
#23 22.02 compilation terminated.

Is there a way to use GoCV without all the extra stuff that I don't need? I also saw that there is support for custom environments by using -tags customenv in my build script, however this does not resolve my problem.

bryanmcgrane commented 2 years ago

Requesting an update on this ticket!