diff --git a/Feature.cpp b/Feature.cpp index cc8781e..cfec29a 100644 --- a/Feature.cpp +++ b/Feature.cpp @@ -1,5 +1,7 @@ #include "Feature.h" +cv::RNG rng(123); + Feature::Feature(float *point, const cv::Mat &description) { // Relative motion in last frame; zero for new point d[0] = 0; @@ -13,6 +15,8 @@ Feature::Feature(float *point, const cv::Mat &description) { desc = description; // Assign default uncertainty u = UNCERTAINTY; + + color = cv::Scalar(rng.uniform(0, 255), rng.uniform(0, 255), rng.uniform(0, 255)); } void Feature::add_match(const float *point, const cv::Mat &description, const float *upper_estimation) { diff --git a/Feature.h b/Feature.h index 5dbd7cf..d8b916b 100644 --- a/Feature.h +++ b/Feature.h @@ -18,6 +18,8 @@ struct Feature { // ORB descriptor cv::Mat desc; + cv::Scalar color; + Feature(float *point, const cv::Mat &description); void add_match(const float *point, const cv::Mat &description, const float *upper_estimation); diff --git a/Layer.h b/Layer.h index 4b21d43..ae1db55 100644 --- a/Layer.h +++ b/Layer.h @@ -15,6 +15,8 @@ class Layer { // Pair points with estimation from layer above virtual void pair(Layer *layer_above) {}; + + virtual void draw(const cv::Mat &frame) {}; }; #endif //GPU_ORB_TRACKER_LAYER_H diff --git a/Motion.cpp b/Motion.cpp index b2ffd2d..3334214 100644 --- a/Motion.cpp +++ b/Motion.cpp @@ -39,3 +39,13 @@ void Motion::add_frame(const std::vector &points, const cv::Mat &d layers[i - 1]->pair(layers[i]); } } + +void Motion::show(const cv::Mat &frame) { + cv::Mat color; + cv::cvtColor(frame,color,cv::COLOR_GRAY2BGR); + for (unsigned i = OCTAVES; i > 0; i--) { + layers[i]->draw(color); + } + cv::imshow("Hierarchical",color); + cv::waitKey(1); +} diff --git a/Motion.h b/Motion.h index 722ac38..8a716e4 100644 --- a/Motion.h +++ b/Motion.h @@ -16,6 +16,8 @@ class Motion { ~Motion(); void add_frame(const std::vector &points, const cv::Mat &descriptors); + + void show(const cv::Mat &frame); }; #endif //GPU_ORB_TRACKER_MOTION_H diff --git a/PointLayer.cpp b/PointLayer.cpp index c3e4149..c7aa39e 100644 --- a/PointLayer.cpp +++ b/PointLayer.cpp @@ -105,3 +105,14 @@ void PointLayer::estimate(float *in, float *out) { out[1] = 0; } } + +void PointLayer::draw(const cv::Mat &frame) { + for (auto &i:active) { + for (auto h = i.history.begin(), h_end = i.history.end();;) { + auto h_old = h++; + if (h == h_end) { break; } + cv::arrowedLine(frame, h_old->second, h->second, + i.color, 1, cv::LINE_AA, 0, 0.2); + } + } +} \ No newline at end of file diff --git a/PointLayer.h b/PointLayer.h index 047e9b2..0086ca7 100644 --- a/PointLayer.h +++ b/PointLayer.h @@ -47,6 +47,8 @@ class PointLayer : public Layer { void estimate(float *in, float *out) override; void pair(Layer *layer_above) override; + + void draw(const cv::Mat &frame) override; }; #endif //GPU_ORB_TRACKER_POINTLAYER_H diff --git a/main.cpp b/main.cpp index d75d147..50ccd2e 100644 --- a/main.cpp +++ b/main.cpp @@ -50,6 +50,7 @@ int main(int argc, char *argv[]) { gpu_desc.download(cpu_desc); motion.add_frame(points, cpu_desc); + motion.show(cpu_gray); frame_number++; }