Skip to content

Instantly share code, notes, and snippets.

@matryer
Created January 16, 2018 13:22
Show Gist options
  • Save matryer/0395b2ad2bbf56d65fa3a09bd50e7206 to your computer and use it in GitHub Desktop.
Save matryer/0395b2ad2bbf56d65fa3a09bd50e7206 to your computer and use it in GitHub Desktop.
Anonymise images using rectangles obtained by facial detection provided by Facebox (by machinebox.io)
// anonymise produces a new image with faces redacted.
// see https://becominghuman.ai/anonymising-images-with-go-and-machine-box-fd0866adb9f5
func anonymise(src image.Image, faces []facebox.Face) image.Image {
dstImage := image.NewRGBA(src.Bounds())
draw.Draw(dstImage, src.Bounds(), src, image.ZP, draw.Src)
for _, face := range faces {
faceRect := image.Rect(
face.Rect.Left,
face.Rect.Top,
face.Rect.Left+face.Rect.Width,
face.Rect.Top+face.Rect.Height,
)
facePos := image.Pt(face.Rect.Left, face.Rect.Top)
draw.Draw(
dstImage,
faceRect,
&image.Uniform{color.Black},
facePos,
draw.Src)
}
return dstImage
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment