Parse the cascade file only once

This commit is contained in:
Endre Simo
2019-02-07 06:38:25 +02:00
parent 747334f841
commit 875db60187

View File

@@ -41,7 +41,7 @@ var (
cascadeFile = flag.String("cf", "", "Cascade binary file")
minSize = flag.Int("min", 20, "Minimum size of face")
maxSize = flag.Int("max", 1000, "Maximum size of face")
shiftFactor = flag.Float64("shift", 0.1, "Shift detection window by percentage")
shiftFactor = flag.Float64("shift", 0.15, "Shift detection window by percentage")
scaleFactor = flag.Float64("scale", 1.1, "Scale detection window by percentage")
angle = flag.Float64("angle", 0.0, "0.0 is 0 radians and 1.0 is 2*pi radians")
iouThreshold = flag.Float64("iou", 0.2, "Intersection over union (IoU) threshold")
@@ -84,6 +84,14 @@ func webcam(w http.ResponseWriter, r *http.Request) {
log.Fatalf("Error reading the cascade file: %v", err)
}
p := pigo.NewPigo()
// Unpack the binary file. This will return the number of cascade trees,
// the tree depth, the threshold and the prediction from tree's leaf nodes.
classifier, err := p.Unpack(cascadeFile)
if err != nil {
log.Fatalf("Error reading the cascade file: %s", err)
}
mpart := multipart.NewReader(stdout, boundary)
for {
p, err := mpart.NextPart()
@@ -128,14 +136,6 @@ func webcam(w http.ResponseWriter, r *http.Request) {
},
}
pigo := pigo.NewPigo()
// Unpack the binary file. This will return the number of cascade trees,
// the tree depth, the threshold and the prediction from tree's leaf nodes.
classifier, err := pigo.Unpack(cascadeFile)
if err != nil {
log.Fatalf("Error reading the cascade file: %s", err)
}
// Run the classifier over the obtained leaf nodes and return the detection results.
// The result contains quadruplets representing the row, column, scale and detection score.
dets := classifier.RunCascade(cParams, *angle)