资源简介
早vs2008 中基于opencv2.4.3 的meanshift目标检测,直接运行,视屏从电脑的摄像头读取,演示效果不错,适合初学目标检测的同行,可以从感性上理解meanshift的原理和不足,为改进的camshift理解做准备。原理部分参见我的博客:http://blog.csdn.net/tiandijun,共同学习、交流。
代码片段和文件信息
//#include “StdAfx.h“
#include “opencv2/video/tracking.hpp“
#include “opencv2/imgproc/imgproc.hpp“
#include “opencv2/highgui/highgui.hpp“
#include
#include
using namespace cv;
using namespace std;
Mat image;
bool backprojMode = false; //表示是否要进入反向投影模式,ture表示准备进入反向投影模式
bool selectobject = false;//代表是否在选要跟踪的初始目标,true表示正在用鼠标选择
int trackobject = 0; //代表跟踪目标数目
bool showHist = true;//是否显示直方图
Point origin;//用于保存鼠标选择第一次单击时点的位置
Rect selection;//用于保存鼠标选择的矩形框
int vmin = 10 vmax = 256 smin = 30;
void onMouse( int event int x int y int void* )
{
if( selectobject )//只有当鼠标左键按下去时才有效,然后通过if里面代码就可以确定所选择的矩形区域selection了
{
selection.x = MIN(x origin.x);//矩形左上角顶点坐标
selection.y = MIN(y origin.y);
selection.width = std::abs(x - origin.x);//矩形宽
selection.height = std::abs(y - origin.y);//矩形高
selection &= Rect(0 0 image.cols image.rows);//用于确保所选的矩形区域在图片范围内
}
switch( event )
{
case CV_EVENT_LBUTTONDOWN:
origin = Point(xy);
selection = Rect(xy00);//鼠标刚按下去时初始化了一个矩形区域
selectobject = true;
break;
case CV_EVENT_LBUTTONUP:
selectobject = false;
if( selection.width > 0 && selection.height > 0 )
trackobject = -1;
break;
}
}
void help()
{
cout << “\nThis is a demo that shows mean-shift based tracking\n“
“You select a color objects such as your face and it tracks it.\n“
“This reads from video camera (0 by default or the camera number the user enters\n“
“Usage: \n“
“ ./camshiftdemo [camera number]\n“;
cout << “\n\nHot keys: \n“
“\tESC - quit the program\n“
“\tc - stop the tracking\n“
“\tb - switch to/from backprojection view\n“
“\th - show/hide object histogram\n“
“\tp - pause video\n“
“To initialize tracking select the object with mouse\n“;
}
const char* keys =
{
“{1| | 0 | camera number}“
};
int main( int argc const char** argv )
{
help();
VideoCapture cap; //定义一个摄像头捕捉的类对象
Rect trackWindow;
RotatedRect trackBox;//定义一个旋转的矩阵类对象
int hsize = 16;
float hranges[] = {0180};//hranges在后面的计算直方图函数中要用到
const float* phranges = hranges;
CommandLineParser parser(argc argv keys);//命令解析器函数
int camNum = parser.get(“1“);
cap.open(camNum);//直接调用成员函数打开摄像头
if( !cap.isOpened() )
{
help();
cout << “***Could not initialize capturing...***\n“;
cout << “Current parameter‘s value: \n“;
parser.printParams();
return -1;
}
namedWindow( “Histogram“ 0 );
namedWindow( “CamShift Demo“ 0 );
setMouseCallback( “CamShift Demo“ onMouse 0 );//消息响应机制
createTrackbar( “Vmin“ “CamShift Demo“ &vmin 256 0 );//createTrackbar函数的功能是在对应的窗口创建滑动条,滑动条Vminvmin表示滑动条的值,最大为256
createTrackbar( “Vmax“ “CamShift Demo“ &vmax
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 10038 2014-06-18 10:43 2014-06-18 MeanShift\2014-06-18 MeanShift\2014-06-18 MeanShift.cpp
文件 4785 2014-06-18 10:43 2014-06-18 MeanShift\2014-06-18 MeanShift\2014-06-18 MeanShift.vcproj
文件 1425 2014-06-18 21:07 2014-06-18 MeanShift\2014-06-18 MeanShift\2014-06-18 MeanShift.vcproj.PC201310041721.Administrator.user
文件 663 2014-06-18 10:44 2014-06-18 MeanShift\2014-06-18 MeanShift\Debug\2014-06-18 MeanShift.exe.em
文件 728 2014-06-18 10:44 2014-06-18 MeanShift\2014-06-18 MeanShift\Debug\2014-06-18 MeanShift.exe.em
文件 621 2014-06-18 10:44 2014-06-18 MeanShift\2014-06-18 MeanShift\Debug\2014-06-18 MeanShift.exe.intermediate.manifest
文件 363539 2014-06-18 10:43 2014-06-18 MeanShift\2014-06-18 MeanShift\Debug\2014-06-18 MeanShift.obj
文件 14644 2014-06-18 10:44 2014-06-18 MeanShift\2014-06-18 MeanShift\Debug\BuildLog.htm
文件 65 2014-06-18 10:44 2014-06-18 MeanShift\2014-06-18 MeanShift\Debug\mt.dep
文件 289792 2014-06-18 10:43 2014-06-18 MeanShift\2014-06-18 MeanShift\Debug\vc90.idb
文件 520192 2014-06-18 10:43 2014-06-18 MeanShift\2014-06-18 MeanShift\Debug\vc90.pdb
文件 3517440 2014-06-18 21:07 2014-06-18 MeanShift\2014-06-18 MeanShift.ncb
文件 926 2014-06-18 10:42 2014-06-18 MeanShift\2014-06-18 MeanShift.sln
..A..H. 8704 2014-06-18 21:07 2014-06-18 MeanShift\2014-06-18 MeanShift.suo
文件 97280 2014-06-18 10:44 2014-06-18 MeanShift\Debug\2014-06-18 MeanShift.exe
文件 638544 2014-06-18 10:44 2014-06-18 MeanShift\Debug\2014-06-18 MeanShift.ilk
文件 1207296 2014-06-18 10:44 2014-06-18 MeanShift\Debug\2014-06-18 MeanShift.pdb
目录 0 2014-06-18 10:44 2014-06-18 MeanShift\2014-06-18 MeanShift\Debug
目录 0 2014-06-18 10:43 2014-06-18 MeanShift\2014-06-18 MeanShift
目录 0 2014-06-18 10:44 2014-06-18 MeanShift\Debug
目录 0 2014-06-18 10:43 2014-06-18 MeanShift
----------- --------- ---------- ----- ----
6676682 21
- 上一篇:3D排3胆码王.rar
- 下一篇:bootstrap 4.1.3-dist.zip
相关资源
- opencv 的knn的训练数据
- 单高斯背景建模opencv
- opencv高斯滤波模板及其滤波
- 基于OpenCV实现Retinex
- 虹膜识别VC2008+opencv2.3.1源码,改编自
- protobuf-cpp-3.1.0.tar.gz 下载192823
- opencv_xxx.310d.lib
- openCV图像检测资源包
- Opencv 下Cascade Classifier实现人脸识别的
-
opencv车牌识别xm
l文件 - Canny算子源代码
- 双目已知图像坐标求空间坐标opencv
- h264+ffmpeg+opencv开发手册
- opencvjs编译后的文件
- OpenCV图像处理教程 - 贾志刚 课程配套
- boostdesc vgg_generated.zip
- 机器视觉标定板选型表-凯林博
- opencv源程序
- 全景拼接_多张图像拼接(stitching_de
-
Online ob
ject Tracking:A Benchmark_CVPR13翻 - protobuf-cpp-3.1.0.tar.gz 配置文件
- 图像特征点提取与匹配
- opencv获取图像像素值
- 动作识别 Hu距 SVM opencv2.4.9 VS2013
- createsamples.exe和haartraining.exe及所需d
- opencv车牌识别系统可直接运行
- 基于opencv与yolo的目标识别案例
- svm颜色分类
- QT OPENCV车牌识别 识别结果输出到Tex
- opencv3.2交叉编译移植笔记
评论
共有 条评论