Пример #1
0
// DrawRectangles uses Rect array values to return image with rectangles drawn.
func DrawRectangles(image *cv.IplImage, rect []*cv.Rect, r int, g int, b int, thickness int) *cv.IplImage {
	for _, value := range rect {
		cv.Rectangle(image,
			cv.Point{value.X() + value.Width(), value.Y()},
			cv.Point{value.X(), value.Y() + value.Height()},
			cv.NewScalar(float64(b), float64(g), float64(r), 0), thickness, 1, 0)
	}
	return image
}
Пример #2
0
func PaintFace(img []byte, face face) []byte {

	image := opencv.DecodeImageMem(img)

	opencv.Rectangle(image,
		opencv.Point{face.coord.x + face.coord.width, face.coord.y},
		opencv.Point{face.coord.x, face.coord.y + face.coord.height},
		opencv.ScalarAll(0), 1, 1, 0)

	le := face.eye_left.Center()
	re := face.eye_right.Center()

	opencv.Circle(image,
		opencv.Point{le.x, le.y},
		2,
		opencv.ScalarAll(255), 1, 1, 0)

	opencv.Circle(image,
		opencv.Point{re.x, re.y},
		2,
		opencv.ScalarAll(255), 1, 1, 0)

	faceCenter := face.Center()
	opencv.Circle(image,
		opencv.Point{faceCenter.x, faceCenter.y},
		2,
		opencv.ScalarAll(50), 1, 1, 0)

	opencv.Rectangle(image,
		opencv.Point{face.mouth.x + face.mouth.width, face.mouth.y},
		opencv.Point{face.mouth.x, face.mouth.y + face.mouth.height},
		opencv.ScalarAll(2), 1, 1, 0)

	buf := new(bytes.Buffer)
	err := jpeg.Encode(buf, image.ToImage(), nil)
	if err != nil {
		panic(err)
	}
	return buf.Bytes()
}
Пример #3
0
func main() {
	_, currentfile, _, _ := runtime.Caller(0)
	image := opencv.LoadImage(path.Join(path.Dir(currentfile), "../images/lena.jpg"))

	cascade := opencv.LoadHaarClassifierCascade(path.Join(path.Dir(currentfile), "haarcascade_frontalface_alt.xml"))
	faces := cascade.DetectObjects(image)

	for _, value := range faces {
		opencv.Rectangle(image,
			opencv.Point{value.X() + value.Width(), value.Y()},
			opencv.Point{value.X(), value.Y() + value.Height()},
			opencv.ScalarAll(255.0), 1, 1, 0)
	}

	win := opencv.NewWindow("Face Detection")
	win.ShowImage(image)
	opencv.WaitKey(0)
}
Пример #4
0
func PaintFaces(img []byte, faces faces) []byte {

	image := opencv.DecodeImageMem(img)

	for _, face := range faces {

		opencv.Rectangle(image,
			opencv.Point{face.coord.x + face.coord.width, face.coord.y},
			opencv.Point{face.coord.x, face.coord.y + face.coord.height},
			opencv.ScalarAll(0), 1, 1, 0)

		le := face.LeftEye().Center()
		re := face.RightEye().Center()

		opencv.Circle(image,
			opencv.Point{le.X(), le.Y()},
			2,
			opencv.ScalarAll(255), 1, 1, 0)

		opencv.Circle(image,
			opencv.Point{re.x, re.y},
			2,
			opencv.ScalarAll(255), 1, 1, 0)

		faceCenter := face.Center()
		opencv.Circle(image,
			opencv.Point{faceCenter.x, faceCenter.y},
			2,
			opencv.ScalarAll(50), 1, 1, 0)

		//		opencv.Rectangle(image,
		//			opencv.Point{face.mouth.x + face.mouth.width, face.mouth.y},
		//			opencv.Point{face.mouth.x, face.mouth.y + face.mouth.height},
		//			opencv.ScalarAll(2), 1, 1, 0)
	}

	buf := new(bytes.Buffer)
	err := jpeg.Encode(buf, image.ToImage(), nil)
	if err != nil {
		panic(err)
	}
	return buf.Bytes()
}