First, we'll open a connection to the webcam:
``` func main() { // open webcam webcam, err := gocv.VideoCaptureDevice(0) if err != nil { log.Fatal(err) } defer webcam.Close() } ```
Here, I used VideoCaptureDevice(0) because, on my computer, which runs Ubuntu, the webcam is device 0. Your webcam may differ in device numbering. Also, do note defer webcam.Close(). This is the aforementioned resource metaphor that GoCV sticks very strongly to. A webcam (specifically, a VideoCaptureDevice) is a resource, much like a file. In fact in Linux, this is true; the webcam on my computer is mounted in the /dev/video0 directory and I can access raw bytes from it by just using a variant of cat. But I digress. The point ...