How to stream video capture to web

I’ve the below code that read the cam and display it in GUI window, I want to push the same thing to my server at url localhost:8080/cam, how can I do this?

package main

import (
	"gocv.io/x/gocv"
)

func main() {
	webcam, _ := gocv.VideoCaptureDevice(0)
	defer webcam.Close() // Close the cam once execution completed
	window := gocv.NewWindow("Hello")
	defer window.Close() // Close the GUI once execution completed, though it is done automatically
	img := gocv.NewMat()
	defer img.Close() // Close the img once execution completed

	for {
		webcam.Read(&img)
		window.IMShow(img)
        // Want to do streaming here to localhost:8080/cam
		if window.WaitKey(1) == 27 { // 27 => Esc
			break
		}
	}
}

That same project has a https://github.com/hybridgroup/mjpeg project and https://github.com/hybridgroup/gocv/tree/release/cmd/mjpeg-streamer which demonstrate how to make an mjpeg stream.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.