Created
January 16, 2018 13:22
-
-
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)
This file contains hidden or 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
// 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