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 := draw2d.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()) } draw2d.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() } }
// Paint is called when the Area needs to be redrawn. // The part of the Area that needs to be redrawn is stored in cliprect. // Before Paint() is called, this region is cleared with a system-defined background color. // You MUST handle this event, and you MUST return a valid image, otherwise deadlocks and panicking will occur. // The image returned must have the same size as rect (but does not have to have the same origin points). func (area *canvasArea) Paint(cliprect image.Rectangle) *image.RGBA { //area.img.SetRGBA(0, 0, color.RGBA{0, 0, 0, 255}) dc := draw2d.NewGraphicContext(area.img) dc.Save() dc.SetFillColor(color.Black) draw2d.Ellipse(dc, 16, 16, 8, 8) dc.FillStroke() dc.Restore() return area.img.SubImage(cliprect).(*image.RGBA) }
func gordon(gc draw2d.GraphicContext, x, y, w, h float64) { h23 := (h * 2) / 3 blf := color.RGBA{0, 0, 0, 0xff} wf := color.RGBA{0xff, 0xff, 0xff, 0xff} nf := color.RGBA{0x8B, 0x45, 0x13, 0xff} brf := color.RGBA{0x8B, 0x45, 0x13, 0x99} brb := color.RGBA{0x8B, 0x45, 0x13, 0xBB} gc.MoveTo(x, y+h) gc.CubicCurveTo(x, y+h, x+w/2, y-h, x+w, y+h) gc.Close() gc.SetFillColor(brb) gc.Fill() draw2d.RoundRect(gc, x, y+h, x+w, y+h+h, 10, 10) gc.Fill() draw2d.Circle(gc, x, y+h, w/12) // left ear gc.SetFillColor(brf) gc.Fill() draw2d.Circle(gc, x, y+h, w/12-10) gc.SetFillColor(nf) gc.Fill() draw2d.Circle(gc, x+w, y+h, w/12) // right ear gc.SetFillColor(brf) gc.Fill() draw2d.Circle(gc, x+w, y+h, w/12-10) gc.SetFillColor(nf) gc.Fill() draw2d.Circle(gc, x+w/3, y+h23, w/9) // left eye gc.SetFillColor(wf) gc.Fill() draw2d.Circle(gc, x+w/3+10, y+h23, w/10-10) gc.SetFillColor(blf) gc.Fill() draw2d.Circle(gc, x+w/3+15, y+h23, 5) gc.SetFillColor(wf) gc.Fill() draw2d.Circle(gc, x+w-w/3, y+h23, w/9) // right eye gc.Fill() draw2d.Circle(gc, x+w-w/3+10, y+h23, w/10-10) gc.SetFillColor(blf) gc.Fill() draw2d.Circle(gc, x+w-(w/3)+15, y+h23, 5) gc.SetFillColor(wf) gc.Fill() gc.SetFillColor(wf) draw2d.RoundRect(gc, x+w/2-w/8, y+h+30, x+w/2-w/8+w/8, y+h+30+w/6, 5, 5) // left tooth gc.Fill() draw2d.RoundRect(gc, x+w/2, y+h+30, x+w/2+w/8, y+h+30+w/6, 5, 5) // right tooth gc.Fill() draw2d.Ellipse(gc, x+(w/2), y+h+30, w/6, w/12) // snout gc.SetFillColor(nf) gc.Fill() draw2d.Ellipse(gc, x+(w/2), y+h+10, w/10, w/12) // nose gc.SetFillColor(blf) gc.Fill() }