2014-06-10 10:01:53 +08:00
# OpenCV
2014-04-26 18:11:51 +08:00
2014-11-29 07:34:42 +08:00
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.
2014-04-26 18:11:51 +08:00
2014-11-29 07:34:42 +08:00
For more info about OpenCV click [here ](http://opencv.org/ )
## How to Install
2014-04-26 18:11:51 +08:00
2016-02-20 10:36:33 +08:00
This package requires OpenCV version 2.4 to be installed on your system. Please note that it is not compatible with OpenCV 3.x at this time.
2014-06-10 10:01:53 +08:00
### OSX
2016-02-20 10:36:33 +08:00
To install OpenCV on OSX using Homebrew:
2014-04-26 18:11:51 +08:00
```
2014-07-07 03:17:10 +08:00
$ brew tap homebrew/science & & brew install opencv
2014-06-10 10:01:53 +08:00
```
### Ubuntu
2016-02-20 10:36:33 +08:00
To install OpenCV on Ubuntu 14.04:
```
$ sudo apt-get install libopencv-dev
```
Or, follow the official [OpenCV installation guide ](http://docs.opencv.org/doc/tutorials/introduction/linux_install/linux_install.html )
2014-06-10 10:01:53 +08:00
2014-07-07 03:17:10 +08:00
### Windows
2014-06-10 10:01:53 +08:00
Follow the official [OpenCV installation guide ](http://docs.opencv.org/doc/tutorials/introduction/windows_install/windows_install.html#windows-installation )
2014-07-07 03:17:10 +08:00
Now you can install the package with
2014-06-10 10:01:53 +08:00
```
2016-12-08 20:24:03 +08:00
go get -d -u gobot.io/x/gobot/... & & go install gobot.io/x/gobot/platforms/opencv
2014-04-26 18:11:51 +08:00
```
2014-11-29 07:34:42 +08:00
## How to Use
Example using the camera.
2014-04-26 18:11:51 +08:00
```go
package main
import (
2016-02-20 10:36:33 +08:00
cv "github.com/lazywei/go-opencv/opencv"
2016-12-08 20:24:03 +08:00
"gobot.io/x/gobot"
"gobot.io/x/gobot/platforms/opencv"
2014-04-26 18:11:51 +08:00
)
func main() {
2016-10-01 23:53:39 +08:00
window := opencv.NewWindowDriver()
camera := opencv.NewCameraDriver(0)
2014-04-26 18:11:51 +08:00
work := func() {
2016-10-01 23:53:39 +08:00
camera.On(camera.Event("frame"), func(data interface{}) {
2014-06-10 10:01:53 +08:00
window.ShowImage(data.(*cv.IplImage))
2014-04-26 18:11:51 +08:00
})
}
2014-07-11 08:02:00 +08:00
robot := gobot.NewRobot("cameraBot",
[]gobot.Device{window, camera},
work,
)
2016-10-19 03:37:10 +08:00
robot.Start()
2014-04-26 18:11:51 +08:00
}
```