Skip to content

Instantly share code, notes, and snippets.

@Niraj-Fonseka
Created July 29, 2019 03:38
Show Gist options
  • Save Niraj-Fonseka/3265e94d9a163b59edc3facecf46f568 to your computer and use it in GitHub Desktop.
Save Niraj-Fonseka/3265e94d9a163b59edc3facecf46f568 to your computer and use it in GitHub Desktop.
gocv.go
package main
import (
"log"
"gocv.io/x/gocv"
)
func main() {
webcam, err := gocv.VideoCaptureDevice(0)
if err != nil {
log.Fatalf("error opening device: %v", err)
}
defer webcam.Close()
img := gocv.NewMat()
defer img.Close()
window := gocv.NewWindow("webcamwindow")
defer window.Close()
for {
if ok := webcam.Read(&img); !ok || img.Empty() {
log.Println("Unable to read from the webcam")
continue
}
window.IMShow(img)
window.WaitKey(50)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment