思路:
1. 前后两帧相减,得到差分图像
2.在差分图像里求像素最大的点(最亮的点)
这样就得到,移动微小物体

#include "check.h"
#include <iostream.h>
void main()


{
DWORD t1,t2;

IplImage *frame=0;
CvCapture *capture = cvCaptureFromAVI("E:\\跟踪\\有源窄滤波片2m30fps_2.avi");
CCheck check;

cvNamedWindow( "目标跟踪", 1 );//创建窗口

frame = cvQueryFrame(capture);
check.Init(frame);

while(1)

{
frame = cvQueryFrame(capture);
if(!frame)

{
break;
}
t1 = ::GetTickCount();
CvPoint point = check.point(frame);
IplImage *show = cvCloneImage( frame );
cvCircle(show, point, 10, cvScalar(0,255,0), 2);
cvShowImage("目标跟踪",show);
cvReleaseImage( &show );
cvWaitKey(1);

t2 = ::GetTickCount();
cout << t2-t1 << endl;

}
cvReleaseCapture(&capture);

cvDestroyWindow("目标跟踪");

}

#ifndef CHECK_H
#define CHECK_H

#include "cv.h"
#include "highgui.h"
#include "cvcam.h"
#include "check.h"

#define _I8(image,x,y) (*((unsigned char*)(image)->imageData+(image)->widthStep*(y)+(x))) //直接调用图像的像素,x、y为整数(图像数据应为32F)

#define _I32(img,x,y) ((float*)((img)->imageData + (img)->widthStep*(y)))[(x)]

class CCheck


{
private:
int px,py;
int width,height;
IplImage *frame1; //当前帧
IplImage *frame2; //前一帧



public:
CCheck();
~CCheck();
void Init(IplImage *img);
CvPoint point(IplImage *img);
};

#endif
#include "check.h"
#include <iostream.h>
void main()


{
DWORD t1,t2;

IplImage *frame=0;
CvCapture *capture = cvCaptureFromAVI("E:\\跟踪\\有源窄滤波片2m30fps_2.avi");
CCheck check;

cvNamedWindow( "目标跟踪", 1 );//创建窗口

frame = cvQueryFrame(capture);
check.Init(frame);

while(1)

{
frame = cvQueryFrame(capture);
if(!frame)

{
break;
}
t1 = ::GetTickCount();
CvPoint point = check.point(frame);
IplImage *show = cvCloneImage( frame );
cvCircle(show, point, 10, cvScalar(0,255,0), 2);
cvShowImage("目标跟踪",show);
cvReleaseImage( &show );
cvWaitKey(1);

t2 = ::GetTickCount();
cout << t2-t1 << endl;

}
cvReleaseCapture(&capture);

cvDestroyWindow("目标跟踪");

}

转载于:https://www.cnblogs.com/wqj1212/archive/2007/12/21/1009689.html