123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239 |
- #ifndef EASYTRACK_EASY_TRACK_H_
- #define EASYTRACK_EASY_TRACK_H_
- #include <memory>
- #include <vector>
- #include "cxxutil/exception.h"
- #include "easyinfer/model_loader.h"
- namespace edk {
- struct BoundingBox {
- float x;
- float y;
- float width;
- float height;
- };
- struct DetectObject {
-
- int label;
-
- float score;
-
- BoundingBox bbox;
-
- int track_id;
-
- int detect_id;
-
- std::vector<float> feature;
-
- mutable float feat_mold;
- };
- using Objects = std::vector<DetectObject>;
- struct TrackFrame {
-
- void *data;
-
- uint32_t width;
-
- uint32_t height;
-
- int64_t frame_id;
-
- int device_id;
-
- enum class ColorSpace { GRAY, NV21, NV12, RGB24, BGR24 } format;
-
- enum class DevType {
- CPU = 0,
- MLU,
- } dev_type;
- };
- class EasyTrack {
- public:
-
- virtual ~EasyTrack() {}
-
- virtual void UpdateFrame(const TrackFrame &frame, const Objects &detects, Objects *tracks) noexcept(false) = 0;
- };
- class FeatureMatchPrivate;
- class FeatureMatchTrack : public EasyTrack {
- public:
-
- FeatureMatchTrack();
-
- ~FeatureMatchTrack();
-
- void SetParams(float max_cosine_distance, int nn_budget, float max_iou_distance, int max_age, int n_init);
-
- void UpdateFrame(const TrackFrame &frame, const Objects &detects, Objects *tracks) override;
- private:
- FeatureMatchPrivate *fm_p_;
- friend class FeatureMatchPrivate;
- float max_cosine_distance_ = 0.2;
- float max_iou_distance_ = 0.7;
- int max_age_ = 30;
- int n_init_ = 3;
- uint32_t nn_budget_ = 100;
- };
- class KcfTrackPrivate;
- class KcfTrack : public EasyTrack {
- public:
-
- KcfTrack();
-
- ~KcfTrack();
-
- void SetModel(std::shared_ptr<ModelLoader> model, int dev_id = 0, uint32_t batch_size = 1);
-
- void SetParams(float max_iou_distance);
-
- void UpdateFrame(const TrackFrame &frame, const Objects &detects, Objects *tracks) override;
- private:
- KcfTrackPrivate *kcf_p_;
- friend class KcfTrackPrivate;
- float max_iou_distance_ = 0.7;
- };
- inline std::ostream &operator<<(std::ostream &os, const DetectObject &obj) {
- os << "[Object] label: " << obj.label << " score: " << obj.score << " track_id: " << obj.track_id << '\t'
- << "bbox: " << obj.bbox.x << " " << obj.bbox.y << " " << obj.bbox.width << " " << obj.bbox.height;
- return os;
- }
- }
- #endif
|