diff --git a/algorithm/sv_algorithm_base.cpp b/algorithm/sv_algorithm_base.cpp index 0f23509..19cbbdd 100644 --- a/algorithm/sv_algorithm_base.cpp +++ b/algorithm/sv_algorithm_base.cpp @@ -758,6 +758,19 @@ int SingleObjectTrackerBase::getTarget() { return this->_target; } +//增加跟踪目标位置输出 +double SingleObjectTrackerBase::getObjectWs() +{ + return this->_object_ws; +} +double SingleObjectTrackerBase::getObjectHs() +{ + return this->_object_hs; +} +int SingleObjectTrackerBase::useWidthOrHeight() +{ + return this->_use_width_or_height; +} void SingleObjectTrackerBase::warmUp() { @@ -803,6 +816,22 @@ void SingleObjectTrackerBase::track(cv::Mat img_, TargetsInFrame& tgts_) tgt.setBox(rect.x, rect.y, rect.x+rect.width, rect.y+rect.height, img_.cols, img_.rows); tgt.setTrackID(1); tgt.setLOS(tgt.cx, tgt.cy, this->camera_matrix, img_.cols, img_.rows); + int ow = int(round(rect.width)); + int oh = int(round(rect.height)); + if (this->_use_width_or_height == 0) + { + double z = this->camera_matrix.at(0, 0) * this->_object_ws / ow; + double x = tan(tgt.los_ax / SV_RAD2DEG) * z; + double y = tan(tgt.los_ay / SV_RAD2DEG) * z; + tgt.setPosition(x, y, z); + } + else if (this->_use_width_or_height == 1) + { + double z = this->camera_matrix.at(1, 1) * this->_object_hs / oh; + double x = tan(tgt.los_ax / SV_RAD2DEG) * z; + double y = tan(tgt.los_ay / SV_RAD2DEG) * z; + tgt.setPosition(x, y, z); + } tgts_.targets.push_back(tgt); } @@ -840,6 +869,18 @@ void SingleObjectTrackerBase::_load() else if ("target" == std::string(i->key)) { this->_target = i->value.toNumber(); } + else if ("useWidthOrHeight" == std::string(i->key)) + { + this->_use_width_or_height = i->value.toNumber(); + } + else if ("sigleobjectW" == std::string(i->key)) + { + this->_object_ws = i->value.toNumber(); + } + else if ("sigleobjectH" == std::string(i->key)) + { + this->_object_hs = i->value.toNumber(); + } } setupImpl(); diff --git a/include/sv_algorithm_base.h b/include/sv_algorithm_base.h index 5822f4e..a3d0ad0 100644 --- a/include/sv_algorithm_base.h +++ b/include/sv_algorithm_base.h @@ -105,6 +105,9 @@ public: std::string getAlgorithm(); int getBackend(); int getTarget(); + double getObjectWs(); + double getObjectHs(); + int useWidthOrHeight(); protected: virtual bool setupImpl(); virtual void initImpl(cv::Mat img_, const cv::Rect& bounding_box_); @@ -114,6 +117,9 @@ protected: std::string _algorithm; int _backend; int _target; + int _use_width_or_height; + double _object_ws; + double _object_hs; };