esimov / pigo

Fast face detection, pupil/eyes localization and facial landmark points detection library in pure Go.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Save detected images differently

adigunhammedolalekan opened this issue · comments

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.

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
	}
}

I will try this. Thank You