diff --git a/examples/talk_detector/talkdet.go b/examples/talk_detector/talkdet.go index 268907d..f5e6756 100644 --- a/examples/talk_detector/talkdet.go +++ b/examples/talk_detector/talkdet.go @@ -112,7 +112,7 @@ func FindFaces(pixels []uint8) uintptr { dist1 := math.Sqrt(math.Pow(float64(p2.y-p1.y), 2) + math.Pow(float64(p2.x-p1.x), 2)) dist2 := math.Sqrt(math.Pow(float64(p4.y-p3.y), 2) + math.Pow(float64(p4.x-p3.x), 2)) - mar := int(math.Round((dist1 / dist2) * 0.19)) + mar := int(round((dist1 / dist2) * 0.19)) dets[i] = append(dets[i], flp.Row, flp.Col, int(flp.Scale), int(results[i].Q), 3, mar) } @@ -200,3 +200,12 @@ func clusterDetection(pixels []uint8, rows, cols int) []pigo.Detection { return dets } + +// round returns the nearest integer, rounding ties away from zero. +func round(x float64) float64 { + t := math.Trunc(x) + if math.Abs(x-t) >= 0.5 { + return t + math.Copysign(1, x) + } + return t +}