esimov / pigo

Fast face detection, pupil/eyes localization and facial landmark points detection library in pure Go.
MIT License
4.37k stars 309 forks source link

Save detected images differently #19

Closed adigunhammedolalekan closed 5 years ago

adigunhammedolalekan commented 5 years ago

Hi, Thanks for the great work here.

Is it possible to use pigo to extract faces from a photo and save the extracted faces individually.

esimov commented 5 years ago

Yes, it is possible, since the API will return the rectangle coordinates of the detected faces. You only need to subtract the subregions of the detected faces from the original image.

A use case scenario should look like the following:

type SubImager interface {
    SubImage(r image.Rectangle) image.Image
}

//.....

// 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)

for i := 0; i < len(dets); i++ {
    if dets[i].Q >= 5.0 {
        rect := image.Rect(
            dets[i].Col-dets[i].Scale/2,
            dets[i].Row-dets[i].Scale/2,
            dets[i].Scale,
            dets[i].Scale,
        )

        subImg := img.(SubImager).SubImage(rect)
        bounds := subImg.Bounds()

        // Do whatever you want with the subImg
    }
}
adigunhammedolalekan commented 5 years ago

I will try this. Thank You