ssa
1package goroi2
3import (4"fmt"5"log"6"os"7
8pigo "github.com/esimov/pigo/core"9)
10
11type Pigs struct {12Classifier *pigo.Pigo13}
14
15func NewPigs(FileCascade string) (*Pigs, error) {16// consumers.StartForwardStreamConsumer()17// camtron.StartCam()18cascadeFile, err := os.ReadFile(FileCascade) // "cascade/facefinder"19if err != nil {20return nil, fmt.Errorf("os.ReadFile: Error reading the cascade file: %v", err)21}22
23pigo := pigo.NewPigo()24// Unpack the binary file. This will return the number of cascade trees,25// the tree depth, the threshold and the prediction from tree's leaf nodes.26classifier, err := pigo.Unpack(cascadeFile)27if err != nil {28return nil, fmt.Errorf("pigo.Unpack: Error reading the cascade file: %v", err)29}30
31return &Pigs{32Classifier: classifier,33}, nil34}
35
36func (p Pigs) getCoords(filepath string) []pigo.Detection {37
38src, err := pigo.GetImage(filepath)39if err != nil {40log.Fatalf("Cannot open the image file: %v", err)41}42
43pixels := pigo.RgbToGrayscale(src)44cols, rows := src.Bounds().Max.X, src.Bounds().Max.Y45
46cParams := pigo.CascadeParams{47MinSize: 20,48MaxSize: 1000,49ShiftFactor: 0.1,50ScaleFactor: 1.1,51
52ImageParams: pigo.ImageParams{53Pixels: pixels,54Rows: rows,55Cols: cols,56Dim: cols,57},58}59
60angle := 0.0 // cascade rotation angle. 0.0 is 0 radians and 1.0 is 2*pi radians61
62// Run the classifier over the obtained leaf nodes and return the detection results.63// The result contains quadruplets representing the row, column, scale and detection score.64dets := p.Classifier.RunCascade(cParams, angle)65// fmt.Printf("%+v\n", dets)66
67// Calculate the intersection over union (IoU) of two clusters.68dets = p.Classifier.ClusterDetections(dets, 0.1)69
70// fmt.Printf("%+v\n", dets)71// fmt.Println()72
73return dets74}
75