hybridgroup / gocv

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

Build failed with gocv v0.38.0 #1228

Open okieraised opened 1 month ago

okieraised commented 1 month ago

Cannot build projects using gocv after upgrading to v0.38.0.

Description

When building a simple project with go using gocv v0.38.0, it returns the stack trace below:

# gocv.io/x/gocv
dnn.cpp: In function ‘Rect Net_BlobRectToImageRect(Rect, Size, double, Size, Scalar, bool, int, int, int, Scalar)’:
dnn.cpp:134:104: error: no matching function for call to ‘cv::dnn::dnn4_v20230620::Image2BlobParams::Image2BlobParams(cv::Scalar&, cv::Size&, cv::Scalar&, bool&, int&, cv::dnn::dnn4_v20230620::DataLayout&, cv::dnn::dnn4_v20230620::ImagePaddingMode&, cv::Scalar&)’
  134 |     cv::dnn::Image2BlobParams params = cv::dnn::Image2BlobParams(sf, sz, cm, swapRB, ddepth, dl, pm, bv);
      |                                                                                                        ^
In file included from /usr/local/include/opencv4/opencv2/dnn.hpp:76,
                 from /usr/local/include/opencv4/opencv2/opencv.hpp:62,
                 from dnn.h:7,
                 from dnn.cpp:1:
/usr/local/include/opencv4/opencv2/dnn/dnn.hpp:1218:17: note: candidate: ‘cv::dnn::dnn4_v20230620::Image2BlobParams::Image2BlobParams(const Scalar&, const Size&, const Scalar&, bool, int, cv::dnn::dnn4_v20230620::DataLayout, cv::dnn::dnn4_v20230620::ImagePaddingMode)’
 1218 |         CV_WRAP Image2BlobParams(const Scalar& scalefactor, const Size& size = Size(), const Scalar& mean = Scalar(),
      |                 ^~~~~~~~~~~~~~~~
/usr/local/include/opencv4/opencv2/dnn/dnn.hpp:1218:17: note:   candidate expects 7 arguments, 8 provided
/usr/local/include/opencv4/opencv2/dnn/dnn.hpp:1217:17: note: candidate: ‘cv::dnn::dnn4_v20230620::Image2BlobParams::Image2BlobParams()’
 1217 |         CV_WRAP Image2BlobParams();
      |                 ^~~~~~~~~~~~~~~~
/usr/local/include/opencv4/opencv2/dnn/dnn.hpp:1217:17: note:   candidate expects 0 arguments, 8 provided
/usr/local/include/opencv4/opencv2/dnn/dnn.hpp:1215:32: note: candidate: ‘cv::dnn::dnn4_v20230620::Image2BlobParams::Image2BlobParams(const cv::dnn::dnn4_v20230620::Image2BlobParams&)’
 1215 |     struct CV_EXPORTS_W_SIMPLE Image2BlobParams
      |                                ^~~~~~~~~~~~~~~~
/usr/local/include/opencv4/opencv2/dnn/dnn.hpp:1215:32: note:   candidate expects 1 argument, 8 provided
/usr/local/include/opencv4/opencv2/dnn/dnn.hpp:1215:32: note: candidate: ‘cv::dnn::dnn4_v20230620::Image2BlobParams::Image2BlobParams(cv::dnn::dnn4_v20230620::Image2BlobParams&&)’
/usr/local/include/opencv4/opencv2/dnn/dnn.hpp:1215:32: note:   candidate expects 1 argument, 8 provided
dnn.cpp:136:29: error: ‘struct cv::dnn::dnn4_v20230620::Image2BlobParams’ has no member named ‘blobRectToImageRect’
  136 |     cv::Rect bRect = params.blobRectToImageRect(cv::Rect(rect.x, rect.y, rect.width, rect.height), cv::Size(originalSize.width, originalSize.height));
      |                             ^~~~~~~~~~~~~~~~~~~
dnn.cpp: In function ‘Rects Net_BlobRectsToImageRects(Rects, Size, double, Size, Scalar, bool, int, int, int, Scalar)’:
dnn.cpp:160:104: error: no matching function for call to ‘cv::dnn::dnn4_v20230620::Image2BlobParams::Image2BlobParams(cv::Scalar&, cv::Size&, cv::Scalar&, bool&, int&, cv::dnn::dnn4_v20230620::DataLayout&, cv::dnn::dnn4_v20230620::ImagePaddingMode&, cv::Scalar&)’
  160 |     cv::dnn::Image2BlobParams params = cv::dnn::Image2BlobParams(sf, sz, cm, swapRB, ddepth, dl, pm, bv);
      |                                                                                                        ^
In file included from /usr/local/include/opencv4/opencv2/dnn.hpp:76,
                 from /usr/local/include/opencv4/opencv2/opencv.hpp:62,
                 from dnn.h:7,
                 from dnn.cpp:1:
/usr/local/include/opencv4/opencv2/dnn/dnn.hpp:1218:17: note: candidate: ‘cv::dnn::dnn4_v20230620::Image2BlobParams::Image2BlobParams(const Scalar&, const Size&, const Scalar&, bool, int, cv::dnn::dnn4_v20230620::DataLayout, cv::dnn::dnn4_v20230620::ImagePaddingMode)’
 1218 |         CV_WRAP Image2BlobParams(const Scalar& scalefactor, const Size& size = Size(), const Scalar& mean = Scalar(),
      |                 ^~~~~~~~~~~~~~~~
/usr/local/include/opencv4/opencv2/dnn/dnn.hpp:1218:17: note:   candidate expects 7 arguments, 8 provided
/usr/local/include/opencv4/opencv2/dnn/dnn.hpp:1217:17: note: candidate: ‘cv::dnn::dnn4_v20230620::Image2BlobParams::Image2BlobParams()’
 1217 |         CV_WRAP Image2BlobParams();
      |                 ^~~~~~~~~~~~~~~~
/usr/local/include/opencv4/opencv2/dnn/dnn.hpp:1217:17: note:   candidate expects 0 arguments, 8 provided
/usr/local/include/opencv4/opencv2/dnn/dnn.hpp:1215:32: note: candidate: ‘cv::dnn::dnn4_v20230620::Image2BlobParams::Image2BlobParams(const cv::dnn::dnn4_v20230620::Image2BlobParams&)’
 1215 |     struct CV_EXPORTS_W_SIMPLE Image2BlobParams
      |                                ^~~~~~~~~~~~~~~~
/usr/local/include/opencv4/opencv2/dnn/dnn.hpp:1215:32: note:   candidate expects 1 argument, 8 provided
/usr/local/include/opencv4/opencv2/dnn/dnn.hpp:1215:32: note: candidate: ‘cv::dnn::dnn4_v20230620::Image2BlobParams::Image2BlobParams(cv::dnn::dnn4_v20230620::Image2BlobParams&&)’
/usr/local/include/opencv4/opencv2/dnn/dnn.hpp:1215:32: note:   candidate expects 1 argument, 8 provided
dnn.cpp:163:12: error: ‘struct cv::dnn::dnn4_v20230620::Image2BlobParams’ has no member named ‘blobRectsToImageRects’
  163 |     params.blobRectsToImageRects(_cRects, detected, cv::Size(originalSize.width, originalSize.height));
      |            ^~~~~~~~~~~~~~~~~~~~~
dnn.cpp: In function ‘cv::Mat* Net_BlobFromImageWithParams(Mat, double, Size, Scalar, bool, int, int, int, Scalar)’:
dnn.cpp:192:104: error: no matching function for call to ‘cv::dnn::dnn4_v20230620::Image2BlobParams::Image2BlobParams(cv::Scalar&, cv::Size&, cv::Scalar&, bool&, int&, cv::dnn::dnn4_v20230620::DataLayout&, cv::dnn::dnn4_v20230620::ImagePaddingMode&, cv::Scalar&)’
  192 |     cv::dnn::Image2BlobParams params = cv::dnn::Image2BlobParams(sf, sz, cm, swapRB, ddepth, dl, pm, bv);
      |                                                                                                        ^
In file included from /usr/local/include/opencv4/opencv2/dnn.hpp:76,
                 from /usr/local/include/opencv4/opencv2/opencv.hpp:62,
                 from dnn.h:7,
                 from dnn.cpp:1:
/usr/local/include/opencv4/opencv2/dnn/dnn.hpp:1218:17: note: candidate: ‘cv::dnn::dnn4_v20230620::Image2BlobParams::Image2BlobParams(const Scalar&, const Size&, const Scalar&, bool, int, cv::dnn::dnn4_v20230620::DataLayout, cv::dnn::dnn4_v20230620::ImagePaddingMode)’
 1218 |         CV_WRAP Image2BlobParams(const Scalar& scalefactor, const Size& size = Size(), const Scalar& mean = Scalar(),
      |                 ^~~~~~~~~~~~~~~~
/usr/local/include/opencv4/opencv2/dnn/dnn.hpp:1218:17: note:   candidate expects 7 arguments, 8 provided
/usr/local/include/opencv4/opencv2/dnn/dnn.hpp:1217:17: note: candidate: ‘cv::dnn::dnn4_v20230620::Image2BlobParams::Image2BlobParams()’
 1217 |         CV_WRAP Image2BlobParams();
      |                 ^~~~~~~~~~~~~~~~
/usr/local/include/opencv4/opencv2/dnn/dnn.hpp:1217:17: note:   candidate expects 0 arguments, 8 provided
/usr/local/include/opencv4/opencv2/dnn/dnn.hpp:1215:32: note: candidate: ‘cv::dnn::dnn4_v20230620::Image2BlobParams::Image2BlobParams(const cv::dnn::dnn4_v20230620::Image2BlobParams&)’
 1215 |     struct CV_EXPORTS_W_SIMPLE Image2BlobParams
      |                                ^~~~~~~~~~~~~~~~
/usr/local/include/opencv4/opencv2/dnn/dnn.hpp:1215:32: note:   candidate expects 1 argument, 8 provided
/usr/local/include/opencv4/opencv2/dnn/dnn.hpp:1215:32: note: candidate: ‘cv::dnn::dnn4_v20230620::Image2BlobParams::Image2BlobParams(cv::dnn::dnn4_v20230620::Image2BlobParams&&)’
/usr/local/include/opencv4/opencv2/dnn/dnn.hpp:1215:32: note:   candidate expects 1 argument, 8 provided
dnn.cpp: In function ‘void Net_BlobFromImagesWithParams(Mats, Mat, double, Size, Scalar, bool, int, int, int, Scalar)’:
dnn.cpp:226:104: error: no matching function for call to ‘cv::dnn::dnn4_v20230620::Image2BlobParams::Image2BlobParams(cv::Scalar&, cv::Size&, cv::Scalar&, bool&, int&, cv::dnn::dnn4_v20230620::DataLayout&, cv::dnn::dnn4_v20230620::ImagePaddingMode&, cv::Scalar&)’
  226 |     cv::dnn::Image2BlobParams params = cv::dnn::Image2BlobParams(sf, sz, cm, swapRB, ddepth, dl, pm, bv);
      |                                                                                                        ^
In file included from /usr/local/include/opencv4/opencv2/dnn.hpp:76,
                 from /usr/local/include/opencv4/opencv2/opencv.hpp:62,
                 from dnn.h:7,
                 from dnn.cpp:1:
/usr/local/include/opencv4/opencv2/dnn/dnn.hpp:1218:17: note: candidate: ‘cv::dnn::dnn4_v20230620::Image2BlobParams::Image2BlobParams(const Scalar&, const Size&, const Scalar&, bool, int, cv::dnn::dnn4_v20230620::DataLayout, cv::dnn::dnn4_v20230620::ImagePaddingMode)’
 1218 |         CV_WRAP Image2BlobParams(const Scalar& scalefactor, const Size& size = Size(), const Scalar& mean = Scalar(),
      |                 ^~~~~~~~~~~~~~~~
/usr/local/include/opencv4/opencv2/dnn/dnn.hpp:1218:17: note:   candidate expects 7 arguments, 8 provided
/usr/local/include/opencv4/opencv2/dnn/dnn.hpp:1217:17: note: candidate: ‘cv::dnn::dnn4_v20230620::Image2BlobParams::Image2BlobParams()’
 1217 |         CV_WRAP Image2BlobParams();
      |                 ^~~~~~~~~~~~~~~~
/usr/local/include/opencv4/opencv2/dnn/dnn.hpp:1217:17: note:   candidate expects 0 arguments, 8 provided
/usr/local/include/opencv4/opencv2/dnn/dnn.hpp:1215:32: note: candidate: ‘cv::dnn::dnn4_v20230620::Image2BlobParams::Image2BlobParams(const cv::dnn::dnn4_v20230620::Image2BlobParams&)’
 1215 |     struct CV_EXPORTS_W_SIMPLE Image2BlobParams
      |                                ^~~~~~~~~~~~~~~~
/usr/local/include/opencv4/opencv2/dnn/dnn.hpp:1215:32: note:   candidate expects 1 argument, 8 provided
/usr/local/include/opencv4/opencv2/dnn/dnn.hpp:1215:32: note: candidate: ‘cv::dnn::dnn4_v20230620::Image2BlobParams::Image2BlobParams(cv::dnn::dnn4_v20230620::Image2BlobParams&&)’
/usr/local/include/opencv4/opencv2/dnn/dnn.hpp:1215:32: note:   candidate expects 1 argument, 8 provided

Steps to Reproduce

  1. Open new project and create a main.go file:
    
    package main

import ( "fmt" "gocv.io/x/gocv" "io" "os" )

func main() { f, err := os.Open("/path/to/an/image") if err != nil { fmt.Println(err) return } defer f.Close()

content, err := io.ReadAll(f)
if err != nil {
    fmt.Println(err)
    return
}

dstMat := gocv.NewMat()
srcMat, err := gocv.IMDecode(content, gocv.IMReadColor)
if err != nil {
    fmt.Println(err)
    return
}

gocv.CvtColor(srcMat, &dstMat, gocv.ColorBGRToRGB)
return

}

2. Build it with:
```shell
go build .

It failed.

Your Environment

deadprogram commented 1 month ago

That sounds like an incompatible version of OpenCV being installed by python, or installed missing required module.

Perhaps you can check pkg-config command output. In any case, the only tested installation for Linux is installing OpenCV from source.