资源简介
基于camshift跟踪算法,使用鼠标框选多个目标进行跟踪
代码片段和文件信息
#include
#include “opencv2/video/tracking.hpp“
#include “opencv2/imgproc.hpp“
#include “opencv2/videoio.hpp“
#include “opencv2/highgui.hpp“
#include
#include
#include “Car.h“
using namespace cv;
using namespace std;
Mat image;
bool backprojMode = false;
bool selectobject = false;
int trackobject = 0;
int count1 = 0;
bool showHist = true;
Point origin;
Rect selection selection2;
int vmin = 10 vmax = 256 smin = 30;
Car* car;
// User draws box around object to track. This triggers CAMShift to start tracking
static void onMouse(int event int x int y int void*)
{
if (selectobject)
{
if (count1 == 1) {
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);
}
if (count1 == 2) {
selection2.x = MIN(x origin.x);
selection2.y = MIN(y origin.y);
selection2.width = std::abs(x - origin.x);
selection2.height = std::abs(y - origin.y);
//selection2 &= Rect(0 0 image.cols image.rows);
}
}
switch (event)
{
case EVENT_LBUTTONDOWN:
origin = Point(x y);
if (count1 == 0)
selection = Rect(x y 0 0);
if (count1 == 1)
selection2 = Rect(x y 0 0);
selectobject = true;
count1++;
break;
case EVENT_LBUTTONUP:
selectobject = false;
if (selection.width > 0 && selection.height > 0 && count1 == 2)
trackobject = -1; // Set up CAMShift properties in main() loop
break;
}
}
string hot_keys =
“\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“;
static void help()
{
cout << “a little demo for the car detection“;
cout << hot_keys;
}
const char* keys =
{
“{help h | | show help message}{@camera_number| 0 | camera number}“
};
int main(int argc const char** argv)
{
VideoCapture cap;
VideoWriter video;
Rect trackWindow;
int hsize = 16;
float hranges[] = { 0180 };
const float* phranges = hranges;
CommandLineParser parser(argc argv keys);
if (parser.has(“help“))
{
help();
return 0;
}
int camNum = parser.get(0);
cap.open(camNum);
if (!cap.isOpened())
{
help();
cout << “***Could not initialize capturing...***\n“;
cout << “Current parameter‘s value: \n“;
parser.printMessage();
return -1;
}
Size S = Size((int)cap.get(CAP_PROP_frame_WIDTH) // Acquire input size
(int)cap.ge
- 上一篇:数据结构——表达式求值 完整代码
- 下一篇:用栈非递归方法迷宫找出路
相关资源
- staple多目标跟踪算法代码
- MOPSO多目标粒子群优化算法c++实现内附
- 光线跟踪算法C++源代码+文档
- OPENGL光线跟踪算法
- 利用opencv 完成camshift+ kalman
- 多目标跟踪c++代码290025
- NSGA II代码实现集合包含、讲解及 网络
- 多目标跟踪c++代码
- 多个光线投射算法ray casting和光线跟踪
- KCF跟踪算法(C++)146187
- 时空上下文跟踪STC
- 多目标进化算法评价
- 多目标粒子群算法C代码
- KCF跟踪算法c++
- 边界跟踪算法的实现,图像处理 c++
- 基于Camshift+Kalman的多目标跟踪
- NSGA多目标遗传算法
- MOEA/D的C++代码
- 多目标车辆路径优化源代码
- Camshift Kalman目标跟踪算法
- 粒子滤波目标跟踪算法
- 2018年及以前经典实时目标跟踪算法代
- 多目标优化进化算法MOEA库 C++语言
- 多目标优化算法(一)NSGA2C语言版
- 多目标优化算法(二)MOEADC语言版
- 基于opencv3.2+VS2015的多目标检测跟踪与
评论
共有 条评论