Ejemplo n.º 1
0
func faceDetect(settings CropSettings, i image.Image, o image.Image) error {

	cvImage := opencv.FromImage(i)
	_, err := os.Stat(settings.FaceDetectionHaarCascadeFilepath)
	if err != nil {
		return err
	}
	cascade := opencv.LoadHaarClassifierCascade(settings.FaceDetectionHaarCascadeFilepath)
	faces := cascade.DetectObjects(cvImage)

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

	if settings.DebugMode == true {
		log.Println("Faces detected:", len(faces))
	}

	for _, face := range faces {
		if settings.DebugMode == true {
			log.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()
	}
	return nil
}
Ejemplo n.º 2
0
Archivo: line.go Proyecto: zzn01/draw2d
// Main draws vertically spaced lines and returns the filename.
// This should only be used during testing.
func Main(gc draw2d.GraphicContext, ext string) (string, error) {
	gc.SetFillRule(draw2d.FillRuleWinding)
	gc.Clear()
	// Draw the line
	for x := 5.0; x < 297; x += 10 {
		Draw(gc, x, 0, x, 210)
	}
	gc.ClearRect(100, 75, 197, 135)
	draw2dkit.Ellipse(gc, 148.5, 105, 35, 25)
	gc.SetFillColor(color.RGBA{0xff, 0xff, 0x44, 0xff})
	gc.FillStroke()

	// Return the output filename
	return samples.Output("line", ext), nil
}
Ejemplo n.º 3
0
func faceDetect(settings CropSettings, i image.Image, o image.Image, scale float64) ([]Face, error) {
	cvImage := opencv.FromImage(i)
	_, err := os.Stat(settings.FaceDetectionHaarCascadeFilepath)
	if err != nil {
		return []Face{}, err
	}

	cascade := opencv.LoadHaarClassifierCascade(settings.FaceDetectionHaarCascadeFilepath)
	faces := cascade.DetectObjects(cvImage)

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

	if settings.DebugMode == true {
		log.Println("Faces detected:", len(faces))
	}

	if len(faces) == 0 {
		return []Face{}, ErrNoFacesFound
	}

	resultFaces := []Face{}

	for _, face := range faces {
		if settings.DebugMode == true {
			log.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()

		x := int(float64(face.X()) * scale)
		y := int(float64(face.Y()) * scale)
		width := int(float64(face.Width()) * scale)
		height := int(float64(face.Height()) * scale)
		resultFaces = append(resultFaces, Face{X: x, Y: y, Width: width, Height: height})
	}

	return resultFaces, nil
}
Ejemplo n.º 4
0
// Draw a gopher head (not rotated)
func Draw(gc draw2d.GraphicContext, x, y, w, h float64) {
	h23 := (h * 2) / 3

	blf := color.RGBA{0, 0, 0, 0xff}          // black
	wf := color.RGBA{0xff, 0xff, 0xff, 0xff}  // white
	nf := color.RGBA{0x8B, 0x45, 0x13, 0xff}  // brown opaque
	brf := color.RGBA{0x8B, 0x45, 0x13, 0x99} // brown transparant
	brb := color.RGBA{0x8B, 0x45, 0x13, 0xBB} // brown transparant

	// round head top
	gc.MoveTo(x, y+h*1.002)
	gc.CubicCurveTo(x+w/4, y-h/3, x+3*w/4, y-h/3, x+w, y+h*1.002)
	gc.Close()
	gc.SetFillColor(brb)
	gc.Fill()

	// rectangle head bottom
	draw2dkit.RoundedRectangle(gc, x, y+h, x+w, y+h+h, h/5, h/5)
	gc.Fill()

	// left ear outside
	draw2dkit.Circle(gc, x, y+h, w/12)
	gc.SetFillColor(brf)
	gc.Fill()

	// left ear inside
	draw2dkit.Circle(gc, x, y+h, 0.5*w/12)
	gc.SetFillColor(nf)
	gc.Fill()

	// right ear outside
	draw2dkit.Circle(gc, x+w, y+h, w/12)
	gc.SetFillColor(brf)
	gc.Fill()

	// right ear inside
	draw2dkit.Circle(gc, x+w, y+h, 0.5*w/12)
	gc.SetFillColor(nf)
	gc.Fill()

	// left eye outside white
	draw2dkit.Circle(gc, x+w/3, y+h23, w/9)
	gc.SetFillColor(wf)
	gc.Fill()

	// left eye black
	draw2dkit.Circle(gc, x+w/3+w/24, y+h23, 0.5*w/9)
	gc.SetFillColor(blf)
	gc.Fill()

	// left eye inside white
	draw2dkit.Circle(gc, x+w/3+w/24+w/48, y+h23, 0.2*w/9)
	gc.SetFillColor(wf)
	gc.Fill()

	// right eye outside white
	draw2dkit.Circle(gc, x+w-w/3, y+h23, w/9)
	gc.Fill()

	// right eye black
	draw2dkit.Circle(gc, x+w-w/3+w/24, y+h23, 0.5*w/9)
	gc.SetFillColor(blf)
	gc.Fill()

	// right eye inside white
	draw2dkit.Circle(gc, x+w-(w/3)+w/24+w/48, y+h23, 0.2*w/9)
	gc.SetFillColor(wf)
	gc.Fill()

	// left tooth
	gc.SetFillColor(wf)
	draw2dkit.RoundedRectangle(gc, x+w/2-w/8, y+h+h/2.5, x+w/2-w/8+w/8, y+h+h/2.5+w/6, w/10, w/10)
	gc.Fill()

	// right tooth
	draw2dkit.RoundedRectangle(gc, x+w/2, y+h+h/2.5, x+w/2+w/8, y+h+h/2.5+w/6, w/10, w/10)
	gc.Fill()

	// snout
	draw2dkit.Ellipse(gc, x+(w/2), y+h+h/2.5, w/6, w/12)
	gc.SetFillColor(nf)
	gc.Fill()

	// nose
	draw2dkit.Ellipse(gc, x+(w/2), y+h+h/7, w/10, w/12)
	gc.SetFillColor(blf)
	gc.Fill()
}