Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build failed with gocv v0.38.0 #1228

Open
okieraised opened this issue Sep 20, 2024 · 3 comments
Open

Build failed with gocv v0.38.0 #1228

okieraised opened this issue Sep 20, 2024 · 3 comments

Comments

@okieraised
Copy link

okieraised commented Sep 20, 2024

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
}
  1. Build it with:
go build .

It failed.

Your Environment

  • Operating System and version: Ubuntu 20.04.6 LTS
  • OpenCV version used: 4.10.0
  • How did you install OpenCV? pip3 install --upgrade opencv-python
  • GoCV version used: v0.38.0
  • Go version: 1.23.1
  • Did you run the env.sh or env.cmd script before trying to go run or go build? No
@deadprogram
Copy link
Member

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.

@louisburton
Copy link

louisburton commented Dec 1, 2024

Hitting this same issue using Go 1.23.3 with GoCV v0.39.0, and OpenCV installed on Alpine 3.19 (aarch64) via the APK package - opencv-dev.
It installs OpenCV 4.8.1-r0 which I thought was within the supported OpenCV versions?
Building OpenCV from source doesn't seem trivial, are the package provided versions not supported?

could not import gocv.io/x/gocv (-: # 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);
apk list -i | grep opencv
libopencv_aruco-4.8.1-r0 aarch64 {opencv} (BSD-3-Clause) [installed]
libopencv_calib3d-4.8.1-r0 aarch64 {opencv} (BSD-3-Clause) [installed]
libopencv_core-4.8.1-r0 aarch64 {opencv} (BSD-3-Clause) [installed]
libopencv_dnn-4.8.1-r0 aarch64 {opencv} (BSD-3-Clause) [installed]
libopencv_face-4.8.1-r0 aarch64 {opencv} (BSD-3-Clause) [installed]
libopencv_features2d-4.8.1-r0 aarch64 {opencv} (BSD-3-Clause) [installed]
libopencv_flann-4.8.1-r0 aarch64 {opencv} (BSD-3-Clause) [installed]
libopencv_highgui-4.8.1-r0 aarch64 {opencv} (BSD-3-Clause) [installed]
libopencv_imgcodecs-4.8.1-r0 aarch64 {opencv} (BSD-3-Clause) [installed]
libopencv_imgproc-4.8.1-r0 aarch64 {opencv} (BSD-3-Clause) [installed]
libopencv_ml-4.8.1-r0 aarch64 {opencv} (BSD-3-Clause) [installed]
libopencv_objdetect-4.8.1-r0 aarch64 {opencv} (BSD-3-Clause) [installed]
libopencv_optflow-4.8.1-r0 aarch64 {opencv} (BSD-3-Clause) [installed]
libopencv_photo-4.8.1-r0 aarch64 {opencv} (BSD-3-Clause) [installed]
libopencv_plot-4.8.1-r0 aarch64 {opencv} (BSD-3-Clause) [installed]
libopencv_shape-4.8.1-r0 aarch64 {opencv} (BSD-3-Clause) [installed]
libopencv_stitching-4.8.1-r0 aarch64 {opencv} (BSD-3-Clause) [installed]
libopencv_superres-4.8.1-r0 aarch64 {opencv} (BSD-3-Clause) [installed]
libopencv_tracking-4.8.1-r0 aarch64 {opencv} (BSD-3-Clause) [installed]
libopencv_video-4.8.1-r0 aarch64 {opencv} (BSD-3-Clause) [installed]
libopencv_videoio-4.8.1-r0 aarch64 {opencv} (BSD-3-Clause) [installed]
libopencv_videostab-4.8.1-r0 aarch64 {opencv} (BSD-3-Clause) [installed]
libopencv_ximgproc-4.8.1-r0 aarch64 {opencv} (BSD-3-Clause) [installed]
opencv-4.8.1-r0 aarch64 {opencv} (BSD-3-Clause)
opencv-dbg-4.8.1-r0 aarch64 {opencv} (BSD-3-Clause)
opencv-dev-4.8.1-r0 aarch64 {opencv} (BSD-3-Clause) [installed]
opencv-doc-4.8.1-r0 aarch64 {opencv} (BSD-3-Clause)
py3-opencv-4.8.1-r0 aarch64 {opencv} (BSD-3-Clause)
py3-opencv-pyc-4.8.1-r0 aarch64 {opencv} (BSD-3-Clause)

Is there some missing required package to be installed?

@deadprogram
Copy link
Member

You would need to use https://github.com/hybridgroup/gocv/releases/tag/opencv-4.8.1 tag of GoCV with that version of OpenCV.

In general, to use the latest GoCV release you need to use the latest OpenCV release. Otherwise, use an older release that is in sync with the desired OpenCV version.

Hope that helps!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants