GoCV Documentation

repository·release·Indexed 27 days ago

https://github.com/hybridgroup/gocv

GoCV 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.

Tokens
37.2K
Snippets
65
Records
308
Agent score
92%

What's inside GoCV

  1. Explore GoCV command line utilities

    release
    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.
  2. Check GoCV module implementation status

    release

    The 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)
  3. Status of OpenCV Contrib modules in GoCV

    release

    GoCV includes support for various OpenCV contrib modules. 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.

  4. Status of CUDA modules in GoCV

    release

    The 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

    • core
    • cudabgsegm (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.

  5. Use GoCV utilities for Object Detection and Tracking

    release

    Common computer vision algorithms are implemented in these utilities:

    • Faceblur: Detects faces using CascadeClassifier and applies a Gaussian blur.
    • Facedetect: Detects faces using CascadeClassifier and 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 TrackerMOSSE algorithm from OpenCV Contrib to track a user-selected region of interest.
  6. Compile OpenCV with CUDA support

    release

    GoCV provides a Makefile target to simplify compiling OpenCV with CUDA support.

    To compile with shared libraries:

    make install_cuda

    To compile with static OpenCV libraries:

    make install_cuda BUILD_SHARED_LIBS=OFF

    After compilation, verify the installation by running the CUDA test command:

    cd $GOPATH/src/gocv.io/x/gocv
    go run ./cmd/cuda/main.go

    Successful verification will output the GoCV version and GPU device information (e.g., Device 0: "GeForce MX150" ...).

  7. Enable non-free OpenCV modules during build

    release

    To 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=ON flag. If you are using the provided build scripts, you can run the following command:

    make build_nonfree
  8. Use GoCV utilities for Video Capture and Display

    release

    Several 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.
  9. Build or run GoCV code with OpenVINO support

    release

    When using go run, go build, or go test with OpenVINO, you must include the -tags customenv flag. 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 version containing -openvino.

  10. Install the Intel OpenVINO toolkit

    release
    To 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 the install.sh program located within the extracted directory.
  11. Use the Intel OpenVINO Inference Engine with GoCV

    release

    GoCV provides support for the Intel OpenVINO Inference Engine via the gocv.io/x/gocv/openvino/ie package. 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.