Merge pull request #26682 from 5usu:4.x

Adding AddRgbFeature(), and improving robustness in ComputeRgbDistance().

### Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work
- [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [ ] The feature is well documented and sample code can be built with the project CMake
This commit is contained in:
sujal 2025-03-31 12:17:34 +05:30 committed by GitHub
parent 9d34a88597
commit 8c7288676e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 20 additions and 10 deletions

View File

@ -141,6 +141,12 @@ ObjectsAssociator::ComputeRgbDistance(const std::vector<Detection> &detections,
if (tracking_per_class_ && (detections[d].class_label != tracklets[t]->label))
continue;
// Check if RGB features are available
auto t_rgb_features = tracklets[t]->GetRgbFeatures();
if (!t_rgb_features || t_rgb_features->empty()) {
continue; // Skip if no RGB features are available
}
// Find best match in rgb feature history
float min_dist = 1000.0f;
for (const auto &t_rgb_feature : *(tracklets[t]->GetRgbFeatures())) {

View File

@ -7,13 +7,15 @@
#include "tracklet.hpp"
#include <sstream>
#include <memory>
namespace vas {
namespace ot {
Tracklet::Tracklet()
: id(0), label(-1), association_idx(kNoMatchDetection), status(ST_DEAD), age(0), confidence(0.f),
occlusion_ratio(0.f), association_delta_t(0.f), association_fail_count(0) {
occlusion_ratio(0.f), association_delta_t(0.f), association_fail_count(0),
rgb_features_(std::make_shared<std::deque<cv::Mat>>()) {
}
Tracklet::~Tracklet() {
@ -45,12 +47,13 @@ void Tracklet::RenewTrajectory(const cv::Rect2f &bounding_box) {
trajectory_filtered.push_back(bounding_box);
}
#define DEFINE_STRING_VAR(var_name, value) \
std::stringstream __##var_name; \
__##var_name << value; \
std::string var_name = __##var_name.str();
std::deque<cv::Mat> *Tracklet::GetRgbFeatures() {
return rgb_features_.get(); // Return the raw pointer from the shared_ptr
}
#define ROUND_F(value, scale) (round((value)*scale) / scale)
void Tracklet::AddRgbFeature(const cv::Mat &feature) {
rgb_features_->push_back(feature);
}
std::string Tracklet::Serialize() const {
#ifdef DUMP_OTAV
@ -97,10 +100,6 @@ std::string Tracklet::Serialize() const {
#endif
}
std::deque<cv::Mat> *Tracklet::GetRgbFeatures() {
return nullptr;
}
ZeroTermImagelessTracklet::ZeroTermImagelessTracklet() : Tracklet(), birth_count(1) {
}

View File

@ -13,6 +13,7 @@
#include <cstdint>
#include <deque>
#include <memory>
namespace vas {
namespace ot {
@ -45,6 +46,7 @@ class Tracklet {
virtual void RenewTrajectory(const cv::Rect2f &bounding_box);
virtual std::deque<cv::Mat> *GetRgbFeatures();
void AddRgbFeature(const cv::Mat &feature);
virtual std::string Serialize() const; // Returns key:value with comma separated format
public:
@ -63,6 +65,9 @@ class Tracklet {
std::deque<cv::Rect2f> trajectory_filtered;
cv::Rect2f predicted; // Result from Kalman prediction. It is for debugging (OTAV)
mutable std::vector<std::string> otav_msg; // Messages for OTAV
private:
std::shared_ptr<std::deque<cv::Mat>> rgb_features_;
};
class ZeroTermImagelessTracklet : public Tracklet {