Beispiel #1
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()
}
Beispiel #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()
}
Beispiel #3
0
func main() {
	win := opencv.NewWindow("Go-OpenCV Webcam Face Detection")
	defer win.Destroy()

	cap := opencv.NewCameraCapture(0)
	if cap == nil {
		panic("cannot open camera")
	}
	defer cap.Release()

	cwd, err := os.Getwd()
	if err != nil {
		panic(err)
	}
	cascade := opencv.LoadHaarClassifierCascade(path.Join(cwd, "haarcascade_frontalface_alt.xml"))

	fmt.Println("Press ESC to quit")
	for {
		if cap.GrabFrame() {
			img := cap.RetrieveFrame(1)
			if img != nil {
				faces := cascade.DetectObjects(img)
				for _, value := range faces {
					opencv.Circle(img,
						opencv.Point{
							value.X() + (value.Width() / 2),
							value.Y() + (value.Height() / 2),
						},
						value.Width()/2,
						opencv.ScalarAll(255.0), 1, 1, 0)
				}

				win.ShowImage(img)
			} else {
				fmt.Println("nil image")
			}
		}
		key := opencv.WaitKey(1)

		if key == 27 {
			os.Exit(0)
		}
	}
}
func (e eyeMarker) drawEyeMarker(img *opencv.IplImage, p opencv.Point) {
	opencv.Circle(img, p, 5, opencv.ScalarAll(175.0), 1, 1, 0)
}
	var eyeMarker = NewEyeMarker(cascade)

	var copy = opencv.CreateImage(v.currentFrameIn.Width(), v.currentFrameIn.Height(), v.currentFrameIn.Depth(), v.currentFrameIn.Channels())
	var copy2 = opencv.CreateImage(v.currentFrameIn.Width(), v.currentFrameIn.Height(), v.currentFrameIn.Depth(), v.currentFrameIn.Channels())
	opencv.Copy(v.currentFrameIn, copy, nil)
	opencv.Copy(v.currentFrameIn, copy2, nil)

	var rois = eyeMarker.MarkEyesRects(copy)

	if len(rois) > 0 {
		copy.SetROI(*rois[0])
		copy = ProcessRoi(copy, 75)
		//var gray = opencv.CreateImage(copy.Width(),copy.Height(),opencv.IPL_DEPTH_8U,1)
		//copy.SetROI(*rois[0])

		var circels = HoughCircles1(copy)
		log.Print(circels)
		for i := 0; i < len(circels); i++ {

			var center = opencv.Point{rois[0].X() + int(circels[i].X), rois[0].Y() + int(circels[0].Y)}
			//var center = opencv.Point{int(circels[i].X),int(circels[0].Y)}
			opencv.Circle(copy2, center, int(circels[i].R), opencv.NewScalar(255, 0, 0, 1), 1, 1, 0)
			//src *IplImage, dp float64, min_dist float64, param1 float64, param2 float64, min_radius int, max_radius int
		}
		copy.ResetROI()
	}
	v.framesOut = append(v.framesOut, copy2)
}

type Process func(*VideoProcessor)
Beispiel #6
0
func MarkRoi() {

	//
	//    var fourcc = opencv.FOURCC('m','p','4','v')
	//    var fps = float32(video.GetProperty(opencv.CV_CAP_PROP_FPS))
	//    var size = opencv.Size{int(video.GetProperty(opencv.CV_CAP_PROP_FRAME_WIDTH)),
	//        int(video.GetProperty(opencv.CV_CAP_PROP_FRAME_HEIGHT))};
	//
	//    log.Print("fourcc: ", fourcc)
	//    log.Print("fps: ", fps)
	//    log.Print("size: ", size)
	//
	//    defer video.Release()

	win := opencv.NewWindow("Go-OpenCV Webcam")
	defer win.Destroy()

	win2 := opencv.NewWindow("rect cam: ")
	win2.Move(400, 0)
	defer win2.Destroy()

	_, currentfile, _, _ := runtime.Caller(0)
	var cascade = path.Join(path.Dir(currentfile), "/../cascades/haarcascade_eye_tree_eyeglasses.xml")
	var eyeMarker = NewEyeMarker(cascade)

	var cap = NewVideoCapture(path.Join(path.Dir(currentfile), "/../eyevid1.mp4"))
	//var cap = NewVideoCapture("")

	var rois []*opencv.Rect

	for {
		var frame = cap.GetFrame()
		if frame == nil {
			break
		}
		img := frame

		var copy = opencv.CreateImage(img.Width(), img.Height(), opencv.IPL_DEPTH_8U, 3)
		opencv.Copy(img, copy, nil)

		rois = eyeMarker.MarkEyesRects(copy)

		if len(rois) > 0 {
			log.Print(rois[0])
			copy.SetROI(*rois[0])
			copy = ProcessRoi(copy, 25)
			//var gray = opencv.CreateImage(copy.Width(),copy.Height(),opencv.IPL_DEPTH_8U,1)
			//copy.SetROI(*rois[0])

			var circels = HoughCircles1(copy)
			log.Print(circels)
			for i := 0; i < len(circels); i++ {

				var center = opencv.Point{rois[0].X() + int(circels[i].X), rois[0].Y() + int(circels[0].Y)}
				//var center = opencv.Point{int(circels[i].X),int(circels[0].Y)}
				opencv.Circle(img, center, int(circels[i].R), opencv.NewScalar(255, 0, 0, 1), 1, 1, 0)
				//src *IplImage, dp float64, min_dist float64, param1 float64, param2 float64, min_radius int, max_radius int
			}
			copy.ResetROI()
		}

		win.ShowImage(img)
		win2.ShowImage(copy)

		key := opencv.WaitKey(10)

		if key == 27 {
			os.Exit(0)
		}
	}

	os.Exit(0)
}