Exemplo n.º 1
0
func detect(cascade *opencv.HaarCascade, r io.Reader) ([]*Face, error) {
	img, format, err := image.Decode(r)
	if err != nil {
		return []*Face{}, err
	}
	log.Printf("Image format: %s", format)
	rects := cascade.DetectObjects(opencv.FromImage(img))

	faces := []*Face{}

	for _, value := range rects {
		face := &Face{
			PointX: value.X(),
			PointY: value.Y(),
			Width:  value.Width(),
			Height: value.Height(),
		}
		faces = append(faces, face)
	}
	return faces, nil
}
Exemplo n.º 2
0
func ProcessImage(img *opencv.IplImage, cascade *opencv.HaarCascade) (bool, error) {
	faces := cascade.DetectObjects(img)
	hasFaces := len(faces) > 0
	return hasFaces, nil
}