add SingleObjectTracker position xyz output

This commit is contained in:
Eason Yi 2024-05-23 16:16:59 +08:00 committed by 王世豪
parent fb9b65401d
commit 8bdde82ff3
2 changed files with 47 additions and 0 deletions

View File

@ -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<double>(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<double>(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();

View File

@ -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;
};