diff --git a/core/flploc_test.go b/core/flploc_test.go index 5c2faa1..9e5efd9 100644 --- a/core/flploc_test.go +++ b/core/flploc_test.go @@ -74,3 +74,59 @@ func TestFlploc_LandmarkPointsFinderShouldReturnDetectionPoints(t *testing.T) { t.Fatalf("should have been detected facial landmark points: %s", err) } } + +func BenchmarkFlploc(b *testing.B) { + pg := 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 := pg.Unpack(pigoCascade) + if err != nil { + b.Fatalf("error reading the cascade file: %s", err) + } + + pl := pigo.PuplocCascade{} + plc, err := pl.UnpackCascade(puplocCascade) + if err != nil { + b.Fatalf("error reading the cascade file: %s", err) + } + + var faces []pigo.Detection + + b.ResetTimer() + + for i := 0; i < b.N; i++ { + pixs := pigo.RgbToGrayscale(srcImg) + cParams.Pixels = pixs + // 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. + faces = classifier.RunCascade(*cParams, 0.0) + // Calculate the intersection over union (IoU) of two clusters. + faces = classifier.ClusterDetections(faces, 0.1) + + for _, face := range faces { + if face.Scale > 50 { + // left eye + puploc := &pigo.Puploc{ + Row: face.Row - int(0.075*float32(face.Scale)), + Col: face.Col - int(0.175*float32(face.Scale)), + Scale: float32(face.Scale) * 0.25, + Perturbs: 50, + } + leftEye := plc.RunDetector(*puploc, *imgParams, 0.0, false) + + // right eye + puploc = &pigo.Puploc{ + Row: face.Row - int(0.075*float32(face.Scale)), + Col: face.Col + int(0.185*float32(face.Scale)), + Scale: float32(face.Scale) * 0.25, + Perturbs: 50, + } + rightEye := plc.RunDetector(*puploc, *imgParams, 0.0, false) + + plc.FindLandmarkPoints(leftEye, rightEye, *imgParams, 63, "left") + + } + } + } + _ = faces +} diff --git a/core/pigo_test.go b/core/pigo_test.go index 2b96387..c11c827 100644 --- a/core/pigo_test.go +++ b/core/pigo_test.go @@ -11,6 +11,7 @@ import ( ) var ( + p = pigo.NewPigo() pigoCascade []byte srcImg *image.NRGBA ) @@ -47,6 +48,43 @@ func init() { } } +func TestPigo_UnpackCascadeFileShouldNotBeNil(t *testing.T) { + var ( + err error + pigo = pigo.NewPigo() + ) + p, err = pigo.Unpack(pigoCascade) + if err != nil { + t.Fatalf("failed unpacking the cascade file: %v", err) + } +} + +func TestPigo_InputImageShouldBeGrayscale(t *testing.T) { + // Since an image converted grayscale has only one channel,we should assume + // that the grayscale image array length is the source image length / 4. + if len(imgParams.Pixels) != len(srcImg.Pix)/4 { + t.Fatalf("the source image should be converted to grayscale") + } +} + +func TestPigo_Detector_ShouldDetectFace(t *testing.T) { + // 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(pigoCascade) + if err != nil { + t.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. + faces := classifier.RunCascade(*cParams, 0.0) + // Calculate the intersection over union (IoU) of two clusters. + faces = classifier.ClusterDetections(faces, 0.1) + if len(faces) == 0 { + t.Fatalf("should have been detected eyes: %s", err) + } +} + func BenchmarkPigo(b *testing.B) { pg := pigo.NewPigo() // Unpack the binary file. This will return the number of cascade trees, diff --git a/core/puploc_test.go b/core/puploc_test.go index 11306af..7f8c105 100644 --- a/core/puploc_test.go +++ b/core/puploc_test.go @@ -34,14 +34,6 @@ func TestPuploc_UnpackCascadeFileShouldNotBeNil(t *testing.T) { } } -func TestPuploc_InputImageShouldBeGrayscale(t *testing.T) { - // Since an image converted grayscale has only one channel,we should assume - // that the grayscale image array length is the source image length / 4. - if len(imgParams.Pixels) != len(srcImg.Pix)/4 { - t.Fatalf("the source image should be converted to grayscale") - } -} - func TestPuploc_Detector_ShouldDetectEyes(t *testing.T) { p := pigo.NewPigo() // Unpack the binary file. This will return the number of cascade trees,