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

Undefined types errors whenever using gocv #852

Open soypat opened 3 years ago

soypat commented 3 years ago

Description

Attempting to run a program that uses gocv (even older versuions) results in errors of undefined types

Steps to Reproduce

I run go clean -modcache and go clean -cache beforehand:

  1. Download gocv as detailed in repo: go get -u -d gocv.io/x/gocv
  2. Build gocv cd /home/pato/go/pkg/mod/gocv.io/x/gocv -> make install

Errors when running make install

$ make install
... lots of build messages
/home/pato/go/pkg/mod/gocv.io/x/gocv@v0.27.0
go clean --cache
rm -rf /tmp/opencv
go run ./cmd/version/main.go
# gocv.io/x/gocv
./calib3d_string.go:3:9: undefined: CalibFlag
./calib3d_string.go:29:9: undefined: CalibCBFlag
./core_string.go:3:9: undefined: MatType
./core_string.go:57:9: undefined: CompareType
./core_string.go:75:9: undefined: CovarFlags
./core_string.go:93:9: undefined: DftFlags
./core_string.go:113:9: undefined: RotateFlag
./core_string.go:125:9: undefined: KMeansFlags
./core_string.go:137:9: undefined: NormType
./core_string.go:159:9: undefined: TermCriteriaType
./core_string.go:159:9: too many errors
make: *** [Makefile:212: verify] Error 2

Running other projects such as https://github.com/milosgajdos/go-estimate-examples/tree/master/bfdynamics which uses gocv.io/x/gocv v0.19.0 yields:

# gocv.io/x/gocv 
../../../go/pkg/mod/gocv.io/x/gocv@v0.19.0/dnn_ext.go:9:28: undefined: Mat
../../../go/pkg/mod/gocv.io/x/gocv@v0.19.0/dnn_ext.go:16:12: undefined: NewMatWithSize
../../../go/pkg/mod/gocv.io/x/gocv@v0.19.0/dnn_ext.go:42:2: undefined: Resize
../../../go/pkg/mod/gocv.io/x/gocv@v0.19.0/dnn_ext.go:42:38: undefined: InterpolationDefault
../../../go/pkg/mod/gocv.io/x/gocv@v0.19.0/dnn_ext.go:45:3: undefined: CvtColor
../../../go/pkg/mod/gocv.io/x/gocv@v0.19.0/dnn_ext.go:48:15: undefined: NewMat
../../../go/pkg/mod/gocv.io/x/gocv@v0.19.0/dnn_ext.go:51:31: undefined: MatTypeCV32F

Your Environment

hostnamectl

$ hostnamectl
   Static hostname: rootmaster
         Icon name: computer-desktop
           Chassis: desktop
        Machine ID: 81ef0e57b20d414d8f32343aa93cf97a
           Boot ID: feaf9455dbef4ecfac5d2263cebb164b
  Operating System: Ubuntu 20.04.2 LTS
            Kernel: Linux 5.8.0-53-generic
      Architecture: x86-64

$ go version
go version go1.16.3 linux/amd64
deadprogram commented 3 years ago

First of all, you HAVE to have the correct version of OpenCV installed that matches the version of GoCV you want to use. Since OpenCV's own interfaces change as they have new releases, any given version of GoCV is only intended to work with that specific version of OpenCV.

The messages you mention are always due to not having OpenCV correctly installed, or else not having the matching version.

If you git clone the repo, and then cd to that dir, the make tasks should build, as well as test and cleanup the OpenCV install. If you did not get that to work yet, nothing else will work after that point.

soypat commented 3 years ago

Thanks for the reply. I'm trying your suggestion to no avail (cloning repo+make install) due to getting same errors.

Pastebin link to result of make install: here

deadprogram commented 3 years ago

You have several errors appearing in your output:

Err:16 https://apt.llvm.org/focal llvm-toolchain-buster-11 Release
  404  Not Found [IP: 2a04:4e42:4d::561 443]
Reading package lists... Done
E: The repository 'http://apt.llvm.org/focal llvm-toolchain-buster-11 Release' does not have a Release file.

then

[opencv.zip]
  End-of-central-directory signature not found.  Either this file is not
  a zipfile, or it constitutes one disk of a multi-part archive.  In the
  latter case the central directory and zipfile comment will be found on
  the last disk(s) of this archive.
unzip:  cannot find zipfile directory in one of opencv.zip or
        opencv.zip.zip, and cannot find opencv.zip.ZIP, period.

the next failure would be expected since you did not appear to have successfully downloaded/unzipped the opencv compressed file with the source fies:

/bin/sh: 1: cd: can't cd to /tmp/opencv/opencv-4.5.2

I have installed personally with this makefile on both Ubuntu 16.04 and 18.04 but probably have not on Ubuntu 20.04. Not sure if that is at all related.