示例#1
0
func faceDetect(i *image.Image, o *image.Image) {

	cvImage := opencv.FromImage(*i)
	_, err := os.Stat(faceDetectionHaarCascade)
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
	cascade := opencv.LoadHaarClassifierCascade(faceDetectionHaarCascade)
	faces := cascade.DetectObjects(cvImage)

	gc := draw2dimg.NewGraphicContext((*o).(*image.RGBA))

	if debug == true {
		fmt.Println("Faces detected:", len(faces))
	}

	for _, face := range faces {
		if debug == true {
			fmt.Printf("Face: x: %d y: %d w: %d h: %d\n", face.X(), face.Y(), face.Width(), face.Height())
		}
		draw2dkit.Ellipse(
			gc,
			float64(face.X()+(face.Width()/2)),
			float64(face.Y()+(face.Height()/2)),
			float64(face.Width()/2),
			float64(face.Height())/2)
		gc.SetFillColor(color.RGBA{255, 0, 0, 255})
		gc.Fill()
	}

}
示例#2
0
func test(t *testing.T, draw sample) {
	// Initialize the graphic context on an RGBA image
	dest := image.NewRGBA(image.Rect(0, 0, 297, 210.0))
	gc := draw2dimg.NewGraphicContext(dest)
	// Draw Android logo
	output, err := draw(gc, "png")
	if err != nil {
		t.Errorf("Drawing %q failed: %v", output, err)
		return
	}
	// Save to png
	err = draw2dimg.SaveToPngFile(output, dest)
	if err != nil {
		t.Errorf("Saving %q failed: %v", output, err)
	}
}
示例#3
0
func imgPng(w http.ResponseWriter, r *http.Request) *appError {
	w.Header().Set("Content-type", "image/png")

	// Initialize the graphic context on an RGBA image
	dest := image.NewRGBA(image.Rect(0, 0, 297, 210.0))
	gc := draw2dimg.NewGraphicContext(dest)

	// Draw sample
	android.Draw(gc, 65, 0)

	err := png.Encode(w, dest)
	if err != nil {
		return &appError{err, fmt.Sprintf("Can't encode: %s", err), 500}
	}

	return nil
}