gocv
gocv copied to clipboard
Example code won't compile on Ubuntu 20.04
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
- Run an Ubuntu 20.04 system
- Install
libopencv-dev
withsudo apt install libopencv-dev
- Copy example code from README ("Hello, video") in a
main.go
file - Run
go mod init test
- Run
go mod tidy
- 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
orenv.cmd
script before trying togo run
orgo build
? No
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.
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.