Fork me on GitHub

GoCV:使用Go和OpenCV4.0.1进行计算机视觉编程

To use GoCV, you must install OpenCV 4.0.1 on your system.

Linux环境安装

Mac 环境安装

示例代码:

This example opens a video capture device using device “0”, reads frames, and shows the video in a GUI window:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
package main
import (
"gocv.io/x/gocv"
)
func main() {
webcam, _ := gocv.VideoCaptureDevice(0)
window := gocv.NewWindow("Hello")
img := gocv.NewMat()
for {
webcam.Read(&img)
window.IMShow(img)
if (window.WaitKey(1) & 0xff == int('q') {
break
}
}
}

编译程序,并执行

1
2
$go build -o test_cv gocv_example.go
$./test_cv

如果执行过程出现如下错误:

1
./test_cv: error while loading shared libraries: libopencv_calib3d.so.4.0: cannot open shared object file: No such file or directory

解决办法:

1
$export LD_LIBRARY_PATH=/home/chengwei/work/github/opencv-4.0.1/release/lib:$LD_LIBRARY_PATH

执行效果:

您的鼓励是我持之以恒的动力