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.57k stars 862 forks source link

Missing Aruco with 4.10.0 and gocv 0.37 #1187

Open arkjxu opened 1 month ago

arkjxu commented 1 month ago

Would appreciate some help if anyone knows whats going on, thank ya'll very much!

Simple script:

package main

import (
    "fmt"

    "gocv.io/x/gocv"
)

func main() {
    frame := gocv.IMRead("frame.png", gocv.IMReadGrayScale)
    fmt.Println(frame.Cols())
}

Running the following command:

go build -ldflags="-extldflags=-static" -o test main.go

# gocv.io/x/gocv
In file included from aruco.cpp:1:
aruco.h:12:13: error: 'aruco' in namespace 'cv' does not name a type
   12 | typedef cv::aruco::Dictionary* ArucoDictionary;

Now If I provide -tags customEnv, it would generate the following error:

go build -tags customenv -ldflags="-extldflags=-static" -o test main.go

aruco.h:5:10: fatal error: opencv2/opencv.hpp: No such file or directory
5 | #include <opencv2/opencv.hpp>
|          ^~~~~~~~~~~~~~~~~~~~

Setting CGO_CPPFLAGS="-I/usr/local/include/opencv4" would trigger the first error again regarding aruco errors.

FYI

I also ran the same code using the prebuilt docker image for gocv/opencv:4.9.0 and the latest gocv/opencv:4.10.0, both static and non-static versions of the image. None of them run.

Also tried to downgrade gocv to 0.36 and opencv 4.9.0, no luck, same issue.

Your Environment

Statically build opencv 4.10.0

RUN cmake -D CMAKE_BUILD_TYPE=Release \
        -D CMAKE_INSTALL_PREFIX=/usr/local \
        -D BUILD_SHARED_LIBS=OFF \
        -D OPENCV_GENERATE_PKGCONFIG=YES \
        -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules \
        -D BUILD_LIST=core,imgproc,imgcodecs \
        -D BUILD_EXAMPLES=OFF \
        -D BUILD_TESTS=OFF \
        -D BUILD_DOCS=OFF \
        -D BUILD_PERF_TESTS=OFF \
        -D BUILD_opencv_ts=OFF \
        -D WITH_CUDA=OFF \
        -D WITH_CUBLAS=OFF \
        -D WITH_NVCUVID=OFF \
        -D WITH_OPENCL=OFF \
        -D WITH_OPENCL_SVM=OFF \
        -D WITH_OPENCLAMDFFT=OFF \
        -D WITH_OPENCLAMDBLAS=OFF \
        -D WITH_VA=OFF \
        -D WITH_VA_INTEL=OFF \
        -D WITH_OPENGL=OFF \
        -D WITH_PNG=ON \
        -D WITH_ZLIB=ON \
        .. && \
    make -j $(nproc --all --ignore 1) && \
    make install && \
    ldconfig

ENV PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH
ENV CGO_CFLAGS="-I/usr/local/include/opencv4"
ENV CGO_LDFLAGS="-L/usr/local/lib -lopencv_core -lopencv_imgproc -lopencv_imgcodecs"
ENV CGO_ENABLED="1"
arkjxu commented 1 month ago

4.8.0 and 4.8.1 works for docker. looks like anything above 4.9.0 breaks. especially the static images.

kevinjwx commented 1 month ago

Please note that I am disabling everything except for the most basic imgproc and core and imgcodec. but looks like it's still trying to include aruco, i even tried to add the build flag for aruco.go and aruco_dictionary.go, no luck, maybe I miss something. Unless I have to include the aruco/dnn features?