Created
June 13, 2020 07:58
-
-
Save grocky/0ae27a636032781944e07b6f8b3a66bc to your computer and use it in GitHub Desktop.
mouse-detective
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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