gocv icon indicating copy to clipboard operation
gocv copied to clipboard

Example code won't compile on Ubuntu 20.04

Open paskozdilar opened this issue 2 years ago • 2 comments

I've tried compiling the example code from README on Ubuntu 20.04 and it failed.

Description

I have installed libopencv-dev (version 4), created a test Go module, put the example code ("Hello, video") in a main.go file, ran go mod tidy then go build main.go. The compilation failed.

The example code:

package main

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

func main() {
	webcam, _ := gocv.OpenVideoCapture(0)
	window := gocv.NewWindow("Hello")
	img := gocv.NewMat()

	for {
		webcam.Read(&img)
		window.IMShow(img)
		window.WaitKey(1)
	}
}

Output of go build main.go:

# gocv.io/x/gocv
calib3d.cpp: In function ‘bool FindChessboardCornersSBWithMeta(Mat, Size, Mat, int, Mat)’:
calib3d.cpp:64:74: error: too many arguments to function ‘bool cv::findChessboardCornersSB(cv::InputArray, cv::Size, cv::OutputArray, int)’
   64 |     return cv::findChessboardCornersSB(*image, sz, *corners, flags, *meta);
      |                                                                          ^
In file included from /usr/include/opencv4/opencv2/opencv.hpp:56,
                 from calib3d.h:5,
                 from calib3d.cpp:1:
/usr/include/opencv4/opencv2/calib3d.hpp:1260:19: note: declared here
 1260 | CV_EXPORTS_W bool findChessboardCornersSB(InputArray image,Size patternSize, OutputArray corners,int flags=0);
      |                   ^~~~~~~~~~~~~~~~~~~~~~~

Steps to Reproduce

  1. Run an Ubuntu 20.04 system
  2. Install libopencv-dev with sudo apt install libopencv-dev
  3. Copy example code from README ("Hello, video") in a main.go file
  4. Run go mod init test
  5. Run go mod tidy
  6. Run go build main.go

Your Environment

  • Operating System and version: Ubuntu 20.04 LTS
  • OpenCV version used: 4.2.0+dfsg-5
  • How did you install OpenCV? apt
  • GoCV version used: v0.31.0
  • Go version: go1.18.2 linux/amd64
  • Did you run the env.sh or env.cmd script before trying to go run or go build? No

paskozdilar avatar Jun 23 '22 12:06 paskozdilar

Gocv version 0.31.0 relays on OpenCV version 4.6.0 Please, use make to compile opencv. Just clone gocv repo, and run make on root dir of cloned repository. Read install instructions on Gocv repository if you need full install tutorial.

golubaca avatar Jun 27 '22 21:06 golubaca

Ah, I see. It's right there in the README. I apologize.

Just out of curiosity, why does Gocv depend on OpenCV 4.6.0? Could it, theoretically, be made compatible with any 4.X.Y version?

If so, I'd be glad to try my luck doing that sometimes.

paskozdilar avatar Jul 26 '22 12:07 paskozdilar