Skip to content

Instantly share code, notes, and snippets.

@grocky
Created June 13, 2020 08:02
Show Gist options
  • Save grocky/61f1276e353a5705d9964338a206e2b5 to your computer and use it in GitHub Desktop.
Save grocky/61f1276e353a5705d9964338a206e2b5 to your computer and use it in GitHub Desktop.
mouse-detective
func processResults(results <-chan result) {
for r := range results {
if r.err != nil {
log.Printf("Frame result with an error: %v\n", r.err)
continue
}
log.Printf("Mouse detected! frame: %d, detectors: %v\n", r.frame, r.detectors)
image, err := jpeg.Decode(r.file)
if err != nil {
log.Printf("Unable to decode image: %v", err)
continue
}
imgCtx := gg.NewContextForImage(image)
green := color.RGBA{50, 205, 50, 255}
imgCtx.SetColor(color.Transparent)
imgCtx.SetStrokeStyle(gg.NewSolidPattern(green))
imgCtx.SetLineWidth(1)
for _, d := range r.detectors {
left := float64(d.Objects[0].Rect.Left)
top := float64(d.Objects[0].Rect.Top)
width := float64(d.Objects[0].Rect.Width)
height := float64(d.Objects[0].Rect.Height)
imgCtx.DrawRectangle(left, top, width, height)
imgCtx.Stroke()
}
cleanedFilename := strings.ReplaceAll(filenameF, "/", "-")
frameFile := path.Join(outputDirF, Version+"-"+cleanedFilename+"-"+strconv.Itoa(r.frame)+".jpg")
err = gg.SaveJPG(frameFile, imgCtx.Image(), 100)
if err != nil {
log.Printf("Unable to create image: %v\n", err)
continue
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment