core
core copied to clipboard
Which widget should be used?
Describe the feature
I want to use Gocv to capture video from a USB camera. Which widget should I use to display this?
- Gocv https://github.com/hybridgroup/gocv
Relevant code
Thanks for asking about this. You could try to use the video widget, or you could just use gocv's builtin interface. I would have to take a closer look to see which of those approaches would work the best.
Thank you for answering my question. I am try to use the video widget,but failed. so i am using the image widget. However, there are two problems: the window cannot automatically adjust to the camera's resolution, and it cannot fill the entire image widget and cpu usage is very high.
package main
import (
"fmt"
"cogentcore.org/core/base/errors"
"cogentcore.org/core/core"
"cogentcore.org/core/styles"
"gocv.io/x/gocv"
)
func main() {
var webcam *gocv.VideoCapture
var err error
b := core.NewBody()
img := core.NewImage(b)
img.Styler(func(s *styles.Style) {
s.Grow.Set(1, 1)
})
webcam, err = gocv.VideoCaptureDevice(0)
if err != nil {
fmt.Printf("err: %#v", err)
}
fmt.Printf("gocv version: %s\n", gocv.Version())
fmt.Printf("opencv lib version: %s\n", gocv.OpenCVVersion())
imgcamer := gocv.NewMat()
go func() {
for {
webcam.Read(&imgcamer)
// rotated_180 = gocv.rotate(img, cv2.ROTATE_180)
success := gocv.IMWrite("temp.png", imgcamer)
if !success {
fmt.Printf("gocv.IMWrite error")
}
errors.Log(img.Open("temp.png"))
img.Update()
}
}()
b.RunMainWindow()
}