Sort.h
2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#ifndef SORT_H_
#define SORT_H_
#include "KalmanBoxTracker.h"
#include "HungarianAlgorithm.h"
#include <opencv2/video/tracking.hpp>
#include <highgui.h>
#include <iostream>
#include <stdio.h>
#include <math.h>
#include<vector>
#include "../MSheader.h"
using namespace std;
#define LOSTMAXFRAMECCOUNT 5 //by zl
#define SNAPSHOTFRAMECOUNT 24 //下标从0开始 取第十帧为快照帧
struct TrackerResult
{
vector< vector<float> > trackers_box;
vector< vector< vector<float> > > trackers_history;
};
typedef struct mylist
{
vector <VPT_ObjInfo> listinfo;
int lost; //丢失的帧数 >LOSTMAXFRAMECCOUNT 则认为彻底丢失目标
long id;
bool isupdate;
bool istraffic;
int index;// 行人类别
int num; // 该ID序列下的第num帧 20170306 从0开始计数
int startframe; //轨迹开始帧
int endframe; //轨迹结束帧
}mylist;
class Sort
{
public:
Sort();
int update(int width, int height, bool isUseDet, vector< vector<float> > &dets, VPT_ObjInfo *result, vector<int> &deleteObjectID);
void Release();
void ReSet();
void Pause();
bool GetState();
int addTracker(cv::Mat *img);
public:
vector<KalmanBoxTracker> trackers;
int max_age = 0;
int min_hits = 0;
int frame_count =0;
int trackcount = 0;
int max_track_length = 0;
private:
int linecount = 0;
bool istraffic = 0; //by zl 是否统计交通量
//vector <mylist> tracker;
bool WORK = false;
private:
void associate_detections_to_trackers(vector< vector<int> > &matched, vector<int> &unmatched_dets, vector<int> &unmatched_trks, vector< vector<float> > &dets, vector< vector<float> > &trks, float iou_threshold = 0.3);
//int addTracker(VPT_ObjInfo *result, int resultcount);
int Traffic();
};
//辅助函数
void RectboundCheck(int Width, int Height, VPT_ObjInfo * result); //防止坐标越界 by zl
bool intersect(cv::Point aa, cv::Point bb, cv::Point cc, cv::Point dd); //判断两个线条是否相交 暂时未用到
bool line_rect_intersection(cv::Point start_p, cv::Point end_p, int left, int top, int right, int bottom); //判断矩形框与线条是否相交
#endif