GoCV Documentation
repository·release·Indexed 27 days ago
https://github.com/hybridgroup/gocvGoCV is a Go wrapper for OpenCV providing access to computer vision modules, including NVIDIA CUDA acceleration for standard modules and the Deep Neural Network (DNN) module. It includes support for Intel OpenVINO Inference Engine, OpenCV Contrib algorithms, and various command-line utilities for tasks such as object detection, video capture, image processing, and deep learning integration using frameworks like Caffe, Tensorflow, and YOLOv8.
What's inside GoCV
- GoCV provides a variety of command-line utilities that serve as both functional tools and practical examples of how to use the GoCV package. These utilities cover common computer vision tasks such as video capture, object detection, image processing, and deep learning integration.
Check GoCV module implementation status
releaseThe GoCV repository maintains a roadmap of OpenCV modules and their implementation status in Go. You can use this to determine if a specific OpenCV function or module is currently supported.
Implemented Modules:
imgcodecs(Image file reading/writing)videoio(Video I/O)highgui(High-level GUI)dnn(Deep Neural Network)features2d(Feature Detection/Description, Descriptor Matchers, Drawing)objdetect(Face Detection)core(Basic structures, Operations on arrays, XML/YAML Persistence)imgproc(ColorMaps, Histograms)video(Motion Analysis)
Modules in Progress (Work Started):
core(Clustering, Optimization Algorithms)imgproc(Filtering, Geometric/Miscellaneous Transformations, Drawing, Shape Descriptors, Feature Detection)video(Object Tracking)calib3d(Camera Calibration, Fisheye)features2d(Object Categorization)objdetect(ArUco Marker Detection)photo(Computational Photography)stitching(Image stitching)
Not Yet Started:
ml(Machine Learning)flann(Clustering and Search)
Status of OpenCV Contrib modules in GoCV
releaseGoCV includes support for various OpenCV
contribmodules. Their implementation status varies:Implemented Contrib Modules
freetype(Drawing UTF-8 strings)img_hash(Image hashing algorithms)mcc(Macbeth Chart module)wechat_qrcode(WeChat QR code detector)xobjdetect(Extended object detection)xphoto(Additional photo processing algorithms)
Contrib Modules in Progress
bgsegm(Background-Foreground Segmentation)face(Face Recognition)tracking(Tracking API)xfeatures2d(Extra 2D Features Framework)ximgproc(Extended Image Processing)
Other Contrib Modules
Many other modules (e.g.,
alphamat,barcode,dnn_superres,sfm,text) are listed in the roadmap but are not yet implemented in GoCV.Status of CUDA modules in GoCV
releaseThe GoCV project is progressively implementing OpenCV's CUDA modules. When choosing modules for your project, be aware of which ones are fully implemented, in progress, or not yet started.
Fully Implemented CUDA Modules
corecudabgsegm(Background Segmentation)cudaobjdetect(Object Detection)cudawarping(Image Warping)
CUDA Modules in Progress
cudaarithm(Operations on Matrices)cudacodec(Video Encoding/Decoding)cudafeatures2d(Feature Detection and Description)cudafilters(Image Filtering)cudaimgproc(Image Processing)cudaoptflow(Optical Flow)cudastereo(Stereo Correspondence)
Note: Check the specific function implementation status in the roadmap if you require a particular mathematical or processing operation.
Use GoCV utilities for Object Detection and Tracking
releaseCommon computer vision algorithms are implemented in these utilities:
- Faceblur: Detects faces using
CascadeClassifierand applies a Gaussian blur. - Facedetect: Detects faces using
CascadeClassifierand draws rectangles around them. - Facedetect from URL: Detects faces in an image downloaded from a URL.
- Counter: Counts objects crossing a user-defined vertical or horizontal line in a video file.
- Hand Gestures: Counts fingers by analyzing convexity defects.
- Motion Detection: Processes a video feed to detect motion.
- Tracking: Uses the
TrackerMOSSEalgorithm from OpenCV Contrib to track a user-selected region of interest.
- Faceblur: Detects faces using
Compile OpenCV with CUDA support
releaseGoCV provides a Makefile target to simplify compiling OpenCV with CUDA support.
To compile with shared libraries:
make install_cudaTo compile with static OpenCV libraries:
make install_cuda BUILD_SHARED_LIBS=OFFAfter compilation, verify the installation by running the CUDA test command:
cd $GOPATH/src/gocv.io/x/gocv go run ./cmd/cuda/main.goSuccessful verification will output the GoCV version and GPU device information (e.g.,
Device 0: "GeForce MX150" ...).Enable non-free OpenCV modules during build
releaseTo use patented or non-free algorithms (like SIFT) that are part of the OpenCV Contrib modules, you must build OpenCV with the
OPENCV_ENABLE_NONFREE=ONflag. If you are using the provided build scripts, you can run the following command:make build_nonfreeUse GoCV utilities for Video Capture and Display
releaseSeveral utilities demonstrate how to interact with webcams and video files:
- ASCIIcam: Captures video from a webcam and displays it in the terminal using ASCII characters.
- Capture test: Verifies that video capture from a connected webcam is working correctly.
- Capture window: Captures video from a webcam and displays it in a standard GUI window.
- MJPEG Streamer: Opens a video capture device and streams the feed via MJPEG, viewable in any web browser.
- Save Image: Captures a single frame from a webcam and saves it to a file.
- Save Video: Captures 100 frames from a camera and saves them to a video file.
- Show Image: Opens an image file from disk and displays it in a window.
Build or run GoCV code with OpenVINO support
releaseWhen using
go run,go build, orgo testwith OpenVINO, you must include the-tags customenvflag. This ensures the CGo compiler uses the correct environment settings provided by the OpenVINO setup scripts instead of the default settings.You can verify the installation by running the version command example. A successful setup will show
opencv lib versioncontaining-openvino.Install the Intel OpenVINO toolkit
releaseTo use Intel OpenVINO with GoCV, download the Intel OpenVINO toolkit (currently 2022.1 LTS) from the official Intel website. After downloading the compressed file, unzip it and execute theinstall.shprogram located within the extracted directory.Install CUDA and cuDNN
releaseTo use GoCV with CUDA, you must install the NVIDIA CUDA toolkit and cuDNN libraries on your host system:
- CUDA Toolkit: Download from NVIDIA CUDA Downloads.
- cuDNN: Download the appropriate runtime and developer libraries from the cuDNN Archive (e.g., 'cuDNN Runtime Library' and 'cuDNN Developer Library' for your specific OS version).
Use the Intel OpenVINO Inference Engine with GoCV
releaseGoCV provides support for the Intel OpenVINO Inference Engine via the
gocv.io/x/gocv/openvino/iepackage. This allows for executing convolutional neural networks using OpenVINO libraries.Requirements
To use OpenVINO with GoCV, you must have Intel OpenVINO version 2019 R3 or higher installed.