gocv

package module
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 11, 2017 License: Apache-2.0 Imports: 6 Imported by: 0

README

GoCV

GoCV

GoDoc Build Status codecov Go Report Card License

The GoCV package provides Go language bindings for the OpenCV 3 computer vision library.

GoCV supports the latest release of OpenCV (v3.3) on Linux, OS X, and (soon) Windows. We hope to make the Go programming language a "first-class" client compatible with the latest developments in the OpenCV ecosystem.

GoCV also supports the Intel Computer Vision SDK using the Photography Vision Library (PVL). Check out the PVL README for more info on how to use GoCV with the Intel CV SDK.

How to use

Hello, video

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

package main

import (
	"github.com/hybridgroup/gocv"
)

func main() {
	webcam, _ := gocv.VideoCaptureDevice(0)
	window := gocv.NewWindow("Hello")	
	img := gocv.NewMat()

	for {
		webcam.Read(img)
		window.IMShow(img)
		gocv.WaitKey(1)
	}
}
Face detect

GoCV

This is a more complete example that opens a video capture device using device "0". It also uses the CascadeClassifier class to load an external data file containing the classifier data. The program grabs each frame from the video, then uses the classifier to detect faces. If any faces are found, it draws a green rectangle around each one, then displays the video in an output window:

package main

import (
	"fmt"
	"image/color"

	"github.com/hybridgroup/gocv"
)

func main() {
	deviceID := 0

	// open webcam
	webcam, err := gocv.VideoCaptureDevice(int(deviceID))
	if err != nil {
		fmt.Printf("error opening video capture device: %v\n", deviceID)
		return
	}	
	defer webcam.Close()

	// open display window
	window := gocv.NewWindow("Face Detect")
	defer window.Close()

	// prepare image matrix
	img := gocv.NewMat()
	defer img.Close()

	// color for the rect when faces detected
	blue := color.RGBA{0, 0, 255, 0}

	// load classifier to recognize faces
	classifier := gocv.NewCascadeClassifier()
	defer classifier.Close()
	
	classifier.Load("data/haarcascade_frontalface_default.xml")

	fmt.Printf("start reading camera device: %v\n", deviceID)
	for {
		if ok := webcam.Read(img); !ok {
			fmt.Printf("cannot read device %d\n", deviceID)
			return
		}
		if img.Empty() {
			continue
		}

		// detect faces
		rects := classifier.DetectMultiScale(img)
		fmt.Printf("found %d faces\n", len(rects))

		// draw a rectangle around each face on the original image
		for _, r := range rects {
			gocv.Rectangle(img, r, blue, 3)
		}

		// show the image in the window, and wait 1 millisecond
		window.IMShow(img)
		gocv.WaitKey(1)
	}
}
More examples

There are examples in the cmd directory of this repo in the form of various useful command line utilities, such as capturing an image file and streaming mjpeg video.

How to install

To install GoCV, run the following command:

go get -u -d github.com/hybridgroup/gocv

To run code that uses the GoCV package, you must also install OpenCV 3.3 on your system. Here are instructions for Ubuntu, OS X, and Windows.

Ubuntu/Linux

You can use make to install OpenCV 3.3 with the handy Makefile included with this repo. If you already have installed OpenCV, you do not need to do so again. The installation performed by the Makefile is minimal, so it may remove OpenCV options such as Python or Java wrappers if you have already installed OpenCV some other way.

Install required packages

First, you need to change the current directory to the location of the GoCV repo, so you can access the Makefile:

	cd $GOPATH/src/github.com/hybridgroup.com/gocv

Next, you need to update the system, and install any required packages:

	make deps
Download source

Now, download the OpenCV 3.3 and OpenCV Contrib source code:

	make download
Build

Build and install everything. This will take quite a while:

	make build
Cleanup extra files

After the installation is complete, you can remove the extra files and folders:

	make cleanup
OS X

You can install OpenCV 3.3 using Homebrew:

	brew install opencv
Windows

Instructions needed...

How to build/run code

Ubuntu/Linux

In order to build/run Go code that uses this package, you will need to specify the location for the includes and libs for your gocv installation.

First, change the current directory to the location of the GoCV repo:

	cd $GOPATH/src/github.com/hybridgroup.com/gocv

One time per session, you must run the script:

	source ./env.sh

Now you should be able to build or run any of the examples:

	go run ./cmd/version/main.go

The version program should output the following:

	gocv version: 0.1.0
	opencv lib version: 3.3.0

You might want to copy the env.sh script into your own projects, to make it easier to setup these vars when building your own code.

Other Linux installations

One way to find out thelocations for your includes and libs is to use the pkg-config tool like this:

	pkg-config --cflags opencv

Should output the include flags:

	-I/usr/local/include/opencv -I/usr/local/include

Then this command:

	pkg-config --libs opencv

Should output the lib flags:

	-L/usr/local/lib -lopencv_stitching -lopencv_superres -lopencv_videostab -lopencv_photo -lopencv_aruco -lopencv_bgsegm -lopencv_bioinspired -lopencv_ccalib -lopencv_dpm -lopencv_face -lopencv_freetype -lopencv_fuzzy -lopencv_img_hash -lopencv_line_descriptor -lopencv_optflow -lopencv_reg -lopencv_rgbd -lopencv_saliency -lopencv_stereo -lopencv_structured_light -lopencv_phase_unwrapping -lopencv_surface_matching -lopencv_tracking -lopencv_datasets -lopencv_text -lopencv_dnn -lopencv_plot -lopencv_ml -lopencv_xfeatures2d -lopencv_shape -lopencv_video -lopencv_ximgproc -lopencv_calib3d -lopencv_features2d -lopencv_highgui -lopencv_videoio -lopencv_flann -lopencv_xobjdetect -lopencv_imgcodecs -lopencv_objdetect -lopencv_xphoto -lopencv_imgproc -lopencv_core

Once you have this info, you can build or run the Go code that consumes it by populating the needed CGO_CPPFLAGS and CGO_LDFLAGS ENV vars.

For example:

	export CGO_CPPFLAGS="-I/usr/local/include" 
	export CGO_LDFLAGS="-L/usr/local/lib -lopencv_core -lopencv_videoio -lopencv_imgproc -lopencv_highgui -lopencv_imgcodecs -lopencv_objdetect -lopencv_calib3d"

Please note that you will need to run these 2 lines of code one time in your current session in order to build or run the code, in order to setup the needed ENV variables.

OS X

In order to build/run Go code that uses this package, you will need to specify the location for the includes and libs for your gocv installation. If you have used Homebrew to install OpenCV 3.3, the following instructions should work.

First, you need to change the current directory to the location of the GoCV repo:

	cd $GOPATH/src/github.com/hybridgroup.com/gocv

One time per session, you must run the script:

	source ./env.sh

Now you should be able to build or run any of the command examples:

	go run ./cmd/version/main.go

The version program should output the following:

	gocv version: 0.1.0
	opencv lib version: 3.3.0

You might want to copy the env.sh script into your own projects, to make it easier to setup these vars when building your own code.

Windows

Instructions here...

What works and to work on next

  • Video capture
  • GUI Window to display video
  • Image load/save
  • CascadeClassifier for object detection/face tracking/etc.
  • Installation instructions for Ubuntu
  • Installation instructions for OS X
  • Code example to use VideoWriter
  • Intel CV SDK PVL FaceTracker support
  • imgproc Image processing
  • Travis CI build
  • At least minimal test coverage for each OpenCV class
  • Implement more of imgproc Image processing
  • Installation/usage instructions for Windows
  • Appveyor build
  • calib3d Camera Calibration and 3D Reconstruction
  • Intel CV SDK PVL FaceRecognizer
  • Your favorite OpenCV module!

How to contribute

We would like your help to make this project better, so we appreciate any contributions.

The master branch of this repo will always have the latest released version of GoCV. All of the active development work for the next release will take place in the dev branch. GoCV will use semantic versioning and will create a tag/release for each release.

Here is how to contribute back some code or documentation:

  • Fork repo
  • Create a feature branch off of the dev branch
  • Make some useful change
  • Submit a pull request against the dev branch.
  • Be kind

Thank you!

Why this project exists

The https://github.com/go-opencv/go-opencv package for Go and OpenCV does not support any version above OpenCV 2.x, and work on adding support for OpenCV 3 has stalled for over a year, mostly due to the complexity of SWIG.

The GoCV package uses a C-style wrapper around the OpenCV 3 C++ classes to avoid having to deal with applying SWIG to a huge existing codebase. The mappings are intended to match as closely as possible to the original OpenCV project structure, to make it easier to find things, and to be able to figure out where to add support to GoCV for additional OpenCV image filters, algorithms, and other features.

For example, the OpenCV videoio module wrappers can be found in the GoCV package in the videoio.* files.

This package was inspired by the original https://github.com/go-opencv/go-opencv project, the blog post https://medium.com/@peterleyssens/using-opencv-3-from-golang-5510c312a3c and the repo at https://github.com/sensorbee/opencv thank you all!

License

Licensed under the Apache 2.0 license. Copyright (c) 2017 The Hybrid Group.

Logo generated by GopherizeMe - https://gopherize.me

Documentation

Overview

Package gocv is a wrapper around the OpenCV 3.x computer vision library. It provides a Go language interface to the latest version of OpenCV.

OpenCV (Open Source Computer Vision Library: http://opencv.org) is an open-source BSD-licensed library that includes several hundreds of computer vision algorithms.

For further details, please see: http://docs.opencv.org/3.3.0/d1/dfb/intro.html

Index

Constants

View Source
const (
	// MatTypeCV8U is a Mat of 8-bit unsigned int
	MatTypeCV8U MatType = 0

	// MatTypeCV8S is a Mat of 8-bit signed int
	MatTypeCV8S = 1

	// MatTypeCV16U is a Mat of 16-bit unsigned int
	MatTypeCV16U = 2

	// MatTypeCV16S is a Mat of 16-bit signed int
	MatTypeCV16S = 3

	// MatTypeCV32S is a Mat of 32-bit signed int
	MatTypeCV32S = 4

	// MatTypeCV32F is a Mat of 32-bit float
	MatTypeCV32F = 5

	// MatTypeCV64F is a Mat of 64-bit float
	MatTypeCV64F = 6
)
View Source
const (
	// IMReadUnchanged return the loaded image as is (with alpha channel,
	// otherwise it gets cropped).
	IMReadUnchanged IMReadFlag = -1

	// IMReadGrayScale always convert image to the single channel
	// grayscale image.
	IMReadGrayScale = 0

	// IMReadColor always converts image to the 3 channel BGR color image.
	IMReadColor = 1

	// IMReadAnyDepth returns 16-bit/32-bit image when the input has the corresponding
	// depth, otherwise convert it to 8-bit.
	IMReadAnyDepth = 2

	// IMReadAnyColor the image is read in any possible color format.
	IMReadAnyColor = 4

	// IMReadLoadGDAL uses the gdal driver for loading the image.
	IMReadLoadGDAL = 8

	// IMReadReducedGrayscale2 always converts image to the single channel grayscale image
	// and the image size reduced 1/2.
	IMReadReducedGrayscale2 = 16

	// IMReadReducedColor2 always converts image to the 3 channel BGR color image and the
	// image size reduced 1/2.
	IMReadReducedColor2 = 17

	// IMReadReducedGrayscale4 always converts image to the single channel grayscale image and
	// the image size reduced 1/4.
	IMReadReducedGrayscale4 = 32

	// IMReadReducedColor4 always converts image to the 3 channel BGR color image and
	// the image size reduced 1/4.
	IMReadReducedColor4 = 33

	// IMReadReducedGrayscale8 always convert image to the single channel grayscale image and
	// the image size reduced 1/8.
	IMReadReducedGrayscale8 = 64

	// IMReadReducedColor8 always convert image to the 3 channel BGR color image and the
	// image size reduced 1/8.
	IMReadReducedColor8 = 65

	// IMReadIgnoreOrientation do not rotate the image according to EXIF's orientation flag.
	IMReadIgnoreOrientation = 128
)
View Source
const (
	// FontHersheySimplex is normal size sans-serif font.
	FontHersheySimplex HersheyFont = 0
	// FontHersheyPlain issmall size sans-serif font.
	FontHersheyPlain = 1
	// FontHersheyDuplex normal size sans-serif font
	// (more complex than FontHersheySIMPLEX).
	FontHersheyDuplex = 2
	// FontHersheyComplex i a normal size serif font.
	FontHersheyComplex = 3
	// FontHersheyTriplex is a normal size serif font
	// (more complex than FontHersheyCOMPLEX).
	FontHersheyTriplex = 4
	// FontHersheyComplexSmall is a smaller version of FontHersheyCOMPLEX.
	FontHersheyComplexSmall = 5
	// FontHersheyScriptSimplex is a hand-writing style font.
	FontHersheyScriptSimplex = 6
	// FontHersheyScriptComplex is a more complex variant of FontHersheyScriptSimplex.
	FontHersheyScriptComplex = 7
	// FontItalic is the flag for italic font.
	FontItalic = 16
)
View Source
const (
	// ColorBGRToBGRA adds alpha channel to BGR image.
	ColorBGRToBGRA ColorConversionCode = 0

	// ColorBGRAToBGR removes alpha channel from BGR image.
	ColorBGRAToBGR = 1

	// ColorBGRToRGBA converts from BGR to RGB with alpha channel.
	ColorBGRToRGBA = 2

	// ColorRGBAToBGR converts from RGB with alpha to BGR color space.
	ColorRGBAToBGR = 3

	// ColorBGRToRGB converts from BGR to RGB without alpha channel.
	ColorBGRToRGB = 4

	// ColorBGRAToRGBA converts from BGR with alpha channel
	// to RGB with alpha channel.
	ColorBGRAToRGBA = 5

	// ColorBGRToGray converts from BGR to grayscale.
	ColorBGRToGray = 6

	// ColorRGBToGray converts from RGB to grayscale.
	ColorRGBToGray = 7

	// ColorGrayToBGR converts from grayscale to BGR.
	ColorGrayToBGR = 8

	// ColorGrayToBGRA converts from grayscale to BGR with alpha channel.
	ColorGrayToBGRA = 9

	// ColorBGRAToGray converts from BGR with alpha channel to grayscale.
	ColorBGRAToGray = 10

	// ColorRGBAToGray converts from RGB with alpha channel to grayscale.
	ColorRGBAToGray = 11

	// ColorBGRToBGR565 converts from BGR to BGR565 (16-bit images).
	ColorBGRToBGR565 = 12

	// ColorRGBToBGR565 converts from RGB to BGR565 (16-bit images).
	ColorRGBToBGR565 = 13

	// ColorBGR565ToBGR converts from BGR565 (16-bit images) to BGR.
	ColorBGR565ToBGR = 14

	// ColorBGR565ToRGB converts from BGR565 (16-bit images) to RGB.
	ColorBGR565ToRGB = 15

	// ColorBGRAToBGR565 converts from BGRA (with alpha channel)
	// to BGR565 (16-bit images).
	ColorBGRAToBGR565 = 16

	// ColorRGBAToBGR565 converts from RGBA (with alpha channel)
	// to BGR565 (16-bit images).
	ColorRGBAToBGR565 = 17

	// ColorBGR565ToBGRA converts from BGR565 (16-bit images)
	// to BGRA (with alpha channel).
	ColorBGR565ToBGRA = 18

	// ColorBGR565ToRGBA converts from BGR565 (16-bit images)
	// to RGBA (with alpha channel).
	ColorBGR565ToRGBA = 19

	// ColorGrayToBGR565 converts from grayscale
	// to BGR565 (16-bit images).
	ColorGrayToBGR565 = 20

	// ColorBGR565ToGray converts from BGR565 (16-bit images)
	// to grayscale.
	ColorBGR565ToGray = 21

	// ColorBGRToBGR555 converts from BGR to BGR555 (16-bit images).
	ColorBGRToBGR555 = 22

	// ColorRGBToBGR555 converts from RGB to BGR555 (16-bit images).
	ColorRGBToBGR555 = 23

	// ColorBGR555ToBGR converts from BGR555 (16-bit images) to BGR.
	ColorBGR555ToBGR = 24

	// ColorBGR555ToRGB converts from BGR555 (16-bit images) to RGB.
	ColorBGR555ToRGB = 25

	// ColorBGRAToBGR555 converts from BGRA (with alpha channel)
	// to BGR555 (16-bit images).
	ColorBGRAToBGR555 = 26

	// ColorRGBAToBGR555 converts from RGBA (with alpha channel)
	// to BGR555 (16-bit images).
	ColorRGBAToBGR555 = 27

	// ColorBGR555ToBGRA converts from BGR555 (16-bit images)
	// to BGRA (with alpha channel).
	ColorBGR555ToBGRA = 28

	// ColorBGR555ToRGBA converts from BGR555 (16-bit images)
	// to RGBA (with alpha channel).
	ColorBGR555ToRGBA = 29

	// ColorGrayToBGR555 converts from grayscale to BGR555 (16-bit images).
	ColorGrayToBGR555 = 30

	// ColorBGR555ToGRAY converts from BGR555 (16-bit images) to grayscale.
	ColorBGR555ToGRAY = 31

	// ColorBGRToXYZ converts from BGR to CIE XYZ.
	ColorBGRToXYZ = 32

	// ColorRGBToXYZ converts from RGB to CIE XYZ.
	ColorRGBToXYZ = 33

	// ColorXYZToBGR converts from CIE XYZ to BGR.
	ColorXYZToBGR = 34

	// ColorXYZToRGB converts from CIE XYZ to RGB.
	ColorXYZToRGB = 35

	// ColorBGRToYCrCb converts from BGR to luma-chroma (aka YCC).
	ColorBGRToYCrCb = 36

	// ColorRGBToYCrCb converts from RGB to luma-chroma (aka YCC).
	ColorRGBToYCrCb = 37

	// ColorYCrCbToBGR converts from luma-chroma (aka YCC) to BGR.
	ColorYCrCbToBGR = 38

	// ColorYCrCbToRGB converts from luma-chroma (aka YCC) to RGB.
	ColorYCrCbToRGB = 39

	// ColorBGRToHSV converts from BGR to HSV (hue saturation value).
	ColorBGRToHSV = 40

	// ColorRGBToHSV converts from RGB to HSV (hue saturation value).
	ColorRGBToHSV = 41

	// ColorBGRToLab converts from BGR to CIE Lab.
	ColorBGRToLab = 44

	// ColorRGBToLab converts from RGB to CIE Lab.
	ColorRGBToLab = 45

	// ColorBGRToLuv converts from BGR to CIE Luv.
	ColorBGRToLuv = 50

	// ColorRGBToLuv converts from RGB to CIE Luv.
	ColorRGBToLuv = 51

	// ColorBGRToHLS converts from BGR to HLS (hue lightness saturation).
	ColorBGRToHLS = 52

	// ColorRGBToHLS converts from RGB to HLS (hue lightness saturation).
	ColorRGBToHLS = 53

	// ColorHSVToBGR converts from HSV (hue saturation value) to BGR.
	ColorHSVToBGR = 54

	// ColorHSVToRGB converts from HSV (hue saturation value) to RGB.
	ColorHSVToRGB = 55

	// ColorLabToBGR converts from CIE Lab to BGR.
	ColorLabToBGR = 56

	// ColorLabToRGB converts from CIE Lab to RGB.
	ColorLabToRGB = 57

	// ColorLuvToBGR converts from CIE Luv to BGR.
	ColorLuvToBGR = 58

	// ColorLuvToRGB converts from CIE Luv to RGB.
	ColorLuvToRGB = 59

	// ColorHLSToBGR converts from HLS (hue lightness saturation) to BGR.
	ColorHLSToBGR = 60

	// ColorHLSToRGB converts from HLS (hue lightness saturation) to RGB.
	ColorHLSToRGB = 61

	// ColorBGRToHSVFull converts from BGR to HSV (hue saturation value) full.
	ColorBGRToHSVFull = 66

	// ColorRGBToHSVFull converts from RGB to HSV (hue saturation value) full.
	ColorRGBToHSVFull = 67

	// ColorBGRToHLSFull converts from BGR to HLS (hue lightness saturation) full.
	ColorBGRToHLSFull = 68

	// ColorRGBToHLSFull converts from RGB to HLS (hue lightness saturation) full.
	ColorRGBToHLSFull = 69

	// ColorHSVToBGRFull converts from HSV (hue saturation value) to BGR full.
	ColorHSVToBGRFull = 70

	// ColorHSVToRGBFull converts from HSV (hue saturation value) to RGB full.
	ColorHSVToRGBFull = 71

	// ColorHLSToBGRFull converts from HLS (hue lightness saturation) to BGR full.
	ColorHLSToBGRFull = 72

	// ColorHLSToRGBFull converts from HLS (hue lightness saturation) to RGB full.
	ColorHLSToRGBFull = 73

	// ColorLBGRToLab converts from LBGR to CIE Lab.
	ColorLBGRToLab = 74

	// ColorLRGBToLab converts from LRGB to CIE Lab.
	ColorLRGBToLab = 75

	// ColorLBGRToLuv converts from LBGR to CIE Luv.
	ColorLBGRToLuv = 76

	// ColorLRGBToLuv converts from LRGB to CIE Luv.
	ColorLRGBToLuv = 77

	// ColorLabToLBGR converts from CIE Lab to LBGR.
	ColorLabToLBGR = 78

	// ColorLabToLRGB converts from CIE Lab to LRGB.
	ColorLabToLRGB = 79

	// ColorLuvToLBGR converts from CIE Luv to LBGR.
	ColorLuvToLBGR = 80

	// ColorLuvToLRGB converts from CIE Luv to LRGB.
	ColorLuvToLRGB = 81

	// ColorBGRToYUV converts from BGR to YUV.
	ColorBGRToYUV = 82

	// ColorRGBToYUV converts from RGB to YUV.
	ColorRGBToYUV = 83

	// ColorYUVToBGR converts from YUV to BGR.
	ColorYUVToBGR = 84

	// ColorYUVToRGB converts from YUV to RGB.
	ColorYUVToRGB = 85

	// ColorYUVToRGBNV12 converts from YUV 4:2:0 to RGB NV12.
	ColorYUVToRGBNV12 = 90

	// ColorYUVToBGRNV12 converts from YUV 4:2:0 to BGR NV12.
	ColorYUVToBGRNV12 = 91

	// ColorYUVToRGBNV21 converts from YUV 4:2:0 to RGB NV21.
	ColorYUVToRGBNV21 = 92

	// ColorYUVToBGRNV21 converts from YUV 4:2:0 to BGR NV21.
	ColorYUVToBGRNV21 = 93

	// ColorYUVToRGBANV12 converts from YUV 4:2:0 to RGBA NV12.
	ColorYUVToRGBANV12 = 94

	// ColorYUVToBGRANV12 converts from YUV 4:2:0 to BGRA NV12.
	ColorYUVToBGRANV12 = 95

	// ColorYUVToRGBANV21 converts from YUV 4:2:0 to RGBA NV21.
	ColorYUVToRGBANV21 = 96

	// ColorYUVToBGRANV21 converts from YUV 4:2:0 to BGRA NV21.
	ColorYUVToBGRANV21 = 97

	ColorYUVToRGBYV12 = 98
	ColorYUVToBGRYV12 = 99
	ColorYUVToRGBIYUV = 100
	ColorYUVToBGRIYUV = 101

	ColorYUVToRGBAYV12 = 102
	ColorYUVToBGRAYV12 = 103
	ColorYUVToRGBAIYUV = 104
	ColorYUVToBGRAIYUV = 105

	ColorYUVToGRAY420 = 106

	// YUV 4:2:2 family to RGB
	ColorYUVToRGBUYVY = 107
	ColorYUVToBGRUYVY = 108

	ColorYUVToRGBAUYVY = 111
	ColorYUVToBGRAUYVY = 112

	ColorYUVToRGBYUY2 = 115
	ColorYUVToBGRYUY2 = 116
	ColorYUVToRGBYVYU = 117
	ColorYUVToBGRYVYU = 118

	ColorYUVToRGBAYUY2 = 119
	ColorYUVToBGRAYUY2 = 120
	ColorYUVToRGBAYVYU = 121
	ColorYUVToBGRAYVYU = 122

	ColorYUVToGRAYUYVY = 123
	ColorYUVToGRAYYUY2 = 124

	// alpha premultiplication
	ColorRGBATomRGBA = 125
	ColormRGBAToRGBA = 126

	// RGB to YUV 4:2:0 family
	ColorRGBToYUVI420 = 127
	ColorBGRToYUVI420 = 128

	ColorRGBAToYUVI420 = 129
	ColorBGRAToYUVI420 = 130
	ColorRGBToYUVYV12  = 131
	ColorBGRToYUVYV12  = 132
	ColorRGBAToYUVYV12 = 133
	ColorBGRAToYUVYV12 = 134

	// Demosaicing
	ColorBayerBGToBGR = 46
	ColorBayerGBToBGR = 47
	ColorBayerRGToBGR = 48
	ColorBayerGRToBGR = 49

	ColorBayerBGToGRAY = 86
	ColorBayerGBToGRAY = 87
	ColorBayerRGToGRAY = 88
	ColorBayerGRToGRAY = 89

	// Demosaicing using Variable Number of Gradients
	ColorBayerBGToBGRVNG = 62
	ColorBayerGBToBGRVNG = 63
	ColorBayerRGToBGRVNG = 64
	ColorBayerGRToBGRVNG = 65

	// Edge-Aware Demosaicing
	ColorBayerBGToBGREA = 135
	ColorBayerGBToBGREA = 136
	ColorBayerRGToBGREA = 137
	ColorBayerGRToBGREA = 138

	// Demosaicing with alpha channel
	ColorBayerBGToBGRA = 139
	ColorBayerGBToBGRA = 140
	ColorBayerRGToBGRA = 141
	ColorBayerGRToBGRA = 142

	ColorCOLORCVTMAX = 143
)
View Source
const (
	// VideoCapturePosMsec contains current position of the
	// video file in milliseconds.
	VideoCapturePosMsec VideoCaptureProperties = 0

	// VideoCapturePosFrames 0-based index of the frame to be
	// decoded/captured next.
	VideoCapturePosFrames = 1

	// VideoCapturePosAVIRatio relative position of the video file:
	// 0=start of the film, 1=end of the film.
	VideoCapturePosAVIRatio = 2

	// VideoCaptureFrameWidth is width of the frames in the video stream.
	VideoCaptureFrameWidth = 3

	// VideoCaptureFrameHeight controls height of frames in the video stream.
	VideoCaptureFrameHeight = 4

	// VideoCaptureFPS controls capture frame rate.
	VideoCaptureFPS = 5

	// VideoCaptureFOURCC contains the 4-character code of codec.
	// see VideoWriter::fourcc for details.
	VideoCaptureFOURCC = 6

	// VideoCaptureFrameCount contains number of frames in the video file.
	VideoCaptureFrameCount = 7

	// VideoCaptureFormat format of the Mat objects returned by
	// VideoCapture::retrieve().
	VideoCaptureFormat = 8

	// VideoCaptureMode contains backend-specific value indicating
	// the current capture mode.
	VideoCaptureMode = 9

	// VideoCaptureBrightness is brightness of the image
	// (only for those cameras that support).
	VideoCaptureBrightness = 10

	// VideoCaptureContrast is contrast of the image
	// (only for cameras that support it).
	VideoCaptureContrast = 11

	// VideoCaptureSaturation saturation of the image
	// (only for cameras that support).
	VideoCaptureSaturation = 12

	// VideoCaptureHue hue of the image (only for cameras that support).
	VideoCaptureHue = 13

	// VideoCaptureGain is the gain of the capture image.
	// (only for those cameras that support).
	VideoCaptureGain = 14

	// VideoCaptureExposure is the exposure of the capture image.
	// (only for those cameras that support).
	VideoCaptureExposure = 15

	// VideoCaptureConvertRGB is a boolean flags indicating whether
	// images should be converted to RGB.
	VideoCaptureConvertRGB = 16

	// VideoCaptureWhiteBalanceBlueU is currently unsupported.
	VideoCaptureWhiteBalanceBlueU = 17

	// VideoCaptureRectification is the rectification flag for stereo cameras.
	// Note: only supported by DC1394 v 2.x backend currently.
	VideoCaptureRectification = 18

	// VideoCaptureMonochrome indicates whether images should be
	// converted to monochrome.
	VideoCaptureMonochrome = 19

	// VideoCaptureSharpness controls image capture sharpness.
	VideoCaptureSharpness = 20

	// VideoCaptureAutoExposure controls the DC1394 exposure control
	// done by camera, user can adjust reference level using this feature.
	VideoCaptureAutoExposure = 21

	// VideoCaptureGamma controls video capture gamma.
	VideoCaptureGamma = 22

	// VideoCaptureTemperature controls video capture temperature.
	VideoCaptureTemperature = 23

	// VideoCaptureTrigger controls video capture trigger.
	VideoCaptureTrigger = 24

	// VideoCaptureTriggerDelay controls video capture trigger delay.
	VideoCaptureTriggerDelay = 25

	// VideoCaptureWhiteBalanceRedV controls video capture setting for
	// white balance.
	VideoCaptureWhiteBalanceRedV = 26

	// VideoCaptureZoom controls video capture zoom.
	VideoCaptureZoom = 27

	// VideoCaptureFocus controls video capture focus.
	VideoCaptureFocus = 28

	// VideoCaptureGUID controls video capture GUID.
	VideoCaptureGUID = 29

	// VideoCaptureISOSpeed controls video capture ISO speed.
	VideoCaptureISOSpeed = 30

	// VideoCaptureBacklight controls video capture backlight.
	VideoCaptureBacklight = 32

	// VideoCapturePan controls video capture pan.
	VideoCapturePan = 33

	// VideoCaptureTilt controls video capture tilt.
	VideoCaptureTilt = 34

	// VideoCaptureRoll controls video capture roll.
	VideoCaptureRoll = 35

	// VideoCaptureIris controls video capture iris.
	VideoCaptureIris = 36

	// VideoCaptureSettings is the pop up video/camera filter dialog. Note:
	// only supported by DSHOW backend currently. The property value is ignored.
	VideoCaptureSettings = 37

	// VideoCaptureBufferSize controls video capture buffer size.
	VideoCaptureBufferSize = 38

	// VideoCaptureAutoFocus controls video capture auto focus..
	VideoCaptureAutoFocus = 39
)
View Source
const GoCVVersion = "0.1.1"

GoCVVersion of this package, for display purposes.

Variables

This section is empty.

Functions

func Blur

func Blur(src Mat, dst Mat, ksize image.Point)

Blur blurs an image Mat using a box filter. The function convolves the src Mat image into the dst Mat using the specified Gaussian kernel params.

For further details, please see: http://docs.opencv.org/3.3.0/d4/d86/group__imgproc__filter.html#gaabe8c836e97159a9193fb0b11ac52cf1

func Canny

func Canny(src Mat, edges Mat, t1 float32, t2 float32)

Canny finds edges in an image using the Canny algorithm. The function finds edges in the input image image and marks them in the output map edges using the Canny algorithm. The smallest value between threshold1 and threshold2 is used for edge linking. The largest value is used to find initial segments of strong edges. See http://en.wikipedia.org/wiki/Canny_edge_detector

For further details, please see: http://docs.opencv.org/3.3.0/dd/d1a/group__imgproc__feature.html#ga04723e007ed888ddf11d9ba04e2232de

func CvtColor

func CvtColor(src Mat, dst Mat, code ColorConversionCode)

CvtColor converts an image from one color space to another. It converts the src Mat image to the dst Mat using the code param containing the desired ColorConversionCode color space.

For further details, please see: http://docs.opencv.org/3.3.0/d7/d1b/group__imgproc__misc.html#ga4e0972be5de079fed4e3a10e24ef5ef0

func GaussianBlur

func GaussianBlur(src Mat, dst Mat, ksize image.Point, sigmaX float64,
	sigmaY float64, borderType int)

GaussianBlur blurs an image Mat using a Gaussian filter. The function convolves the src Mat image into the dst Mat using the specified Gaussian kernel params.

For further details, please see: http://docs.opencv.org/3.3.0/d4/d86/group__imgproc__filter.html#gaabe8c836e97159a9193fb0b11ac52cf1

func GetTextSize

func GetTextSize(text string, fontFace HersheyFont, fontScale float64, thickness int) image.Point

GetTextSize calculates the width and height of a text string. It returns an image.Point with the size required to draw text using a specific font face, scale, and thickness.

For further details, please see: http://docs.opencv.org/3.3.0/d6/d6e/group__imgproc__draw.html#ga3d2abfcb995fd2db908c8288199dba82

func HoughLines

func HoughLines(src Mat, lines Mat, rho float32, theta float32, threshold int)

HoughLines implements the standard or standard multi-scale Hough transform algorithm for line detection. For a good explanation of Hough transform, see: http://homepages.inf.ed.ac.uk/rbf/HIPR2/hough.htm

For further details, please see: http://docs.opencv.org/3.3.0/dd/d1a/group__imgproc__feature.html#ga46b4e588934f6c8dfd509cc6e0e4545a

func HoughLinesP

func HoughLinesP(src Mat, lines Mat, rho float32, theta float32, threshold int)

HoughLinesP implements the probabilistic Hough transform algorithm for line detection. For a good explanation of Hough transform, see: http://homepages.inf.ed.ac.uk/rbf/HIPR2/hough.htm

For further details, please see: http://docs.opencv.org/3.3.0/dd/d1a/group__imgproc__feature.html#ga8618180a5948286384e3b7ca02f6feeb

func IMEncode

func IMEncode(fileExt string, img Mat) (buf []byte, err error)

IMEncode encodes an image Mat into a memory buffer. This function compresses the image and stores it in the returned memory buffer, using the image format passed in in the form of a file extension string.

For further details, please see: http://docs.opencv.org/3.3.0/d4/da8/group__imgcodecs.html#ga461f9ac09887e47797a54567df3b8b63

func IMWrite

func IMWrite(name string, img Mat) bool

IMWrite writes a Mat to an image file.

For further details, please see: http://docs.opencv.org/3.3.0/d4/da8/group__imgcodecs.html#gabbc7ef1aa2edfaa87772f1202d67e0ce

func OpenCVVersion

func OpenCVVersion() string

OpenCVVersion returns the current OpenCV lib version

func PutText

func PutText(img Mat, text string, org image.Point, fontFace HersheyFont, fontScale float64, c color.RGBA, thickness int)

PutText draws a text string. It renders the specified text string into the img Mat at the location passed in the "org" param, using the desired font face, font scale, color, and line thinkness.

For further details, please see: http://docs.opencv.org/3.3.0/d6/d6e/group__imgproc__draw.html#ga5126f47f883d730f633d74f07456c576

func Rectangle

func Rectangle(img Mat, r image.Rectangle, c color.RGBA, thickness int)

Rectangle draws a simple, thick, or filled up-right rectangle. It renders a rectangle with the desired characteristics to the target Mat image.

For further details, please see: http://docs.opencv.org/3.3.0/d6/d6e/group__imgproc__draw.html#ga346ac30b5c74e9b5137576c9ee9e0e8c

func Version

func Version() string

Version returns the current golang package version

func WaitKey

func WaitKey(delay int) int

WaitKey waits for a pressed key. This function is the only method in OpenCV's HighGUI that can fetch and handle events, so it needs to be called periodically for normal event processing

For further details, please see: http://docs.opencv.org/3.3.0/d7/dfc/group__highgui.html#ga5628525ad33f52eab17feebcfba38bd7

Types

type CascadeClassifier

type CascadeClassifier struct {
	// contains filtered or unexported fields
}

CascadeClassifier is a cascade classifier class for object detection.

For further details, please see: http://docs.opencv.org/3.3.0/d1/de5/classcv_1_1CascadeClassifier.html

func NewCascadeClassifier

func NewCascadeClassifier() CascadeClassifier

NewCascadeClassifier returns a new CascadeClassifier.

func (*CascadeClassifier) Close

func (c *CascadeClassifier) Close() error

Close deletes the CascadeClassifier's pointer.

func (*CascadeClassifier) DetectMultiScale

func (c *CascadeClassifier) DetectMultiScale(img Mat) []image.Rectangle

DetectMultiScale detects objects of different sizes in the input Mat image. The detected objects are returned as a slice of image.Rectangle structs.

For further details, please see: http://docs.opencv.org/3.3.0/d1/de5/classcv_1_1CascadeClassifier.html#aaf8181cb63968136476ec4204ffca498

func (*CascadeClassifier) Load

func (c *CascadeClassifier) Load(name string) bool

Load cascade classifier from a file.

For further details, please see: http://docs.opencv.org/3.3.0/d1/de5/classcv_1_1CascadeClassifier.html#a1a5884c8cc749422f9eb77c2471958bc

type ColorConversionCode

type ColorConversionCode int

ColorConversionCode is a color conversion code used on Mat.

For further details, please see: http://docs.opencv.org/3.3.0/d7/d1b/group__imgproc__misc.html#ga4e0972be5de079fed4e3a10e24ef5ef0

type HersheyFont

type HersheyFont int

HersheyFont are the font libraries included in OpenCV. Only a subset of the available Hershey fonts are supported by OpenCV.

For more information, see: http://sources.isc.org/utils/misc/hershey-font.txt

type IMReadFlag

type IMReadFlag int

IMReadFlag is one of the valid flags to use for the IMRead function.

type Mat

type Mat struct {
	// contains filtered or unexported fields
}

Mat represents an n-dimensional dense numerical single-channel or multi-channel array. It can be used to store real or complex-valued vectors and matrices, grayscale or color images, voxel volumes, vector fields, point clouds, tensors, and histograms.

For further details, please see: http://docs.opencv.org/3.3.0/d3/d63/classcv_1_1Mat.html

func IMRead

func IMRead(name string, flags IMReadFlag) Mat

IMRead reads an image from a file into a Mat. The flags param is one of the IMReadFlag flags. If the image cannot be read (because of missing file, improper permissions, unsupported or invalid format), the function returns an empty Mat.

For further details, please see: http://docs.opencv.org/3.3.0/d4/da8/group__imgcodecs.html#ga288b8b3da0892bd651fce07b3bbd3a56

func NewMat

func NewMat() Mat

NewMat returns a new empty Mat.

func NewMatWithSize

func NewMatWithSize(rows int, cols int, mt MatType) Mat

NewMatWithSize returns a new Mat with a specific size and type.

func (*Mat) Clone

func (m *Mat) Clone() Mat

Clone returns a cloned full copy of the Mat.

func (*Mat) Close

func (m *Mat) Close() error

Close the Mat object.

func (*Mat) Cols

func (m *Mat) Cols() int

Cols returns the number of columns for this Mat.

func (*Mat) Empty

func (m *Mat) Empty() bool

Empty determines if the Mat is empty or not.

func (*Mat) GetDoubleAt

func (m *Mat) GetDoubleAt(row int, col int) float64

GetDoubleAt returns a value from a specific row/col in this Mat expecting it to be of type double aka CV_64F.

func (*Mat) GetFloatAt

func (m *Mat) GetFloatAt(row int, col int) float32

GetFloatAt returns a value from a specific row/col in this Mat expecting it to be of type float aka CV_32F.

func (*Mat) GetIntAt

func (m *Mat) GetIntAt(row int, col int) int32

GetIntAt returns a value from a specific row/col in this Mat expecting it to be of type int aka CV_32S.

func (*Mat) GetSCharAt

func (m *Mat) GetSCharAt(row int, col int) int8

GetSCharAt returns a value from a specific row/col in this Mat expecting it to be of type schar aka CV_8S.

func (*Mat) GetShortAt

func (m *Mat) GetShortAt(row int, col int) int16

GetShortAt returns a value from a specific row/col in this Mat expecting it to be of type short aka CV_16S.

func (*Mat) GetUCharAt

func (m *Mat) GetUCharAt(row int, col int) int8

GetUCharAt returns a value from a specific row/col in this Mat expecting it to be of type uchar aka CV_8U.

func (*Mat) Ptr

func (m *Mat) Ptr() C.Mat

Ptr returns the Mat's underlying object pointer.

func (*Mat) Region

func (m *Mat) Region(rio image.Rectangle) Mat

Region returns a new Mat that points to a region of this Mat. Changes made to the region Mat will affect the original Mat, sinec they are pointers to the underlying OpenCV Mat object.

func (*Mat) Rows

func (m *Mat) Rows() int

Rows returns the number of rows for this Mat.

type MatType

type MatType int

MatType is the type for the various different kinds of Mat you can create.

type Scalar

type Scalar struct {
	Val1 float64
	Val2 float64
	Val3 float64
	Val4 float64
}

Scalar is a 4-element vector widely used in OpenCV to pass pixel values.

For further details, please see: http://docs.opencv.org/3.3.0/d1/da0/classcv_1_1Scalar__.html

func NewScalar

func NewScalar(v1 float64, v2 float64, v3 float64, v4 float64) Scalar

NewScalar returns a new Scalar. These are usually colors typically being in BGR order.

type VideoCapture

type VideoCapture struct {
	// contains filtered or unexported fields
}

VideoCapture is a wrapper around the OpenCV VideoCapture class.

For further details, please see: http://docs.opencv.org/3.3.0/d8/dfe/classcv_1_1VideoCapture.html

func VideoCaptureDevice

func VideoCaptureDevice(device int) (vc *VideoCapture, err error)

VideoCaptureDevice opens a VideoCapture from a device and prepares to start capturing.

func VideoCaptureFile

func VideoCaptureFile(uri string) (vc *VideoCapture, err error)

VideoCaptureFile opens a VideoCapture from a file and prepares to start capturing.

func (*VideoCapture) Close

func (v *VideoCapture) Close() error

Close VideoCapture object.

func (*VideoCapture) Grab

func (v *VideoCapture) Grab(skip int)

Grab skips a specific number of frames.

func (*VideoCapture) IsOpened

func (v *VideoCapture) IsOpened() bool

IsOpened returns if the VideoCapture has been opened to read from a file or capture device.

func (*VideoCapture) Read

func (v *VideoCapture) Read(m Mat) bool

Read read the next frame from the VideoCapture to the Mat passed in as the parem. It returns false if the VideoCapture cannot read frame.

func (*VideoCapture) Set

func (v *VideoCapture) Set(prop VideoCaptureProperties, param float64)

Set parameter with property (=key).

type VideoCaptureProperties

type VideoCaptureProperties int

VideoCaptureProperties are the properties used for VideoCapture operations.

type VideoWriter

type VideoWriter struct {
	// contains filtered or unexported fields
}

VideoWriter is a wrapper around the OpenCV VideoWriter`class.

For further details, please see: http://docs.opencv.org/3.3.0/dd/d9e/classcv_1_1VideoWriter.html

func VideoWriterFile

func VideoWriterFile(name string, codec string, fps float64, width int, height int) (vw *VideoWriter, err error)

VideoWriterFile opens a VideoWriter with a specific output file. The "codec" param should be the four-letter code for the desired output codec, for example "MJPG".

For further details, please see: http://docs.opencv.org/3.3.0/dd/d9e/classcv_1_1VideoWriter.html#a0901c353cd5ea05bba455317dab81130

func (*VideoWriter) Close

func (vw *VideoWriter) Close() error

Close VideoWriter object.

func (*VideoWriter) IsOpened

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/3.3.0/dd/d9e/classcv_1_1VideoWriter.html#a9a40803e5f671968ac9efa877c984d75

func (*VideoWriter) Write

func (vw *VideoWriter) Write(img Mat) error

Write the next video frame from the Mat image to the open VideoWriter.

For further details, please see: http://docs.opencv.org/3.3.0/dd/d9e/classcv_1_1VideoWriter.html#a3115b679d612a6a0b5864a0c88ed4b39

type Window

type Window struct {
	// contains filtered or unexported fields
}

Window is a wrapper around OpenCV's "HighGUI" named windows. While OpenCV was designed for use in full-scale applications and can be used within functionally rich UI frameworks (such as Qt*, WinForms*, or Cocoa*) or without any UI at all, sometimes there it is required to try functionality quickly and visualize the results. This is what the HighGUI module has been designed for.

For further details, please see: http://docs.opencv.org/3.3.0/d7/dfc/group__highgui.html

func NewWindow

func NewWindow(name string) *Window

NewWindow creates a new named OpenCV window

For further details, please see: http://docs.opencv.org/3.3.0/d7/dfc/group__highgui.html#ga5afdf8410934fd099df85c75b2e0888b

func (*Window) Close

func (w *Window) Close() error

Close closes and deletes a named OpenCV Window.

For further details, please see: http://docs.opencv.org/3.3.0/d7/dfc/group__highgui.html#ga851ccdd6961022d1d5b4c4f255dbab34

func (*Window) IMShow

func (w *Window) IMShow(img Mat)

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.

For further details, please see: http://docs.opencv.org/3.3.0/d7/dfc/group__highgui.html#ga453d42fe4cb60e5723281a89973ee563

func (*Window) IsOpen

func (w *Window) IsOpen() bool

IsOpen checks to see if the Window seems to be open.

Directories

Path Synopsis
Package pvl is the GoCV wrapper around the Intel Computer Vision (CV) SDK's Photography Vision Library (PVL).
Package pvl is the GoCV wrapper around the Intel Computer Vision (CV) SDK's Photography Vision Library (PVL).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL