Пример #1
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)
}
Пример #2
0
func run() {
	imageName := flag.String("image", "", "Use a static image instead of loading from a webcam")
	flag.Parse()

	cv.NamedWindow(windowName, cv.WINDOW_AUTOSIZE)

	if *imageName != "" {
		img, err := cv.LoadImage(*imageName, 1)
		if err != nil {
			fmt.Println(err)
			os.Exit(1)
		}
		defer img.Release()

		rects := findRectangles(img)
		drawRectangles(img, rects)
		cv.WaitKey(time.Duration(0))
	} else {
		capture, err := cv.CaptureFromCAM(0)
		if err != nil {
			fmt.Println(err)
			os.Exit(1)
		}

		for {
			img, err := capture.QueryFrame()
			if err != nil {
				fmt.Println(err)
				os.Exit(1)
			}
			img0 := img.Clone()

			rects := findRectangles(img0)
			drawRectangles(img0, rects)
			if key := cv.WaitKey(time.Duration(10*time.Millisecond)) & 0x7f; key == 'q' {
				break
			}

			img0.Release()
			//img.Release()
		}

		capture.Release()
	}
	os.Exit(0)
}