core: replacing custom sorting function with sort.Slice

This commit is contained in:
esimov
2022-09-30 09:47:38 +03:00
parent 10ce5702a4
commit c5ba41ea1e

View File

@@ -261,7 +261,9 @@ func (pg *Pigo) RunCascade(cp CascadeParams, angle float64) []Detection {
// We need to make this comparison to filter out multiple face detection regions.
func (pg *Pigo) ClusterDetections(detections []Detection, iouThreshold float64) []Detection {
// Sort detections by their score
sort.Sort(det(detections))
sort.Slice(detections, func(i, j int) bool {
return detections[i].Q < detections[j].Q
})
calcIoU := func(det1, det2 Detection) float64 {
// Unpack the position and size of each detection.
@@ -304,12 +306,3 @@ func (pg *Pigo) ClusterDetections(detections []Detection, iouThreshold float64)
}
return clusters
}
// Implement sorting function on detection values.
type det []Detection
func (q det) Len() int { return len(q) }
func (q det) Swap(i, j int) { q[i], q[j] = q[j], q[i] }
func (q det) Less(i, j int) bool {
return q[i].Q < q[j].Q
}