#include "Detector.h"
using namespace suanzi;
+using namespace cv;
Detector::Detector()
{
namespace suanzi {
+ struct Detection;
+
TK_DECLARE_PTR(Detector);
class Detector
{
public:
Detector();
virtual ~Detector();
- void detect(cv::Mat& frame){};
+ unsigned int detect(cv::Mat& frame, Detection* detections){return 1;}
+ };
+
+ struct Detection
+ {
+ // 检测目标的类型,目前只有一个类human,默认等于0。为以后可以检测的更多类别预留
+ unsigned int object_type;
+ // 检测目标的分数,可以不填
+ float score;
+ // 检测目标的坐标,包括物体中心的x、y坐标,物体的高和宽
+ unsigned int center_x;
+ unsigned int center_y;
+ unsigned int height;
+ unsigned int width;
+ // 检测目标的特征向量
+ unsigned int feature_size;
+ float * feature;
};
}
void Engine::setVideoSrc(VideoSrcType type, const std::string& url)
{
- videoSrc = url;
+// videoSrc = url;
reader = VideoReaderFactory::createVideoReader(type, url);
}
{
LOG_DEBUG(TAG, "run");
cv::Mat frame;
+ Detection detections[128];
while (reader->read(frame)){
LOG_DEBUG(TAG, "Size: " << frame.cols << "x" << frame.rows);
- detector->detect(frame);
+ // TODO
+ int total = detector->detect(frame, detections);
+ multiTracker->update(total, detections, frame);
}
}
DetectorPtr detector;
MultiTrackerPtr multiTracker;
std::set<EngineObserver *> observer_list;
- std::string videoSrc;
+ //std::string videoSrc;
VideoReaderPtr reader;
};
Metrics::Metrics(const std::string& clf_path)
{
- descriptor = HOGDescriptor(Size(64, 128), Size(16, 16), Size(8, 8), Size(8, 8), 9);
if (clf_path.empty()){
+
} else {
+
}
}
public:
Metrics(const std::string& cl_path = "");
~Metrics(){}
- long int MaxCost = 100000;
+ const static long int MaxCost = 100000;
const static int MaxPatch = 5;
private:
- cv::HOGDescriptor descriptor;
+ cv::HOGDescriptor descriptor = {cv::Size(64, 128), cv::Size(16, 16), cv::Size(8, 8), cv::Size(8, 8), 9};
};
class Patch
#include "MultiTracker.h"
#include "Metrics.h"
+#include <algorithm>
using namespace suanzi;
+using namespace cv;
MultiTracker::MultiTracker(MetricsPtr m) : metrics(m)
{
trackers.erase(t);
}
+void MultiTracker::initNewTrackers(cv::Mat& iamge)
+{
+}
+
-void MultiTracker::update()
+void MultiTracker::correctTrackers(MetricsPtr m, Mat& image)
{
+}
+
+
+void MultiTracker::update(unsigned int total, const Detection* d, const Mat& image)
+{
+
+ // correct_trackers
+
+
+ //
+
+
+
+
+
+
+
+
+ // Delete long lost trackers;
+// for (auto& t : trackers){
+// if (t->status == TrackerStatus::Delete)
+// trackers.erase(t);
+// }
+//
+ // Update trackers using kalman filter
+// for(auto& t: trackers){
+// //t.bb_ltrb =
+// }
+//
+ // associate trackers with detections
+// correctTrackers(this->metric, image);
+ // create new trackers for new detections
}
#define _MULTI_TRACKER_H_
#include "Tracker.h"
+#include "Detector.h"
#include "Metrics.h"
#include "SharedPtr.h"
+#include <opencv2/opencv.hpp>
namespace suanzi {
public:
MultiTracker(MetricsPtr m);
virtual ~MultiTracker();
- void addTracker(TrackerPtr t);
- void removeTracker(TrackerPtr t);
- TrackerPtr createTracker(int id = 0);
- void update();
-
+ void update(unsigned int total, const Detection* d, const cv::Mat& image);
+
private:
MetricsPtr metrics;
std::set<TrackerPtr> trackers;
int max_id = 0;
+ void addTracker(TrackerPtr t);
+ TrackerPtr createTracker(int id = 0);
+ void removeTracker(TrackerPtr t);
+ void correctTrackers(MetricsPtr m, cv::Mat& image);
+ void initNewTrackers(cv::Mat& iamge);
};
{
status = TrackerStatus::Fire;
preStatus = TrackerStatus::Fire;
+
+ // TODO
+ // init KalmanFilter
+ this->kf.transitionMatrix = (Mat_<float>(4, 4) <<
+ 1, 0, 1, 0,
+ 0, 1, 0, 1,
+ 0, 0, 1, 0,
+ 0, 0, 0, 1);
+
+ this->kf.measurementMatrix = (Mat_<float>(2, 2) <<
+ 1, 0, 0, 0,
+ 0, 1, 0, 0);
+
+ this->kf.processNoiseCov = 1e-5 * Mat_<float>::eye(4, 4);
+ this->kf.measurementNoiseCov = 1e-1 * Mat_<float>::ones(2, 2);
+ this->kf.errorCovPost = 1. * Mat_<float>::ones(4, 4);
}
Tracker::~Tracker()
} TrackerStatus;
TK_DECLARE_PTR(Tracker);
+// TK_DECLARE_PTR(KalmanFilter);
class Tracker
{
public:
virtual ~Tracker();
void updateState(const cv::Mat& image);
void addPatch(Patch* p);
+ TrackerStatus status;
private:
- TrackerStatus status;
TrackerStatus preStatus;
int id;
int age;
int last_active;
std::vector<Patch *> patches;
+ cv::KalmanFilter kf = {4,2};
};
+// class KalmanFilter
+// {
+// public:
+// KalmanFilter();
+// ~KalmanFilter();
+// private:
+// cv::KalmanFilter
+//
+// };
+
}
VideoReaderPtr VideoReaderFactory::createVideoReader(VideoSrcType type, const std::string& url)
{
+ VideoReaderPtr v;
switch(type){
case VideoSrcType::URL:
- {
- VideoReaderPtr v (new UrlReader(type, url));
- return v;
- }
+ v = std::make_shared<UrlReader>(type, url);
+ break;
case VideoSrcType::File:
- {
- VideoReaderPtr v (new FileReader(type, url));
- return v;
- }
+ v = std::make_shared<FileReader>(type, url);
+ break;
case VideoSrcType::USB:
- {
- VideoReaderPtr v (new UsbReader(type, url));
- return v;
- }
+ v = std::make_shared<UsbReader>(type, url);
+ break;
default:
break;
}
- return nullptr;
+ return v;
}
VideoReader::~VideoReader()