资源简介
用Opencv和vs2012编写的跟踪视频内运动物体的代码,内附有测试视频
代码片段和文件信息
#include “cv.h“
#include “highgui.h“
#include
#include
#include
#include
#include
// various tracking parameters (in seconds)
const double MHI_DURATION = 0.5;
const double MAX_TIME_DELTA = 0.5;
const double MIN_TIME_DELTA = 0.05;
const int N = 3;
//
const int CONTOUR_MAX_AERA = 16;
// ring image buffer
IplImage **buf = 0;
int last = 0;
// temporary images
IplImage *mhi = 0; // MHI: motion history image
//CvFilter filter = CV_GAUSSIAN_5x5;
CvConnectedComp *cur_comp min_comp;
CvConnectedComp comp;
CvMemStorage *storage;
CvPoint pt[4];
// 参数:
// img – 输入视频帧
// dst – 检测结果
void update_mhi( IplImage* img IplImage* dst int diff_threshold )
{
double timestamp = clock()/100.; // get current time in seconds
CvSize size = cvSize(img->widthimg->height); // get current frame size
int i j idx1 idx2;
IplImage* silh;
uchar val;
float temp;
IplImage* pyr = cvCreateImage( cvSize((size.width & -2)/2 (size.height & -2)/2) 8 1 );
CvMemStorage *stor;
CvSeq *cont *result *squares;
CvSeqReader reader;
if( !mhi || mhi->width != size.width || mhi->height != size.height )
{
if( buf == 0 )
{
buf = (IplImage**)malloc(N*sizeof(buf[0]));
memset( buf 0 N*sizeof(buf[0]));
}
for( i = 0; i < N; i++ )
{
cvReleaseImage( &buf[i] );
buf[i] = cvCreateImage( size IPL_DEPTH_8U 1 );
cvZero( buf[i] );
}
cvReleaseImage( &mhi );
mhi = cvCreateImage( size IPL_DEPTH_32F 1 );
cvZero( mhi ); // clear MHI at the beginning
} // end of if(mhi)
cvCvtColor( img buf[last] CV_BGR2GRAY ); // convert frame to grayscale
idx1 = last;
idx2 = (last + 1) % N; // index of (last - (N-1))th frame
last = idx2;
// 做帧差
silh = buf[idx2];
cvAbsDiff( buf[idx1] buf[idx2] silh ); // get difference between frames
// 对差图像做二值化
cvThreshold( silh silh 30 255 CV_THRESH_BINARY ); // and threshold it
cvUpdateMotionHistory( silh mhi timestamp MHI_DURATION ); // update MHI
cvCvtScale( mhi dst 255./MHI_DURATION
(MHI_DURATION - timestamp)*255./MHI_DURATION );
cvCvtScale( mhi dst 255./MHI_DURATION 0 );
// 中值滤波,消除小的噪声
cvSmooth( dst dst CV_MEDIAN 3 0 0 0 );
// 向下采样,去掉噪声
cvPyrDown( dst pyr 7 );
cvDilate( pyr pyr 0 1 ); // 做膨胀操作,消除目标的不连续空洞
cvPyrUp( pyr dst 7 );
//
// 下面的程序段用来找到轮廓
//
// Create dynamic structure and sequence.
stor = cvCreateMemStorage(0);
cont = cvCreateSeq(CV_SEQ_ELTYPE_POINT sizeof(CvSeq) sizeof(CvPoint) stor);
// 找到所有轮廓
cvFindContours( dst stor &cont sizeof(CvContour)
CV_RETR_LIST CV_CHAIN_APPROX_SIMPLE cvPoint(00));
/*
for(;cont;cont = con
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2015-10-27 17:07 ConsoleApplication1\
目录 0 2015-10-27 17:06 ConsoleApplication1\ConsoleApplication1\
文件 16580608 2015-10-27 17:07 ConsoleApplication1\ConsoleApplication1.sdf
文件 924 2015-10-27 16:58 ConsoleApplication1\ConsoleApplication1.sln
文件 21504 2015-10-27 17:07 ConsoleApplication1\ConsoleApplication1.v11.suo
文件 5248 2015-10-27 17:04 ConsoleApplication1\ConsoleApplication1\1.cpp
文件 5127 2015-10-27 17:02 ConsoleApplication1\ConsoleApplication1\ConsoleApplication1.vcxproj
文件 939 2015-10-27 17:02 ConsoleApplication1\ConsoleApplication1\ConsoleApplication1.vcxproj.filters
目录 0 2015-10-27 17:07 ConsoleApplication1\ConsoleApplication1\Debug\
文件 211718 2015-10-27 17:05 ConsoleApplication1\ConsoleApplication1\Debug\1.obj
文件 626 2015-10-27 17:05 ConsoleApplication1\ConsoleApplication1\Debug\cl.command.1.tlog
文件 20218 2015-10-27 17:05 ConsoleApplication1\ConsoleApplication1\Debug\CL.read.1.tlog
文件 366 2015-10-27 17:05 ConsoleApplication1\ConsoleApplication1\Debug\CL.write.1.tlog
文件 69 2015-10-27 17:05 ConsoleApplication1\ConsoleApplication1\Debug\ConsoleApplication1.lastbuildstate
文件 3067 2015-10-27 17:05 ConsoleApplication1\ConsoleApplication1\Debug\ConsoleApplication1.log
文件 2 2015-10-27 17:05 ConsoleApplication1\ConsoleApplication1\Debug\li
文件 2 2015-10-27 17:05 ConsoleApplication1\ConsoleApplication1\Debug\li
文件 2 2015-10-27 17:05 ConsoleApplication1\ConsoleApplication1\Debug\li
文件 2 2015-10-27 17:05 ConsoleApplication1\ConsoleApplication1\Debug\li
文件 2 2015-10-27 17:05 ConsoleApplication1\ConsoleApplication1\Debug\li
文件 2 2015-10-27 17:05 ConsoleApplication1\ConsoleApplication1\Debug\li
文件 2 2015-10-27 17:05 ConsoleApplication1\ConsoleApplication1\Debug\li
文件 2 2015-10-27 17:05 ConsoleApplication1\ConsoleApplication1\Debug\li
文件 2 2015-10-27 17:05 ConsoleApplication1\ConsoleApplication1\Debug\li
文件 2 2015-10-27 17:05 ConsoleApplication1\ConsoleApplication1\Debug\li
文件 2804 2015-10-27 17:05 ConsoleApplication1\ConsoleApplication1\Debug\li
文件 6414 2015-10-27 17:05 ConsoleApplication1\ConsoleApplication1\Debug\li
文件 480 2015-10-27 17:05 ConsoleApplication1\ConsoleApplication1\Debug\li
文件 658432 2015-10-27 17:05 ConsoleApplication1\ConsoleApplication1\Debug\vc110.idb
文件 1224704 2015-10-27 17:05 ConsoleApplication1\ConsoleApplication1\Debug\vc110.pdb
文件 432700 2006-09-05 00:10 ConsoleApplication1\ConsoleApplication1\video.avi
............此处省略4个文件信息
相关资源
- sift算法VC实现需要OPENCV
- opencv标定单目相机
- opencv 数字识别
- itti视觉显著性计算模型opencv实现
- 异常行为检测
- qt+opencv视频图像采集与基于tcp协议的
- opencv2.4.3和4.0函数手册带目录可搜索
- 遗留物检测
- 笔记本OpenCV调用摄像头进行人脸捕捉
- VS+OPENCV手势识别
- opencv下haarclassifiercascade加上LBPHFaceRe
- 图片动漫风格化
- 基于SVM与ANN的车牌识别
- OpenCV实现同一窗口显示多幅图片
- haar特征的手势检测OpenCV
- 基于opencv的人脸表情识别的预处理
- opencv+qt+vs的摄像头视频显示和处理G
- OpenCV算法精解——源码和测试图片
- opencv结构光生成代码
- opencv 书籍
- 基于PCA的人脸识别系统
-
haartraining+ob
jectmarker,opencv,Adaboo - opencv提取光斑质心
- Ubuntu下Opencv显示中文
- 划痕缺陷检测
- 单USB双目摄像头拍摄程序
- RAAR相位恢复 opencv
- FTVd全变差去模糊opencv实现
- 全变差TV去噪(split bregman) opencv
- opencv开启本地摄像头并拍照
评论
共有 条评论