From fd1f81c6e722ef224623d381bd6ea6a49b490755 Mon Sep 17 00:00:00 2001 From: Martyn Date: Fri, 17 Dec 2021 22:38:57 +0100 Subject: [PATCH] Renamed for potential other options later --- pkg/gocvwebcam/gocvwebcam.go | 56 ++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/pkg/gocvwebcam/gocvwebcam.go b/pkg/gocvwebcam/gocvwebcam.go index cd11a1f..eaf30b7 100644 --- a/pkg/gocvwebcam/gocvwebcam.go +++ b/pkg/gocvwebcam/gocvwebcam.go @@ -1,4 +1,4 @@ -package webcam +package gocvwebcam import ( "image" @@ -11,82 +11,82 @@ import ( "gocv.io/x/gocv" ) -var _ fyne.WidgetRenderer = (*webcamRenderer)(nil) +var _ fyne.WidgetRenderer = (*gocvGocvWebcamRenderer)(nil) -type Webcam struct { +type GocvWebcam struct { widget.BaseWidget - WebcamID int64 - UpdateFPS int64 - fpsTimer *time.Ticker + GocvWebcamID int64 + UpdateFPS int64 + fpsTimer *time.Ticker } -func NewWebcam() *Webcam { - w := &Webcam{} +func NewGocvWebcam() *GocvWebcam { + w := &GocvWebcam{} w.ExtendBaseWidget(w) - w.WebcamID = 0 + w.GocvWebcamID = 0 w.UpdateFPS = 25 return w } -func (w *Webcam) Resize(s fyne.Size) { +func (w *GocvWebcam) Resize(s fyne.Size) { w.BaseWidget.Resize(s) } -func (w *Webcam) CreateRenderer() fyne.WidgetRenderer { +func (w *GocvWebcam) CreateRenderer() fyne.WidgetRenderer { fpsTimer := time.NewTicker(time.Duration(1000/25) * time.Millisecond) - go func(w *Webcam) { + go func(w *GocvWebcam) { for { _ = <-fpsTimer.C w.Refresh() } }(w) - return newWebcamRenderer(w) + return newGocvWebcamRenderer(w) } -type webcamRenderer struct { - webcam *Webcam +type gocvGocvWebcamRenderer struct { + gocvGocvWebcam *GocvWebcam background *canvas.Rectangle currentframe *canvas.Raster goCVVideoCapture *gocv.VideoCapture } -func (r *webcamRenderer) actualrenderframe(w, h int) image.Image { - webcam, _ := gocv.VideoCaptureDevice(int(r.webcam.WebcamID)) +func (r *gocvGocvWebcamRenderer) actualrenderframe(w, h int) image.Image { + gocvGocvWebcam, _ := gocv.VideoCaptureDevice(int(r.gocvGocvWebcam.GocvWebcamID)) img := gocv.NewMat() - webcam.Read(&img) + gocvGocvWebcam.Read(&img) frameImage, _ := img.ToImage() //no point doing anything other than returning anyway! return frameImage } -func newWebcamRenderer(w *Webcam) *webcamRenderer { - renderer := &webcamRenderer{ - webcam: w, - background: canvas.NewRectangle(color.RGBA{255, 0, 255, 255}), +func newGocvWebcamRenderer(w *GocvWebcam) *gocvGocvWebcamRenderer { + renderer := &gocvGocvWebcamRenderer{ + gocvGocvWebcam: w, + background: canvas.NewRectangle(color.RGBA{255, 0, 255, 255}), } renderer.currentframe = canvas.NewRaster(renderer.actualrenderframe) return renderer } -func (r *webcamRenderer) Objects() []fyne.CanvasObject { +func (r *gocvGocvWebcamRenderer) Objects() []fyne.CanvasObject { // The order is critical, rect is drawn first then currentframe return []fyne.CanvasObject{r.background, r.currentframe} } -func (r *webcamRenderer) Layout(s fyne.Size) { +func (r *gocvGocvWebcamRenderer) Layout(s fyne.Size) { r.background.Resize(s) r.currentframe.Resize(s) } -func (r *webcamRenderer) MinSize() fyne.Size { +func (r *gocvGocvWebcamRenderer) MinSize() fyne.Size { return fyne.NewSize(200, 200) } -func (r *webcamRenderer) Refresh() { +func (r *gocvGocvWebcamRenderer) Refresh() { r.currentframe.Refresh() } -func (r *webcamRenderer) Destroy() { - r.webcam.fpsTimer.Stop() +func (r *gocvGocvWebcamRenderer) Destroy() { + r.gocvGocvWebcam.fpsTimer.Stop() } // Called when the renderer is destroyed