Example #1
0
func ProcessImage(img *opencv.IplImage, win *opencv.Window, pos int) error {
	w := img.Width()
	h := img.Height()

	// Create the output image
	cedge := opencv.CreateImage(w, h, opencv.IPL_DEPTH_8U, 3)
	defer cedge.Release()

	// Convert to grayscale
	gray := opencv.CreateImage(w, h, opencv.IPL_DEPTH_8U, 1)
	edge := opencv.CreateImage(w, h, opencv.IPL_DEPTH_8U, 1)
	defer gray.Release()
	defer edge.Release()

	opencv.CvtColor(img, gray, opencv.CV_BGR2GRAY)

	opencv.Smooth(gray, edge, opencv.CV_BLUR, 3, 3, 0, 0)
	opencv.Not(gray, edge)

	// Run the edge detector on grayscale
	opencv.Canny(gray, edge, float64(pos), float64(pos*3), 3)

	opencv.Zero(cedge)
	// copy edge points
	opencv.Copy(img, cedge, edge)

	win.ShowImage(img)
	return nil
}
func ProcessbetterImage(img *opencv.IplImage, win *opencv.Window, pos int) error {
	_, currentfile, _, _ := runtime.Caller(0)
	//image := opencv.LoadImage(path.Join(path.Dir(currentfile), "../images/eye.jpg"))

	if counter == 1 {
		//find eye, cache them and then mark them
		counter = 0
		cachedPointsCenterY = []int{}
		cachedPointsCenterX = []int{}

		if haarClassifier == nil {
			//load and cache haarClassifier
			haarClassifier = opencv.LoadHaarClassifierCascade(path.Join(path.Dir(currentfile), "/cascades/haarcascade_eye_tree_eyeglasses.xml"))
		}

		rects := haarClassifier.DetectObjects(img)

		for _, value := range rects {

			var pointRect1 = opencv.Point{value.X() + value.Width(), value.Y()}
			var pointRect2 = opencv.Point{value.X(), value.Y() + value.Height()}
			var centerPointX = int((pointRect1.X + pointRect2.X) / 2)
			var centerPointY = int((pointRect1.Y + pointRect2.Y) / 2)

			var center = opencv.Point{centerPointX, centerPointY}
			cachedPointsCenterX = append(cachedPointsCenterX, center.X)
			cachedPointsCenterY = append(cachedPointsCenterY, center.Y)

			//draw eye marker
			drawEyeMarker(img, center)
		}
	} else {
		//if we have a cached value
		for i := 0; i < len(cachedPointsCenterY); i++ {
			drawEyeMarker(img, opencv.Point{cachedPointsCenterX[i], cachedPointsCenterY[i]})
		}

	}
	win.ShowImage(img)
	//counter for cache
	counter = counter + 1
	return nil
}