问题描述
- 老是显示未声明 "eig_image和tmp_image"
-
// pyramid L-K light flow 4.cpp : 定义控制台应用程序的入口点。
//// TestLucasKanade.cpp : 定义控制台应用程序的入口点。
#include "stdafx.h"
#include "cv.h"
#include "highgui.h"
#include
#include
const int MAX_CORNERS=500;
int main(int argc,char** argv)
{
IplImage* imgA=cvLoadImage("d:dcachetest.jpg",CV_LOAD_IMAGE_GRAYSCALE);
IplImage* imgB=cvLoadImage("d:dcache1.jpg",CV_LOAD_IMAGE_GRAYSCALE);
CvSize img_sz=cvGetSize(imgA);
int win_size=10;
//
IplImage* imgC=cvLoadImage("d:dcache2.jpg",CV_LOAD_IMAGE_UNCHANGED);IplImage* eig_image=cvCreateImage(img_sz,IPL_DEPTH_32F,1);
IplImage* tmp_image=cvCreateImage(img_sz,IPL_DEPTH_32F,1);int corner_count=MAX_CORNERS;
CvPoint2D32f* cornersA=new CvPoint2D32f[MAX_CORNERS];
cvGoodFeaturesToTrack(
imgA,//检测角点
eig_image,//两个临时图像
tmp_image,
cornersA,//函数的输出,即检测到的角点数组
&corner_count,//最大角点数,调用函数后返回的角点的数目
0.01,
5.0,//返回角点之间的最短距离不应小于min_distance
0,
3,
0,
0.04
);
cvFindCornerSubPix(//根据上一步精确角点位置,确定亚像素角点
imgA,
cornersA,//整数值的像素位置
corner_count,//角点数目
cvSize(win_size,win_size),//等式产生窗口的尺寸
cvSize(-1,-1),//禁区,不需要时设置cvSize(-1,-1)
cvTermCriteria(CV_TERMCRIT_ITER|CV_TERMCRIT_EPS,20,0.03)
);char features_found[MAX_CORNERS];
float feature_errors[MAX_CORNERS];
CvSize pyr_sz=cvSize(imgA->width+8,imgB->height/3);
IplImage* pyrA=cvCreateImage(pyr_sz,IPL_DEPTH_32F,1);
IplImage* pyrB=cvCreateImage(pyr_sz,IPL_DEPTH_32F,1);
CvPoint2D32f* cornersB=new CvPoint2D32f[MAX_CORNERS];
cvCalcOpticalFlowPyrLK(
imgA,//初始图像
imgB,//最终图像
pyrA,//申请存放两幅输入图像金字塔的缓存,大小至少为(img.width-8)*img.height/3字节
pyrB,
cornersA,//用于寻找运动的点
cornersB,//存放featureA中点的新的位置
corner_count,//featureA中点的数目
cvSize(win_size,win_size),
5,//金字塔层数
features_found,//对应点是否在第二副图像中发现
feature_errors,
cvTermCriteria(CV_TERMCRIT_ITER|CV_TERMCRIT_EPS,20,0.3),
0
);for(int i=0;i<corner_count;i++)
{
if(features_found[i]==0||feature_errors[i]<550)
{
printf("error is %f/n",feature_errors[i]);
continue;
}
printf("got it/n");
CvPoint p0=cvPoint(cvRound(cornersA[i].x),cvRound(cornersA[i].y));
CvPoint p1=cvPoint(cvRound(cornersB[i].x),cvRound(cornersB[i].y));
cvLine(imgC,p0,p1,CV_RGB(255,0,0),2);
}
cvNamedWindow("ImageA",0);
cvNamedWindow("ImageB",0);
cvNamedWindow("LKpyr_opticalFlow",0);
cvShowImage("ImageA",imgA);
cvShowImage("ImageB",imgB);
cvShowImage("LKpyr_opticalFlow",imgC);cvWaitKey(0);
return 0;}