diff --git a/core/grayscale_test.go b/core/grayscale_test.go index 1f9cfe3..8628fb7 100644 --- a/core/grayscale_test.go +++ b/core/grayscale_test.go @@ -1,4 +1,4 @@ -package pigo +package pigo_test import ( "image" @@ -7,7 +7,7 @@ import ( ) const ( - ImgWidth = 10 + ImgWidth = 10 ImgHeight = 10 ) diff --git a/core/image_test.go b/core/image_test.go index ea10b01..6b2b283 100644 --- a/core/image_test.go +++ b/core/image_test.go @@ -1,4 +1,4 @@ -package pigo +package pigo_test import ( "image" diff --git a/core/pigo_test.go b/core/pigo_test.go new file mode 100644 index 0000000..2118868 --- /dev/null +++ b/core/pigo_test.go @@ -0,0 +1,65 @@ +package pigo_test + +import ( + "io/ioutil" + "log" + "path/filepath" + "testing" + + pigo "github.com/esimov/pigo/core" +) + +var pigoCascadeFile []byte + +func init() { + var err error + pigoCascadeFile, err = ioutil.ReadFile("../data/facefinder") + if err != nil { + log.Fatalf("Error reading the cascade file: %v", err) + } +} + +func BenchmarkPigo(b *testing.B) { + source := filepath.Join("../testdata", "sample.jpg") + src, err := pigo.GetImage(source) + if err != nil { + log.Fatalf("Error reading the source file: %s", err) + } + + pixs := pigo.RgbToGrayscale(src) + cols, rows := src.Bounds().Max.X, src.Bounds().Max.Y + + cParams := pigo.CascadeParams{ + MinSize: 20, + MaxSize: 1000, + ShiftFactor: 0.2, + ScaleFactor: 1.1, + ImageParams: pigo.ImageParams{ + Pixels: pixs, + Rows: rows, + Cols: cols, + Dim: cols, + }, + } + 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(pigoCascadeFile) + if err != nil { + log.Fatalf("Error reading the cascade file: %s", err) + } + + var dets []pigo.Detection + b.ResetTimer() + + for i := 0; i < b.N; i++ { + pixs := pigo.RgbToGrayscale(src) + 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. + dets = classifier.RunCascade(cParams, 0.0) + // Calculate the intersection over union (IoU) of two clusters. + dets = classifier.ClusterDetections(dets, 0.1) + } + _ = dets +}