Skip to content

Instantly share code, notes, and snippets.

@grocky
Created June 13, 2020 07:58
Show Gist options
  • Save grocky/0ae27a636032781944e07b6f8b3a66bc to your computer and use it in GitHub Desktop.
Save grocky/0ae27a636032781944e07b6f8b3a66bc to your computer and use it in GitHub Desktop.
mouse-detective
func extractFrames(done <-chan struct{}, filename string) (<-chan frame, <-chan error) {
framec := make(chan frame)
errc := make(chan error, 1)
go func() {
defer close(framec)
video, err := gocv.VideoCaptureFile(filename)
if err != nil {
errc <- err
return
}
frameMat := gocv.NewMat()
errc <- func() error {
n := 1
for {
if !video.Read(&frameMat) {
return &endOfFile{n}
}
buf, err := gocv.IMEncode(gocv.JPEGFileExt, frameMat)
if err != nil {
return err
}
select {
case framec <- frame{n, buf}:
case <-done:
return errors.New("Frame extraction canceled")
}
n++
}
}()
}()
return framec, errc
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment