Files
gocv/examples/saveimage.go
deadprogram 3dddcbe528 Can save an image from Mat to disk
Signed-off-by: deadprogram <ron@hybridgroup.com>
2017-09-22 20:32:49 +02:00

43 lines
754 B
Go

// +build example
//
// Do not build by default.
//
// This example uses the VideoCapture class to capture a frame from a connected webcam,
// then save it to a file on disk
//
// how to run:
// go run ./examples/saveimage.go filename.jpg
//
package main
import (
"fmt"
"os"
opencv3 ".."
)
func main() {
deviceID := 0
webcam := opencv3.NewVideoCapture()
defer webcam.Delete()
if ok := webcam.OpenDevice(int(deviceID)); !ok {
fmt.Printf("error opening device: %v\n", deviceID)
}
img := opencv3.NewMat()
defer img.Delete()
if ok := webcam.Read(img); !ok {
fmt.Printf("cannot read device %d\n", deviceID)
return
}
if img.Empty() {
fmt.Printf("no image on device %d\n", deviceID)
return
}
opencv3.IMWrite(os.Args[1], img)
}