OpenCV:运动模板检测

本文深入探讨了OpenCV中的运动模板检测技术,通过实例展示了如何利用该技术进行目标检测。通过运行结果截图,读者可以直观地理解运动模板检测在实际应用中的效果及其优势。
摘要由CSDN通过智能技术生成
<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(
  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 8
    评论
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值