### Hello: Basic computer vision "hello world" (Go) Source: https://github.com/katefox1982/gocv/blob/release/cmd/README.md The "hello world" of computer vision using GoCV. This minimal example demonstrates the basic setup for image processing. ```Go // Example for Hello World // Source: https://github.com/hybridgroup/gocv/blob/release/cmd/hello/main.go ``` -------------------------------- ### Verify GoCV Installation Source: https://github.com/katefox1982/gocv/blob/release/README.md Verifies the GoCV installation by building and running the version example program. This checks if GoCV and OpenCV were installed correctly and reports their versions. ```shell cd $HOME/folder/with/your/src/gocv go run ./cmd/version/main.go ``` -------------------------------- ### Show Image: Display an image file in a window (Go) Source: https://github.com/katefox1982/gocv/blob/release/cmd/README.md Opens an image file from disk and displays it in a window. This is a fundamental example for image loading and visualization. ```Go // Example for Show Image // Source: https://github.com/hybridgroup/gocv/blob/release/cmd/showimage/main.go ``` -------------------------------- ### Install GoCV Source: https://github.com/katefox1982/gocv/blob/release/README.md Installs the compiled GoCV library. This command typically requires superuser privileges. ```shell make sudo_install ``` -------------------------------- ### Verify GoCV Installation Source: https://github.com/katefox1982/gocv/blob/release/README.md Runs a Go program to verify the GoCV installation and display the installed versions of GoCV and OpenCV. ```shell cd $HOME/src/gocv.io/x/gocv go run ./cmd/version/main.go ``` -------------------------------- ### GoCV Tracking Example (TrackerMOSSE) Source: https://github.com/katefox1982/gocv/blob/release/cmd/README.md Demonstrates using the TrackerMOSSE algorithm from OpenCV Contrib to track a user-selected region of interest via a connected camera. ```go package main import ( "fmt" "image" "os" "gocv.io/gocv/v2" "gocv.io/gocv/v2/contrib/tracking" ) func main() { imgFile := "image.jpg" webcam, err := gocv.VideoCaptureDevice(0) if err != nil { fmt.Printf("Error opening video capture device: %v\n", 0) return } defer webcam.Close() img := gocv.NewMat() defer img.Close() // Initialize the tracker tracker, err := tracking.NewTracker("MOSSE") if err != nil { fmt.Printf("Error creating tracker: %v\n", err) return } defer tracker.Close() fmt.Printf("Start reading video stream.\n") for { if ok := webcam.Read(&img); !ok || img.Empty() { fmt.Printf("Cannot read snapshot for device %v\n", 0) break } // Select ROI if not already initialized if !tracker.IsInitialized() { // For demonstration, let's assume a fixed ROI or prompt user // In a real app, you'd use mouse events to select the ROI // Example: roi := image.Rect(100, 100, 300, 300) // tracker.Init(img, roi) fmt.Println("Tracker not initialized. Please select an ROI.") // Placeholder: In a real app, you'd wait for user input or a specific key press continue } // Update the tracker bbox := tracker.Update(img) // Draw the bounding box gocv.Rectangle(&img, bbox, gocv.NewScalar(0, 255, 0, 0), 2) gocv.IMShow("Tracking", img) if gocv.WaitKey(1) == 'q' { break } } } ``` -------------------------------- ### Windows OpenCV Installation Source: https://github.com/katefox1982/gocv/blob/release/README.md Steps to install OpenCV 4.11.0 on a 64-bit Windows 10 system. This involves downloading and installing MinGW-W64 and CMake, running a batch script to build OpenCV, and updating the system's PATH environment variable. ```batch chdir %GOPATH%\src\gocv.io\x\gocv win_build_opencv.cmd ``` ```powershell # Add MinGW-W64 bin to PATH $mingwPath = "C:\\Program Files\\mingw-w64\\x86_64-8.1.0-posix-seh-rt_v6-rev0\\mingw64\\bin" [System.Environment]::SetEnvironmentVariable("PATH", $env:PATH + ";" + $mingwPath, [System.EnvironmentVariableTarget]::Machine) # Add OpenCV bin to PATH $opencvPath = "C:\\opencv\\build\\install\\x64\\mingw\\bin" [System.Environment]::SetEnvironmentVariable("PATH", $env:PATH + ";" + $opencvPath, [System.EnvironmentVariableTarget]::Machine) # Verify installation chdir %GOPATH%\src\gocv.io\x\gocv go run cmd\version\main.go ``` -------------------------------- ### Install GoCV Dependencies Source: https://github.com/katefox1982/gocv/blob/release/README.md Downloads and installs necessary system dependencies for GoCV. This command should be run from the GoCV repository directory. ```shell cd $HOME/folder/with/your/src/gocv make deps ``` -------------------------------- ### GoCV XPhoto Module Examples (White Balance, Inpainting) Source: https://github.com/katefox1982/gocv/blob/release/cmd/README.md Demonstrates the XPhoto module, including using GrayworldWB for white balance and Inpaint functions for image restoration, saving results to disk. ```go package main import ( "fmt" "os" "gocv.io/gocv/v2" "gocv.io/gocv/v2/contrib/xphoto" ) func main() { if len(os.Args) < 2 { fmt.Println("How to run: \n\t./xphoto [image] [output_path]\n") return } imgFile := os.Args[1] outputPath := os.Args[2] img := gocv.IMRead(imgFile, gocv.IMReadColor) if img.Empty() { fmt.Printf("Error reading image: %s\n", imgFile) return } defer img.Close() // White Balance Example wb := xphoto.NewGrayWorldWB() defer wb.Close() balancedImg := gocv.NewMat() defer balancedImg.Close() wb.BalanceWhite(img, &balancedImg) err := gocv.imwrite(outputPath+"/balanced.jpg", balancedImg) if err != nil { fmt.Printf("Error saving balanced image: %v\n", err) } // Inpainting Example // Create a mask for inpainting (e.g., a rectangle) mask := gocv.NewMatWithSize(img.Rows(), img.Cols(), gocv.MatTypeCV8UC1) defer mask.Close() // Define the area to inpaint inpaintRect := image.Rect(img.Cols()/4, img.Rows()/4, img.Cols()/2, img.Rows()/2) gocv.Rectangle(&mask, inpaintRect, gocv.Scalar(255), -1) inpaintedImg := gocv.NewMat() defer inpaintedImg.Close() // Use Navier-Stokes inpainting algorithm inpainter := xphoto.NewInpaintNLMeans() defer inpainter.Close() inpainter.Inpaint(img, mask, &inpaintedImg, xphoto.INPAINT_TELEA, 3) err = gocv.imwrite(outputPath+"/inpainted.jpg", inpaintedImg) if err != nil { fmt.Printf("Error saving inpainted image: %v\n", err) } fmt.Printf("Processed images saved to %s\n", outputPath) } ``` -------------------------------- ### Feature Matching: Match image features using SIFT (Go) Source: https://github.com/katefox1982/gocv/blob/release/cmd/README.md Matches features in an image using the SIFT algorithm. This example demonstrates image feature detection and matching techniques. ```Go // Example for Feature Matching // Source: https://github.com/hybridgroup/gocv/blob/release/cmd/feature-matching/main.go ``` -------------------------------- ### Install GoCV with OpenVINO and CUDA Support Source: https://github.com/katefox1982/gocv/blob/release/README.md Installs GoCV along with OpenCV, enabling support for OpenVINO and CUDA. This command requires the repository to be cloned. ```shell cd $HOME/folder/with/gocv/ make install_all ``` -------------------------------- ### Windows Custom Environment Setup Source: https://github.com/katefox1982/gocv/blob/release/README.md Configure GoCV on Windows to use a custom OpenCV installation, especially for different versions. This requires setting CGO environment variables for C++ flags, preprocessor paths, and linker flags, then building with the customenv tag. ```powershell set CGO_CXXFLAGS="--std=c++11" set CGO_CPPFLAGS=-IC:\opencv\build\install\include set CGO_LDFLAGS=-LC:\opencv\build\install\x64\mingw\lib -lopencv_core4110 -lopencv_face4110 -lopencv_videoio4110 -lopencv_imgproc4110 -lopencv_highgui4110 -lopencv_imgcodecs4110 -lopencv_objdetect4110 -lopencv_features2d4110 -lopencv_video4110 -lopencv_dnn4110 -lopencv_xfeatures2d4110 -lopencv_plot4110 -lopencv_tracking4110 -lopencv_img_hash4110 ``` ```go go run -tags customenv cmd\version\main.go ``` -------------------------------- ### GoCV DNN CUDA Backend Setup Source: https://github.com/katefox1982/gocv/blob/release/cuda/README.md Loads a Caffe model and configures the network to use CUDA as the preferred backend and target for GPU acceleration. This requires OpenCV to be compiled with CUDA support. ```go net := gocv.ReadNet("/path/to/your/model.caffemodel", "/path/to/your/config.proto") if net.Empty() { fmt.Println("Error reading network model") return } net.SetPreferableBackend(gocv.NetBackendType(gocv.NetBackendCUDA)) net.SetPreferableTarget(gocv.NetTargetType(gocv.NetTargetCUDA)) ``` -------------------------------- ### Clone GoCV Repository Source: https://github.com/katefox1982/gocv/blob/release/README.md Clones the GoCV repository from GitHub to your local machine. This is the initial step for installation. ```shell cd $HOME/folder/with/your/src/ git clone https://github.com/hybridgroup/gocv.git ``` -------------------------------- ### Capture Test: Verify webcam capture functionality (Go) Source: https://github.com/katefox1982/gocv/blob/release/cmd/README.md Tests to verify that video can be successfully captured from a connected webcam. This is a fundamental example for establishing camera input. ```Go // Example for Capture Test // Source: https://github.com/hybridgroup/gocv/blob/release/cmd/captest/main.go ``` -------------------------------- ### Install Pkg-config on macOS Source: https://github.com/katefox1982/gocv/blob/release/README.md Installs pkg-config using Homebrew. Pkg-config is essential for determining the correct compilation and linking flags for OpenCV. ```shell brew install pkgconfig ``` -------------------------------- ### Image Similarity: Compare image perceptual hashes (Go) Source: https://github.com/katefox1982/gocv/blob/release/cmd/README.md Computes and compares perceptual hashes for a pair of images using various algorithms. This example is useful for finding similar images. ```Go // Example for Image Similarity // Source: https://github.com/hybridgroup/gocv/blob/release/cmd/img-similarity/main.go ``` -------------------------------- ### Install GoCV on Raspbian Source: https://github.com/katefox1982/gocv/blob/release/README.md Installs OpenCV 4.11.0 and GoCV on Raspbian using the provided Makefile. This command handles downloading and building the necessary components with hardware optimizations. ```shell cd $HOME/folder/with/your/src/gocv make install_raspi ``` -------------------------------- ### Save Video: Capture and save video frames to file (Go) Source: https://github.com/katefox1982/gocv/blob/release/cmd/README.md Captures video from a camera and saves 100 frames to a video file on disk. This example demonstrates video recording and file output. ```Go // Example for Save Video // Source: https://github.com/hybridgroup/gocv/blob/release/cmd/savevideo/main.go ``` -------------------------------- ### Install GoCV with Static OpenCV Libraries Source: https://github.com/katefox1982/gocv/blob/release/README.md Installs GoCV using static OpenCV libraries, disabling the build of shared libraries for a self-contained installation. ```shell make install BUILD_SHARED_LIBS=OFF ``` -------------------------------- ### Setup OpenVINO Environment Source: https://github.com/katefox1982/gocv/blob/release/openvino/README.md Sets up the necessary environment variables for the Intel OpenVINO toolkit by sourcing the `setupvars.sh` script. This is a prerequisite for using OpenVINO functionalities. ```shell source /opt/intel/openvino_2022/setupvars.sh ``` -------------------------------- ### Start Socat Proxy for X Window Traffic Source: https://github.com/katefox1982/gocv/blob/release/README.md Starts a local socat proxy to stream X Window data into XQuartz. This command listens on port 6000 and forwards traffic to the XQuartz server, enabling GUI display from Docker. Ensure no other process is using port 6000 beforehand. ```shell lsof -i TCP:6000 socat TCP-LISTEN:6000,reuseaddr,fork UNIX-CLIENT:"$DISPLAY" ``` -------------------------------- ### ASCIIcam: Display webcam video in terminal (Go) Source: https://github.com/katefox1982/gocv/blob/release/cmd/README.md Captures video from a connected webcam and displays it in the current terminal window using ASCII characters. This example showcases real-time video processing and terminal output. ```Go // Example for ASCIIcam // Source: https://github.com/hybridgroup/gocv/blob/release/cmd/asciicam/main.go ``` -------------------------------- ### Install GoCV with OpenCV 4.11.0 on Linux Source: https://github.com/katefox1982/gocv/blob/release/README.md Installs GoCV and OpenCV 4.11.0 on Linux. This command assumes the repository has already been cloned. ```shell cd gocv make install ``` -------------------------------- ### Motion Detection: Detect motion in a video feed (Go) Source: https://github.com/katefox1982/gocv/blob/release/cmd/README.md Opens a video capture device and processes the feed to detect motion, whether human or otherwise. This example focuses on background subtraction and motion analysis. ```Go // Example for Motion Detection // Source: https://github.com/hybridgroup/gocv/blob/release/cmd/motion-detect/main.go ``` -------------------------------- ### Find Lines: Detect lines in an image using Hough transform (Go) Source: https://github.com/katefox1982/gocv/blob/release/cmd/README.md Finds lines in an image using the Hough transform. This example demonstrates line detection, a common task in image analysis. ```Go // Example for Find Lines // Source: https://github.com/hybridgroup/gocv/blob/release/cmd/find-lines/main.go ``` -------------------------------- ### Install GoCV with Static OpenVINO/CUDA Libraries Source: https://github.com/katefox1982/gocv/blob/release/README.md Installs GoCV with static OpenCV libraries, including support for OpenVINO and CUDA, disabling shared library builds. ```shell make install_all BUILD_SHARED_LIBS=OFF ``` -------------------------------- ### Example: HTTP Interface for Profiling Source: https://github.com/katefox1982/gocv/blob/release/README.md This example shows how to integrate GoCV's Mat profiler with the standard Go HTTP profiling interface. It leaks a Mat every second and exposes profiling data at http://localhost:6060/debug/pprof/gocv.io/x/gocv.Mat. ```go package main import ( "net/http" _ "net/http/pprof" "time" "gocv.io/x/gocv" ) func leak() { gocv.NewMat() } func main() { go func() { ticker := time.NewTicker(time.Second) for { <- icker.C leak() } }() http.ListenAndServe("localhost:6060", nil) } ``` -------------------------------- ### DNN Style Transfer: Real-time style transfer with DNN (Go) Source: https://github.com/katefox1982/gocv/blob/release/cmd/README.md Performs real-time style transfer using a Deep Neural Network. This example applies artistic styles to video feeds dynamically. ```Go // Example for DNN Style Transfer // Source: https://github.com/hybridgroup/gocv/blob/release/cmd/dnn-style-transfer/main.go ``` -------------------------------- ### Capture Window: Display webcam video in a window (Go) Source: https://github.com/katefox1982/gocv/blob/release/cmd/README.md Captures video from a webcam and displays the video feed in a graphical window. This demonstrates basic video output and window management. ```Go // Example for Capture Window // Source: https://github.com/hybridgroup/gocv/blob/release/cmd/capwindow/main.go ``` -------------------------------- ### MJPEG Streamer: Stream webcam feed as MJPEG (Go) Source: https://github.com/katefox1982/gocv/blob/release/cmd/README.md Opens a video capture device and streams its feed as MJPEG, viewable in any web browser. This example demonstrates real-time streaming capabilities. ```Go // Example for MJPEG Streamer // Source: https://github.com/hybridgroup/gocv/blob/release/cmd/mjpeg-streamer/main.go ``` -------------------------------- ### Clone GoCV Repository Source: https://github.com/katefox1982/gocv/blob/release/README.md Clones the GoCV repository from GitHub to your local machine. This is the first step in the installation process for Raspbian. ```shell cd $HOME/folder/with/your/src/ git clone https://github.com/hybridgroup/gocv.git ``` -------------------------------- ### SSD Face Detection: Detect faces using SSD DNN (Go) Source: https://github.com/katefox1982/gocv/blob/release/cmd/README.md An advanced example using a Single Shot Detector (SSD) classifier to detect faces from a connected camera. This showcases state-of-the-art DNN-based face detection. ```Go // Example for SSD Face Detection // Source: https://github.com/hybridgroup/gocv/blob/release/cmd/ssd-facedetect/main.go ``` -------------------------------- ### Core - Optimization Algorithms: DownhillSolver Source: https://github.com/katefox1982/gocv/blob/release/ROADMAP.md The 'DownhillSolver' class is part of the optimization algorithms in the core module. It is currently marked as 'WORK STARTED' and requires implementation. ```APIDOC Module: core Submodule: Optimization Algorithms Class: DownhillSolver Status: WORK STARTED Description: A solver class for optimization problems, likely implementing a downhill simplex method. Reference: https://docs.opencv.org/master/d4/d43/classcv_1_1DownhillSolver.html ``` -------------------------------- ### Core - Optimization Algorithms: ConjGradSolver Source: https://github.com/katefox1982/gocv/blob/release/ROADMAP.md The 'ConjGradSolver' class is part of the optimization algorithms in the core module. It is currently marked as 'WORK STARTED' and requires implementation. ```APIDOC Module: core Submodule: Optimization Algorithms Class: ConjGradSolver Status: WORK STARTED Description: A solver class for optimization problems, likely implementing the Conjugate Gradient method. Reference: https://docs.opencv.org/master/d0/d21/classcv_1_1ConjGradSolver.html ``` -------------------------------- ### DNN Pose Detection: Track human body poses with DNN (Go) Source: https://github.com/katefox1982/gocv/blob/release/cmd/README.md Utilizes a Deep Neural Network trained with OpenPose to detect and track human body poses in real-time. This example demonstrates sophisticated pose estimation. ```Go // Example for DNN Pose Detection // Source: https://github.com/hybridgroup/gocv/blob/release/cmd/dnn-pose-detection/main.go ``` -------------------------------- ### Download OpenCV Source Source: https://github.com/katefox1982/gocv/blob/release/README.md Downloads the source code for OpenCV 4.11.0 and the OpenCV Contrib modules. This is part of the manual installation process. ```shell make download ``` -------------------------------- ### GoCV Version Display Source: https://github.com/katefox1982/gocv/blob/release/cmd/README.md Displays the current version of OpenCV being utilized by the GoCV library. ```go package main import ( "fmt" "os" "gocv.io/gocv/v2" ) func main() { fmt.Printf("GoCV Version: %s\n", gocv.Version()) fmt.Printf("OpenCV Version: %s\n", gocv.OpenCVVersion()) if len(os.Args) > 1 && os.Args[1] == "--help" { fmt.Println("Usage: version") return } } ``` -------------------------------- ### Build GoCV Application with Custom Environment Source: https://github.com/katefox1982/gocv/blob/release/README.md Builds or runs a GoCV application using a custom environment setup, enabling the 'customenv' tag. ```shell go run -tags customenv ./cmd/version/main.go ``` -------------------------------- ### Core Functionality - Basic Structures Source: https://github.com/katefox1982/gocv/blob/release/ROADMAP.md This section covers the basic data structures used within the core functionality of the gocv project. It is marked as 'WORK STARTED'. ```APIDOC Module: core Functionality: Basic Structures Status: WORK STARTED Description: Implementation of fundamental data structures for the core module. Details: Specific structures and their usage are not detailed in the provided text, but are part of the initial development phase. ``` -------------------------------- ### Compile OpenCV with CUDA Support Source: https://github.com/katefox1982/gocv/blob/release/cuda/README.md Commands to compile OpenCV with CUDA support using the GoCV Makefile. Includes options for static library builds and verification steps. ```bash make install_cuda # For static opencv libraries: # make install_cuda BUILD_SHARED_LIBS=OFF # Verify installation: cd $GOPATH/src/gocv.io/x/gocv go run ./cmd/cuda/main.go ``` -------------------------------- ### KAZE Constructor Functions Source: https://github.com/katefox1982/gocv/blob/release/DOCS.md Provides functions to create new KAZE algorithm instances, with options for default or custom parameter initialization. ```go func NewKAZE() KAZE // NewKAZE returns a new KAZE algorithm func NewKazeWithParams(extended bool, upright bool, threshold float32, nOctaves int, nOctaveLayers int, diffusivity int) KAZE // NewKazeWithParams returns a new KAZE algorithm with the specified parameters. ``` -------------------------------- ### Install OpenCV on macOS Source: https://github.com/katefox1982/gocv/blob/release/README.md Installs OpenCV 4.11.0 on macOS using Homebrew. It's recommended to uninstall any previous versions (e.g., 3.4.x) before installing the new version. ```shell brew uninstall opencv brew install opencv ``` -------------------------------- ### Verify GoCV OpenVINO Version Source: https://github.com/katefox1982/gocv/blob/release/openvino/README.md Runs a GoCV example to verify that the application is compiling and linking against the Intel OpenVINO enabled OpenCV library. The `-tags customenv` flag is necessary for `go run`, `go build`, and `go test` to pick up the correct environment settings. ```go go run -tags customenv ./cmd/version/main.go ``` -------------------------------- ### Basic Drawing: Demonstrate drawing primitives (Go) Source: https://github.com/katefox1982/gocv/blob/release/cmd/README.md Demonstrates the basic drawing primitives available for drawing on images using GoCV. This includes lines, rectangles, circles, and text, illustrating image manipulation capabilities. ```Go // Example for Basic Drawing // Source: https://github.com/hybridgroup/gocv/blob/release/cmd/basic-drawing/main.go ``` -------------------------------- ### Install XQuartz and Socat for macOS Docker GUI Source: https://github.com/katefox1982/gocv/blob/release/README.md Prerequisites for running GoCV GUI programs in Docker on macOS. XQuartz is needed for the X Window System, and socat is used to create a TCP proxy. ```shell brew cask install xquartz brew install socat ``` -------------------------------- ### Setup GoCV OpenVINO Exports Source: https://github.com/katefox1982/gocv/blob/release/openvino/README.md Sets additional environment variables required for building and running GoCV code with OpenVINO support. This involves sourcing the `env.sh` script located within the GoCV `openvino` directory. ```shell source openvino/env.sh ``` -------------------------------- ### Find Circles: Detect circles in an image using Hough transform (Go) Source: https://github.com/katefox1982/gocv/blob/release/cmd/README.md Finds circles in an image using the Hough transform. This example demonstrates geometric shape detection in images. ```Go // Example for Find Circles // Source: https://github.com/hybridgroup/gocv/blob/release/cmd/find-circles/main.go ``` -------------------------------- ### Save Image: Capture and save a single webcam frame (Go) Source: https://github.com/katefox1982/gocv/blob/release/cmd/README.md Captures a single frame from a connected webcam and saves it to an image file on disk. This is a basic example for capturing and persisting image data. ```Go // Example for Save Image // Source: https://github.com/hybridgroup/gocv/blob/release/cmd/saveimage/main.go ``` -------------------------------- ### NewWindow Function Source: https://github.com/katefox1982/gocv/blob/release/DOCS.md Creates and returns a pointer to a new named OpenCV window. This function is the entry point for managing GUI windows. ```go func NewWindow(name string) *Window ``` -------------------------------- ### VideoWriter.IsOpened Method Source: https://github.com/katefox1982/gocv/blob/release/DOCS.md Checks if the VideoWriter instance is successfully opened and ready for writing video frames. Returns true if the writer is operational. ```go func (vw *VideoWriter) IsOpened() bool // IsOpened checks if the VideoWriter is open and ready to be written to. // For further details, please see: // http://docs.opencv.org/master/dd/d9e/classcv_1_1VideoWriter.html#a9a40803e5f671968ac9efa877c984d75 ``` -------------------------------- ### Hand Gestures: Count fingers using convexity defects (Go) Source: https://github.com/katefox1982/gocv/blob/release/cmd/README.md Counts the number of fingers held up by analyzing convexity defects in the camera feed. This example showcases gesture recognition and contour analysis. ```Go // Example for Hand Gestures // Source: https://github.com/hybridgroup/gocv/blob/release/cmd/hand-gestures/main.go ``` -------------------------------- ### Faceblur: Detect and blur faces in webcam feed (Go) Source: https://github.com/katefox1982/gocv/blob/release/cmd/README.md Captures video from a camera, detects faces using CascadeClassifier, blurs them with Gaussian blur, and displays the result. This example focuses on privacy-preserving video processing. ```Go // Example for Faceblur // Source: https://github.com/hybridgroup/gocv/blob/release/cmd/faceblur/main.go ``` -------------------------------- ### Open and Display Video Feed in Go Source: https://github.com/katefox1982/gocv/blob/release/README.md This Go code snippet demonstrates how to open a video capture device (like a webcam) using the GoCV library. It continuously reads frames from the device and displays them in a GUI window, providing a basic video streaming functionality. It requires the GoCV library and OpenCV to be installed. ```Go package main import ( "gocv.io/x/gocv" ) func main() { webcam, _ := gocv.OpenVideoCapture(0) window := gocv.NewWindow("Hello") img := gocv.NewMat() for { webcam.Read(&img) window.IMShow(img) window.WaitKey(1) } } ``` -------------------------------- ### DNN Detection: Detect and track objects/faces with DNN (Go) Source: https://github.com/katefox1982/gocv/blob/release/cmd/README.md Uses a Deep Neural Network (DNN) to detect and track objects or faces in video streams. This example showcases advanced object recognition capabilities. ```Go // Example for DNN Detection // Source: https://github.com/hybridgroup/gocv/blob/release/cmd/dnn-detection/main.go ``` -------------------------------- ### Counter: Count objects crossing a line in video (Go) Source: https://github.com/katefox1982/gocv/blob/release/cmd/README.md Captures video from a file and counts detected objects crossing a user-defined vertical or horizontal line. This example focuses on object tracking and motion detection. ```Go // Example for Counter // Source: https://github.com/hybridgroup/gocv/blob/release/cmd/counter/main.go ``` -------------------------------- ### WaitKeyEx Source: https://github.com/katefox1982/gocv/blob/release/DOCS.md WaitKeyEx is similar to WaitKey but returns the full key code. The returned key code is implementation-specific and depends on the backend used (e.g., QT, GTK). ```go func (w *Window) WaitKeyEx(delay int) int ``` -------------------------------- ### Points2fVector Methods Source: https://github.com/katefox1982/gocv/blob/release/DOCS.md Methods for manipulating Points2fVector, including appending Point2fVectors, accessing Point2fVectors by index, checking if the vector is nil, getting its size, and converting it to a slice of slices of Point2f. It also includes a method to get the underlying CGo pointer. ```go func (pvs Points2fVector) Append(pv Point2fVector) ``` ```go func (pvs Points2fVector) At(idx int) Point2fVector ``` ```go func (pvs Points2fVector) Close() ``` ```go func (pvs Points2fVector) IsNil() bool ``` ```go func (pvs Points2fVector) P() C.Points2fVector ``` ```go func (pvs Points2fVector) Size() int ``` ```go func (pvs Points2fVector) ToPoints() [][]Point2f ``` -------------------------------- ### Tensorflow Classifier: Classify webcam feed with TensorFlow (Go) Source: https://github.com/katefox1982/gocv/blob/release/cmd/README.md Captures video from a webcam and uses the TensorFlow machine learning framework to classify objects in the camera's view. This example highlights integration with TensorFlow models. ```Go // Example for Tensorflow Classifier // Source: https://github.com/hybridgroup/gocv/blob/release/cmd/tf-classifier/main.go ``` -------------------------------- ### IMShow Source: https://github.com/katefox1982/gocv/blob/release/DOCS.md IMShow displays an image Mat in the specified window. This function should be followed by the WaitKey function which displays the image for specified milliseconds; otherwise, it won't display the image. ```go func (w *Window) IMShow(img Mat) error ``` -------------------------------- ### Caffe Classifier: Classify webcam feed with Caffe (Go) Source: https://github.com/katefox1982/gocv/blob/release/cmd/README.md Captures video from a webcam and uses the Caffe deep learning framework to classify objects in the camera's view. This example highlights integration with deep learning models. ```Go // Example for Caffe Classifier // Source: https://github.com/hybridgroup/gocv/blob/release/cmd/caffe-classifier/main.go ``` -------------------------------- ### Facedetect: Detect faces and draw rectangles (Go) Source: https://github.com/katefox1982/gocv/blob/release/cmd/README.md Captures video from a camera, detects faces using CascadeClassifier, and draws rectangles around them before displaying the video. This demonstrates face detection and annotation. ```Go // Example for Facedetect // Source: https://github.com/hybridgroup/gocv/blob/release/cmd/facedetect/main.go ``` -------------------------------- ### PointsVector: Get CGo Pointer (Go) Source: https://github.com/katefox1982/gocv/blob/release/DOCS.md Returns the underlying CGo pointer for the PointsVector. This is typically used for internal CGo operations. ```go func (pvs PointsVector) P() C.PointsVector ``` -------------------------------- ### Mat Initialization and Utility Source: https://github.com/katefox1982/gocv/blob/release/DOCS.md Provides utility functions for creating Mats filled with specific values, such as ones or zeros. These are useful for initializing matrices for calculations or as placeholders. ```APIDOC func Ones(rows int, cols int, mt MatType) Mat Returns an array of all 1's of the specified size and type. The method returns a Matlab-style 1's array initializer. For further details, please see: https://docs.opencv.org/master/d3/d63/classcv_1_1Mat.html#a69ae0402d116fc9c71908d8508dc2f09 func Zeros(rows int, cols int, mt MatType) Mat Returns a zero array of the specified size and type. The method returns a Matlab-style zero array initializer. For further details, please see: https://docs.opencv.org/master/d3/d63/classcv_1_1Mat.html#a0b57b6a326c8876d944d188a46e0f556 ``` -------------------------------- ### Size: Get Mat dimensions in Go Source: https://github.com/katefox1982/gocv/blob/release/DOCS.md Returns an array containing the size of each dimension for the Mat. This provides the extent of the matrix along each axis. ```go func (m *Mat) Size() (dims []int) ``` -------------------------------- ### Running GoCV Tests Source: https://github.com/katefox1982/gocv/blob/release/CONTRIBUTING.md Commands to execute GoCV unit tests. You can run all tests, tests within the contrib directory, filter tests by name using a regular expression, or run tests specifically for Intel OpenVINO integration. ```shell go test . ``` ```shell go test ./contrib/. ``` ```shell go test -run TestMat ``` ```shell go test ./openvino/... ``` -------------------------------- ### Cleanup GoCV Build Files Source: https://github.com/katefox1982/gocv/blob/release/README.md Removes temporary build files and folders created during the GoCV installation process. ```shell make clean ``` -------------------------------- ### Total: Get total number of elements in Go Mat Source: https://github.com/katefox1982/gocv/blob/release/DOCS.md Returns the total number of elements contained within the Mat. This is the product of all dimension sizes. ```go func (m *Mat) Total() int ``` -------------------------------- ### FaceDetectorYN Constructor Source: https://github.com/katefox1982/gocv/blob/release/DOCS.md Provides the constructor for the FaceDetectorYN struct, which is used for face detection. It takes model and configuration paths, along with the input image size, to initialize the detector. ```go func NewFaceDetectorYN(modelPath string, configPath string, size image.Point) FaceDetectorYN // NewFaceDetectorYN Creates an instance of face detector with given parameters. // modelPath: the path to the requested model // configPath: the path to the config file for compability, which is not requested // for ONNX models // size: the size of the input image ``` -------------------------------- ### PointsVector: Get Size (Go) Source: https://github.com/katefox1982/gocv/blob/release/DOCS.md Returns the number of Point vectors contained within the PointsVector. This indicates how many distinct contour sets are stored. ```go func (pvs PointsVector) Size() int ``` -------------------------------- ### Run Project Tests Source: https://github.com/katefox1982/gocv/blob/release/CONTRIBUTING.md Executes the project's test suite using the 'make test' command. This is essential to run before committing to ensure your changes do not break existing functionality. ```make make test ``` -------------------------------- ### Go CreateHanningWindow Source: https://github.com/katefox1982/gocv/blob/release/DOCS.md Computes Hanning window coefficients in two dimensions. It takes a destination Mat pointer, the desired size, and the Mat type. ```go func CreateHanningWindow(img *Mat, size image.Point, typ MatType) error ``` -------------------------------- ### PointsVector: Get PointVector at Index (Go) Source: https://github.com/katefox1982/gocv/blob/release/DOCS.md Returns the PointVector located at the specified index within the PointsVector. This allows access to individual contour vectors. ```go func (pvs PointsVector) At(idx int) PointVector ```