<span style="font-size:14px;">#include <opencv\cv.h>
#include <opencv\highgui.h>
#include <time.h>
#include <math.h>
#include <ctype.h>
#include <stdio.h>
// 不同的跟踪参数
const double MHI_DURATION = 0.5;
const double MAX_TIME_DELTA = 0.5;
const double MIN_TIME_DELTA = 0.05;
// 用于运动检测的循环帧数,与机器速度及FPS设置有关
const int N = 2;
IplImage **buf = 0;
int last = 0;
// 临时图像
IplImage *mhi = 0; // MHI: 运动历史图像
IplImage *orient = 0; // 方向
IplImage *mask = 0; // 有效的运动掩码
IplImage *segmask = 0; // 运动分割映射
CvMemStorage* storage = 0; // 临时存储区
// parameters:
// img - input video frame
// dst - resultant motion picture
// args - optional parameters
void update_mhi( IplImage* img, IplImage* dst, int diff_threshold ){
double timestamp = clock()/1000.; // 获取当前时间,以秒为单位
CvSize size = cvSize(img->width,img->height); // 获取当前帧尺寸
int i, idx1 = last, idx2;
IplImage* silh;
CvSeq* seq;
CvRect comp_rect;
double count;
double angle;
CvPoint center;
double magnitude;
CvScalar color;
// 开始时为图像分配内存 or 帧尺寸改变时重新分配内存
if( !mhi || mhi->width != size.width || mhi->height != size.height ){
if( buf == 0 ){
buf = (IplImage**)malloc(
OpenCV:运动模板检测
最新推荐文章于 2024-05-25 09:57:59 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)