예제 #1
0
func dendriteCam(deltaE chan float32, config Configuration) {
	camera := C.cvCaptureFromCAM(-1)

	// Shutdown dendrite if no camera detected.
	if camera == nil {
		fmt.Printf("WARNING: No camera detected. Shutting down DendriteCam\n")
		return
	}

	C.cvSetCaptureProperty(camera, C.CV_CAP_PROP_FRAME_WIDTH, 160)
	C.cvSetCaptureProperty(camera, C.CV_CAP_PROP_FRAME_HEIGHT, 120)

	// Capture original frame.
	prev := C.cvCloneImage(C.cvQueryFrame(camera))

	// Save out the first frame for debuging purposes.
	file := C.CString("frame.png")
	C.cvSaveImage(file, unsafe.Pointer(prev), nil)
	C.free(unsafe.Pointer(file))

	flow := C.cvCreateImage(C.cvSize(prev.width, prev.height), C.IPL_DEPTH_32F, 2)
	prevG := C.cvCreateImage(C.cvSize(prev.width, prev.height), C.IPL_DEPTH_8U, 1)
	nextG := C.cvCreateImage(C.cvSize(prev.width, prev.height), C.IPL_DEPTH_8U, 1)
	C.cvConvertImage(unsafe.Pointer(prev), unsafe.Pointer(prevG), 0)

	for {
		C.cvGrabFrame(camera)

		// Capture the new frame and convert it to grayscale.
		next := C.cvCloneImage(C.cvQueryFrame(camera))
		C.cvConvertImage(unsafe.Pointer(prev), unsafe.Pointer(prevG), 0)
		C.cvConvertImage(unsafe.Pointer(next), unsafe.Pointer(nextG), 0)

		C.cvCalcOpticalFlowFarneback(unsafe.Pointer(prevG), unsafe.Pointer(nextG), unsafe.Pointer(flow), 0.5, 2, 5, 2, 5, 1.1, 0)
		deltaE <- float32(calcDeltaEnergy(flow, &config))

		C.cvReleaseImage(&prev)
		prev = next
	}

	// Never reached - but here in comments for completeness.
	//C.cvReleaseImage(&prev)
	//C.cvReleaseImage(&nextG)
	//C.cvReleaseImage(&prevG)
	//C.cvReleaseImage(&flow)
	//C.cvReleaseCapture(&camera)
}
예제 #2
0
/* Creates a copy of IPL image (widthStep may differ) */
func (img *IplImage) Clone() *IplImage {
	p := C.cvCloneImage((*C.IplImage)(img))
	return (*IplImage)(p)
}
예제 #3
0
파일: image.go 프로젝트: mottalli/go-cv
func (img *Image) Clone() (res *Image) {
	res, _ = imageFromIplImage(C.cvCloneImage(img.iplImage))
	return
}