2014-06-10 10:01:53 +08:00
|
|
|
# OpenCV
|
2014-04-26 18:11:51 +08:00
|
|
|
|
2023-06-05 00:36:55 +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
|
|
|
|
2023-06-05 00:36:55 +08:00
|
|
|
This package requires OpenCV 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](https://gocv.io).
|
2019-01-21 02:51:00 +08:00
|
|
|
|
|
|
|
The instructions should automatically install OpenCV 4+
|
2014-06-10 10:01:53 +08:00
|
|
|
|
2018-02-14 23:47:49 +08:00
|
|
|
### macOS
|
2014-06-10 10:01:53 +08:00
|
|
|
|
2018-02-14 23:47:49 +08:00
|
|
|
To install on macOS follow the instructions here:
|
2014-04-26 18:11:51 +08:00
|
|
|
|
2023-06-05 00:36:55 +08:00
|
|
|
<https://gocv.io/getting-started/macos/>
|
2014-06-10 10:01:53 +08:00
|
|
|
|
|
|
|
### Ubuntu
|
|
|
|
|
2018-02-14 23:47:49 +08:00
|
|
|
To install on Ubuntu follow the instructions here:
|
2016-02-20 10:36:33 +08:00
|
|
|
|
2023-06-05 00:36:55 +08:00
|
|
|
<https://gocv.io/getting-started/linux/>
|
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
|
|
|
|
2023-06-05 00:36:55 +08:00
|
|
|
Please refer to the main [README.md](https://github.com/hybridgroup/gobot/blob/release/README.md)
|
2014-06-10 10:01:53 +08:00
|
|
|
|
2023-06-05 00:36:55 +08:00
|
|
|
To install on Windows follow the instructions here:
|
2018-02-14 23:47:49 +08:00
|
|
|
|
2023-06-05 00:36:55 +08:00
|
|
|
<https://gocv.io/getting-started/windows/>
|
2014-04-26 18:11:51 +08:00
|
|
|
|
2014-11-29 07:34:42 +08:00
|
|
|
## How to Use
|
|
|
|
|
2018-02-14 23:47:49 +08:00
|
|
|
Here is an example using the camera:
|
2014-11-29 07:34:42 +08:00
|
|
|
|
2014-04-26 18:11:51 +08:00
|
|
|
```go
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2023-06-05 00:36:55 +08:00
|
|
|
"gobot.io/x/gobot/v2"
|
|
|
|
"gobot.io/x/gobot/v2/platforms/opencv"
|
|
|
|
"gocv.io/x/gocv"
|
2014-04-26 18:11:51 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2023-06-05 00:36:55 +08:00
|
|
|
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()
|
2014-04-26 18:11:51 +08:00
|
|
|
}
|
|
|
|
```
|