Skip to content

Commit

Permalink
add example/fillskinpixels.
Browse files Browse the repository at this point in the history
  • Loading branch information
koyachi committed May 9, 2014
1 parent b95348e commit fd53661
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions example/fillskinpixels/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package main

import (
"../../"
"fmt"
"image"
"image/color"
"image/draw"
"image/jpeg"
"log"
"os"
"path/filepath"
)

func fillSkinPixels(imagePath string, regions nude.Regions) {
path, err := filepath.Abs(imagePath)
if err != nil {
log.Fatal(err)
}

img, err := nude.DecodeImage(path)
dstImg := image.NewRGBA(img.Bounds())
draw.Draw(dstImg, img.Bounds(), img, image.ZP, draw.Src)

for i := 0; i < len(regions); i++ {
blue := color.RGBA{0, 0, 255, 255}
for _, pixel := range regions[i] {
dstImg.Set(pixel.X, pixel.Y, blue)
}
}

path, err = filepath.Abs("result.jpg")
if err != nil {
log.Fatal(err)
}

file, err := os.Create(path)
if err != nil {
log.Fatal(err)
}
err = jpeg.Encode(file, dstImg, nil)
if err != nil {
log.Fatal(err)
}
}

func main() {
imagePath := "../images/damita.jpg"
//imagePath := "../images/damita2.jpg"
//imagePath := "../images/test2.jpg"
//imagePath := "../images/test6.jpg"

d := nude.NewDetector(imagePath)
isNude, err := d.Parse()
if err != nil {
log.Fatal(err)
}
fmt.Printf("isNude = %v\n", isNude)
fmt.Printf("%s\n", d)
fillSkinPixels(imagePath, d.SkinRegions)
}
Binary file added example/fillskinpixels/result.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit fd53661

Please sign in to comment.