示例#1
0
func drawRectangles(img *cv.IplImage, rects [][4]cv.Point) {
	cpy := img.Clone()
	defer cpy.Release()

	for _, r := range rects {
		points := r[:]
		cv.PolyLine(cpy, [][]cv.Point{points}, true, cv.Scalar{0.0, 255.0, 0.0, 0.0}, 3, cv.AA, 0)
	}

	cv.ShowImage(windowName, cpy)
}
示例#2
0
func run() {
	// Create windows
	cv.NamedWindow(inputWindowName, cv.WINDOW_AUTOSIZE)
	cv.NamedWindow(outputWindowName, cv.WINDOW_AUTOSIZE)

	// Set up camera
	capture, err := NewAxisCamera(axisHost, axisUsername, axisPassword)
	if err != nil {
		fmt.Fprintln(os.Stderr, "failed to start capture")
		os.Exit(1)
	}

	for {
		// Get a frame
		img, err := capture.QueryFrame()
		if err != nil {
			fmt.Fprintln(os.Stderr, "failed to query frame")
			os.Exit(1)
		}

		// Process image
		out, rects := processImage(img)

		// Display images
		drawRectangles(inputWindowName, img, rects)
		cv.ShowImage(outputWindowName, out)
		out.Release()

		// Wait for input
		key := cv.WaitKey(10 * time.Millisecond)
		if key == 'q' {
			break
		}
	}
	os.Exit(0)
}