Skip to content

Commit

Permalink
fix skinRateInBoundingPolygon()
Browse files Browse the repository at this point in the history
  • Loading branch information
koyachi committed May 12, 2014
1 parent 419ea82 commit a94e10b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
1 change: 1 addition & 0 deletions nude.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ func (d *Detector) analyzeRegions() bool {
if totalSkinParcentage < 30 {
for i, region := range d.SkinRegions {
skinRate := region.skinRateInBoundingPolygon()
fmt.Printf("skinRate[%v] = %v\n", i, skinRate)
if skinRate < 0.55 {
d.message = fmt.Sprintf("region[%d].skinRate(%v) < 0.55", i, skinRate)
d.result = false
Expand Down
35 changes: 27 additions & 8 deletions region.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ type Pixel struct {
// TODO: cache caluculated leftMost, rightMost, upperMost, lowerMost.
type Region []*Pixel

// TODO: optimize
func (r Region) isSkin(x, y int) bool {
for _, pixel := range r {
if pixel.isSkin && pixel.X == x && pixel.Y == y {
return true
}
}
return false
}

func (r Region) leftMost() *Pixel {
minX := 1000000
index := 0
Expand Down Expand Up @@ -71,6 +81,7 @@ func (r Region) skinRateInBoundingPolygon() float64 {
var w int
var h int
var inclination float64

// left-upper
w = upper.X - left.X
h = left.Y - upper.Y
Expand All @@ -79,9 +90,11 @@ func (r Region) skinRateInBoundingPolygon() float64 {
xx := float64(y) / inclination
for x := left.X; x < upper.X; x++ {
if float64(x) >= xx {
skin = skin + 1
if r.isSkin(x, y) {
skin = skin + 1
}
total = total + 1
}
total = total + 1
}
}
// upper-right
Expand All @@ -92,9 +105,11 @@ func (r Region) skinRateInBoundingPolygon() float64 {
xx := float64(y) / inclination
for x := upper.X; x < right.X; x++ {
if float64(x) <= xx {
skin = skin + 1
if r.isSkin(x, y) {
skin = skin + 1
}
total = total + 1
}
total = total + 1
}
}
// left-lower
Expand All @@ -105,9 +120,11 @@ func (r Region) skinRateInBoundingPolygon() float64 {
xx := float64(y) / inclination
for x := left.X; x < lower.X; x++ {
if float64(x) >= xx {
skin = skin + 1
if r.isSkin(x, y) {
skin = skin + 1
}
total = total + 1
}
total = total + 1
}
}
// lower-right
Expand All @@ -118,9 +135,11 @@ func (r Region) skinRateInBoundingPolygon() float64 {
xx := float64(y) / inclination
for x := lower.X; x < right.X; x++ {
if float64(x) <= xx {
skin = skin + 1
if r.isSkin(x, y) {
skin = skin + 1
}
total = total + 1
}
total = total + 1
}
}

Expand Down

0 comments on commit a94e10b

Please sign in to comment.