光流法 \OpenCV2.1\samples\c\lkdemo.exe

转载 2012年03月24日 17:48:15
/////////////光流法//////////////
#include <D:\\OpenCV\\OpenCV2.2\\include\\opencv2/video/tracking.hpp>
#include <D:\\OpenCV\\OpenCV2.2\\include\\opencv2/highgui/highgui.hpp>
#include <stdio.h>
void help()
{
	printf(
		"This program demonstrate dense \"Farneback\n optical flow\n"
		"It read from camera 0, and shows how to use and display dense Franeback optical flow\n"
		"Call:\n"
		"./fback_c\n\n");

}
void drawOptFlowMap(const CvMat* flow, CvMat* cflowmap, int step,
	double scale, CvScalar color)
{
	int x, y;
	for( y = 0; y < cflowmap->rows; y += step)
		for( x = 0; x < cflowmap->cols; x += step)
		{
			CvPoint2D32f fxy = CV_MAT_ELEM(*flow, CvPoint2D32f, y, x);
			cvLine(cflowmap, cvPoint(x,y), cvPoint(cvRound(x+fxy.x), cvRound(y+fxy.y)),
				color, 1, 8, 0);
			cvCircle(cflowmap, cvPoint(x,y), 2, color, -1, 8, 0);
		}
}

int main(int argc, char** argv)
{
	CvCapture* capture = cvCreateCameraCapture(0);
	CvMat* prevgray = 0, *gray = 0, *flow = 0, *cflow = 0;

	help();

	if( !capture )
		return -1;

	cvNamedWindow("flow", 1);

	for(;;)
	{
		int firstFrame = gray == 0;
		IplImage* frame = cvQueryFrame(capture);
		if(!frame)
			break;
		if(!gray)
		{
			gray = cvCreateMat(frame->height, frame->width, CV_8UC1);
			prevgray = cvCreateMat(gray->rows, gray->cols, gray->type);
			flow = cvCreateMat(gray->rows, gray->cols, CV_32FC2);
			cflow = cvCreateMat(gray->rows, gray->cols, CV_8UC3);
		}
		cvCvtColor(frame, gray, CV_BGR2GRAY);

		if( !firstFrame )
		{
			cvCalcOpticalFlowFarneback(prevgray, gray, flow, 0.5, 3, 15, 3, 5, 1.2, 0);
			cvCvtColor(prevgray, cflow, CV_GRAY2BGR);
			drawOptFlowMap(flow, cflow, 16, 1.5, CV_RGB(0, 255, 0));
			cvShowImage("flow", cflow);
		}
		if(cvWaitKey(30)>=0)
			break;
		{
			CvMat* temp;    
			CV_SWAP(prevgray, gray, temp);
		}
	}
	cvReleaseCapture(&capture);
	return 0;
}

相关文章推荐

OpenCV学习笔记——VideoWriter生成视频流highgui

首先要先纠正个误区,我见有人用OpenCV做多媒体开发,真的是很搞笑,OpenCV这东西再强大,这方面也不行的,之所以把视频读取写入这部分做的强大一些,也是为了方便大家做视频处理的时候方便些,而且这部...

光流法

#include #include #include #include #include #include using namespace std; using namespace c...

Opencv2.1+vs2008生成不依赖编译环境的exe文件

转载自:http://blog.163.com/sky_sgx/blog/static/1994391942011111310356235/ 工作环境: IDE:Microsoft Vis...

samples-2.1_r01-linux.zip

  • 2013年03月12日 15:36
  • 7.32MB
  • 下载

OpenCV2.4.10之samples_cpp_tutorial-code_learn-----ImgTrans(Hough变换)

本系列学习笔记参考自OpenCV2.4.10之opencv\sources\samples\cpp\tutorial_code和http://www.opencv.org.cn/opencvdoc/2...

OpenCV Samples ------ BackgroundSubtraction

1. Sample Description A program demonstrating the use and capabilities of a particular BackgroundSub...

OpenCV2.4.10之samples_cpp_tutorial-code_learn-----ml(SVM支持向量机一)

本系列学习笔记参考自OpenCV2.4.10之opencv\sources\samples\cpp\tutorial_code和http://www.opencv.org.cn/opencvdoc/2...

OpenCV2.4.10之samples_cpp_tutorial-code_learn-----ImgTrans(图片边框与图片卷积)

本系列学习笔记参考自OpenCV2.4.10之 opencv\sources\samples\cpp\tutorial_code和 http://www.opencv.org.cn/opencvd...

OpenCV2.4.10之samples_cpp_tutorial-code_learn-----ImgProc(图像处理)

本系列学习笔记参考自OpenCV2.4.10之opencv\sources\samples\cpp\tutorial_code和http://www.opencv.org.cn/opencvdoc/2...

OpenCV2.4.10之samples_cpp_tutorial-code_learn-----ImgTrans(仿射变换)

本系列学习笔记参考自OpenCV2.4.10之 opencv\sources\samples\cpp\tutorial_code和 http://www.opencv.org.cn/opencvdoc...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:光流法 \OpenCV2.1\samples\c\lkdemo.exe
举报原因:
原因补充:

(最多只允许输入30个字)