opencv

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2018 License: Apache-2.0, Apache-2.0 Imports: 5 Imported by: 0

README

OpenCV

OpenCV (Open Source Computer Vision Library) is an open source computer vision and machine learning software library. OpenCV was built to provide a common infrastructure for computer vision applications and to accelerate the use of machine perception in the commercial products. Being a BSD-licensed product, OpenCV makes it easy for businesses to utilize and modify the code.

For more info about OpenCV click here

How to Install

This package requires OpenCV version 3.4 be installed on your system, along with GoCV, which is the Go programming language wrapper used by Gobot. The best way is to follow the installation instructions on the GoCV website at https://gocv.io.

macOS

To install on macOS follow the instructions here:

https://gocv.io/getting-started/macos/

Ubuntu

To install on Ubuntu follow the instructions here:

https://gocv.io/getting-started/linux/

Windows

To install on Windows follow the instructions here:

https://gocv.io/getting-started/windows/

Now you can install the Gobot package itself with

go get -d -u gobot.io/x/gobot/...

How to Use

When you run code that uses OpenCV, you must setup some environment variables first. The best way to do this, is to first run the env.sh script that comes with GoCV, like this:

source $GOPATH/src/gocv.io/x/gocv/env.sh

Once you have run this script you can use go run or go build on your Gobot code that uses OpenCV as you normally would.

Here is an example using the camera:

package main

import (
	"gobot.io/x/gobot"
	"gobot.io/x/gobot/platforms/opencv"
	"gocv.io/x/gocv"
)

func main() {
	window := opencv.NewWindowDriver()
	camera := opencv.NewCameraDriver(0)

	work := func() {
		camera.On(opencv.Frame, func(data interface{}) {
			img := data.(gocv.Mat)
			window.ShowImage(img)
			window.WaitKey(1)
		})
	}

	robot := gobot.NewRobot("cameraBot",
		[]gobot.Device{window, camera},
		work,
	)

	robot.Start()
}

Documentation

Overview

Package opencv contains the Gobot drivers for opencv.

Installing:

This package requires `opencv` to be installed on your system

Then you can install the package with:

go get gobot.io/x/gobot && go install gobot.io/x/gobot/platforms/opencv

Example:

package main

import (
	cv "gobot.io/x/go-opencv/opencv"
	"gobot.io/x/gobot"
	"gobot.io/x/gobot/platforms/opencv"
)

func main() {
	window := opencv.NewWindowDriver()
	camera := opencv.NewCameraDriver(0)

	work := func() {
		camera.On(camera.Event("frame"), func(data interface{}) {
			window.ShowImage(data.(*cv.IplImage))
		})
	}

	robot := gobot.NewRobot("cameraBot",
		[]gobot.Device{window, camera},
		work,
	)

	robot.Start()
}

For further information refer to opencv README: https://github.com/hybridgroup/gobot/blob/master/platforms/opencv/README.md

Index

Constants

View Source
const (
	// Frame event
	Frame = "frame"
)

Variables

This section is empty.

Functions

func DetectObjects added in v1.7.0

func DetectObjects(haar string, img gocv.Mat) []image.Rectangle

DetectObjects loads Haar cascade to detect face objects in image

func DrawRectangles

func DrawRectangles(img gocv.Mat, rects []image.Rectangle, r int, g int, b int, thickness int)

DrawRectangles uses Rect array values to return image with rectangles drawn.

Types

type CameraDriver

type CameraDriver struct {
	Source interface{}

	gobot.Eventer
	// contains filtered or unexported fields
}

CameraDriver is the Gobot Driver for the OpenCV camera

func NewCameraDriver

func NewCameraDriver(source interface{}) *CameraDriver

NewCameraDriver creates a new driver with specified source. It also creates a start function to either set camera as a File or Camera capture.

func (*CameraDriver) Connection

func (c *CameraDriver) Connection() gobot.Connection

Connection returns the Driver's connection

func (*CameraDriver) Halt

func (c *CameraDriver) Halt() (err error)

Halt stops camera driver

func (*CameraDriver) Name

func (c *CameraDriver) Name() string

Name returns the Driver name

func (*CameraDriver) SetName added in v1.0.0

func (c *CameraDriver) SetName(n string)

SetName sets the Driver name

func (*CameraDriver) Start

func (c *CameraDriver) Start() (err error)

Start initializes camera by grabbing frames

type WindowDriver

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

WindowDriver is the Gobot Driver for the OpenCV window

func NewWindowDriver

func NewWindowDriver() *WindowDriver

NewWindowDriver creates a new window driver. It adds an start function to initialize window

func (*WindowDriver) Connection

func (w *WindowDriver) Connection() gobot.Connection

Connection returns the Driver's connection

func (*WindowDriver) Halt

func (w *WindowDriver) Halt() (err error)

Halt returns true if camera is halted successfully

func (*WindowDriver) Name

func (w *WindowDriver) Name() string

Name returns the Driver name

func (*WindowDriver) SetName added in v1.0.0

func (w *WindowDriver) SetName(n string)

SetName sets the Driver name

func (*WindowDriver) ShowImage

func (w *WindowDriver) ShowImage(img gocv.Mat)

ShowImage displays image in window

func (*WindowDriver) Start

func (w *WindowDriver) Start() (err error)

Start starts window thread and driver

func (*WindowDriver) WaitKey added in v1.7.0

func (w *WindowDriver) WaitKey(pause int) int

WaitKey gives window a chance to redraw, and checks for keyboard input

Jump to

Keyboard shortcuts

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