gitmyhub

gocv

Go ★ 7.5k updated 24d ago

Go package for computer vision using OpenCV 4 and beyond. Includes support for DNN, CUDA, OpenCV Contrib, and OpenVINO.

A Go package that brings OpenCV's image and video processing capabilities to Go programs, letting you do face detection, webcam capture, and computer vision without writing any C++ code.

GoOpenCVC++CUDAOpenVINODockersetup: hardcomplexity 4/5

GoCV is a Go programming package that gives Go developers access to OpenCV, one of the most widely used libraries for analyzing images and video. OpenCV is written in C++, so without a bridge like GoCV, Go programs cannot call its functions. GoCV provides that bridge, letting you write Go code that opens a webcam, reads video frames, detects faces, measures objects, and performs other image processing tasks.

The face detection example in the README is a good illustration of what the library can do. A short Go program opens a webcam feed, loads a pre-trained face detection model, and then for each incoming frame draws a rectangle around any face it finds before displaying the result in a window. This requires only a few dozen lines of Go code that read naturally, rather than the longer setup that would be needed in raw C++.

GoCV supports hardware acceleration through Nvidia GPU processing (called CUDA) and Intel's OpenVINO toolkit, which is a separate optimization layer for computer vision models from Intel. These options are handled by separate sub-packages within the repository and are covered in their own setup guides. For most basic tasks on a laptop or desktop, neither is required.

Installation requires OpenCV 4.12.0 to be installed on your system separately first. GoCV wraps that library, so OpenCV must be present before GoCV code will compile. Installation guides for Linux, macOS, Windows, and Docker are linked from the project's website. The library works on all four platforms.

One technical note the README highlights: image data objects (called Mat) must be explicitly closed when you are done with them, because they use memory that Go's automatic cleanup process does not track. The library includes a built-in profiler to help find cases where a Mat was created but never closed, which can be useful when debugging memory issues in longer-running programs.

Where it fits