提交 9a47921c 编写于 作者: G gineshidalgo99

PoseExtractor for 3D

上级 b162274d
......@@ -20,6 +20,8 @@ namespace op
void trackLockThread(Array<float>& poseKeypoints, const cv::Mat& cvMatInput, const Array<long long>& poseIds,
const long long frameId);
bool getMergeResults() const;
private:
const bool mMergeResults;
......
......@@ -17,7 +17,7 @@ namespace op
PoseExtractor(const std::shared_ptr<PoseExtractorNet>& poseExtractorNet,
const std::shared_ptr<KeepTopNPeople>& keepTopNPeople = nullptr,
const std::shared_ptr<PersonIdExtractor>& personIdExtractor = nullptr,
const std::vector<std::shared_ptr<PersonTracker>>& personTracker = {},
const std::shared_ptr<std::vector<std::shared_ptr<PersonTracker>>>& personTracker = {},
const int numberPeopleMax = -1, const int tracking = -1);
virtual ~PoseExtractor();
......@@ -67,7 +67,7 @@ namespace op
const std::shared_ptr<PoseExtractorNet> spPoseExtractorNet;
const std::shared_ptr<KeepTopNPeople> spKeepTopNPeople;
const std::shared_ptr<PersonIdExtractor> spPersonIdExtractor;
const std::vector<std::shared_ptr<PersonTracker>> spPersonTrackers;
const std::shared_ptr<std::vector<std::shared_ptr<PersonTracker>>> spPersonTrackers;
DELETE_COPY(PoseExtractor);
};
......
......@@ -616,10 +616,10 @@ namespace op
std::make_shared<KeepTopNPeople>(wrapperStructPose.numberPeopleMax)
: nullptr);
// Person tracker
std::vector<std::shared_ptr<PersonTracker>> personTrackers;
auto personTrackers = std::make_shared<std::vector<std::shared_ptr<PersonTracker>>>();
if (wrapperStructPose.tracking > -1)
personTrackers.resize(spWPoseExtractors.size(),
std::make_shared<PersonTracker>(wrapperStructPose.tracking == 0));
personTrackers->emplace_back(
std::make_shared<PersonTracker>(wrapperStructPose.tracking == 0));
for (auto i = 0u; i < spWPoseExtractors.size(); i++)
{
// OpenPose keypoint detector + keepTopNPeople
......
......@@ -58,4 +58,17 @@ namespace op
error(e.what(), __LINE__, __FUNCTION__, __FILE__);
}
}
bool PersonTracker::getMergeResults() const
{
try
{
return mMergeResults;
}
catch (const std::exception& e)
{
error(e.what(), __LINE__, __FUNCTION__, __FILE__);
return false;
}
}
}
......@@ -60,36 +60,39 @@ namespace op
if (!poseIds.empty())
{
const auto poseKeypointsArea = poseKeypoints.getSize(1)*poseKeypoints.getSize(2);
const auto isVisible = 0.05f;
for (auto i = 0u ; i < poseIds.getVolume() ; i++)
{
const auto indexMain = i * poseKeypointsArea;
const auto indexSecondary = i * poseKeypointsArea + poseKeypoints.getSize(2);
const auto isVisible = 0.05f;
if (poseKeypoints[indexMain+2] > isVisible || poseKeypoints[indexSecondary+2] > isVisible)
if (poseIds[i] > -1)
{
const auto xA = intRound(poseKeypoints[indexMain]);
const auto yA = intRound(poseKeypoints[indexMain+1]);
const auto xB = intRound(poseKeypoints[indexSecondary]);
const auto yB = intRound(poseKeypoints[indexSecondary+1]);
int x;
int y;
if (poseKeypoints[indexMain+2] > isVisible && poseKeypoints[indexSecondary+2] > isVisible)
const auto indexMain = i * poseKeypointsArea;
const auto indexSecondary = i * poseKeypointsArea + poseKeypoints.getSize(2);
if (poseKeypoints[indexMain+2] > isVisible || poseKeypoints[indexSecondary+2] > isVisible)
{
const auto keypointRatio = intRound(0.15f * std::sqrt((xA-xB)*(xA-xB) + (yA-yB)*(yA-yB)));
x = xA + 3*keypointRatio;
y = yA - 3*keypointRatio;
const auto xA = intRound(poseKeypoints[indexMain]);
const auto yA = intRound(poseKeypoints[indexMain+1]);
const auto xB = intRound(poseKeypoints[indexSecondary]);
const auto yB = intRound(poseKeypoints[indexSecondary+1]);
int x;
int y;
if (poseKeypoints[indexMain+2] > isVisible && poseKeypoints[indexSecondary+2] > isVisible)
{
const auto keypointRatio = intRound(0.15f * std::sqrt((xA-xB)*(xA-xB) + (yA-yB)*(yA-yB)));
x = xA + 3*keypointRatio;
y = yA - 3*keypointRatio;
}
else if (poseKeypoints[indexMain+2] > isVisible)
{
x = xA + intRound(0.25f*borderMargin);
y = yA - intRound(0.25f*borderMargin);
}
else //if (poseKeypoints[indexSecondary+2] > isVisible)
{
x = xB + intRound(0.25f*borderMargin);
y = yB - intRound(0.5f*borderMargin);
}
putTextOnCvMat(cvOutputData, std::to_string(poseIds[i]), {x, y}, WHITE_SCALAR, false, cvOutputData.cols);
}
else if (poseKeypoints[indexMain+2] > isVisible)
{
x = xA + intRound(0.25f*borderMargin);
y = yA - intRound(0.25f*borderMargin);
}
else //if (poseKeypoints[indexSecondary+2] > isVisible)
{
x = xB + intRound(0.25f*borderMargin);
y = yB - intRound(0.5f*borderMargin);
}
putTextOnCvMat(cvOutputData, std::to_string(poseIds[i]), {x, y}, WHITE_SCALAR, false, cvOutputData.cols);
}
}
}
......
......@@ -8,7 +8,7 @@ namespace op
PoseExtractor::PoseExtractor(const std::shared_ptr<PoseExtractorNet>& poseExtractorNet,
const std::shared_ptr<KeepTopNPeople>& keepTopNPeople,
const std::shared_ptr<PersonIdExtractor>& personIdExtractor,
const std::vector<std::shared_ptr<PersonTracker>>& personTrackers,
const std::shared_ptr<std::vector<std::shared_ptr<PersonTracker>>>& personTrackers,
const int numberPeopleMax, const int tracking) :
mNumberPeopleMax{numberPeopleMax},
mTracking{tracking},
......@@ -174,13 +174,17 @@ namespace op
{
try
{
if (!spPersonTrackers.empty() && spPersonTrackers.at(imageViewIndex))
if (!spPersonTrackers->empty())
{
// Resize if required
while (spPersonTrackers->size() <= imageViewIndex)
spPersonTrackers->emplace_back(std::make_shared<PersonTracker>(
(*spPersonTrackers)[0]->getMergeResults()));
// Security check
if (!poseKeypoints.empty() && poseIds.empty() && mNumberPeopleMax != 1)
error(errorMessage, __LINE__, __FUNCTION__, __FILE__);
// Run person ID extractor
spPersonTrackers[imageViewIndex]->track(
(*spPersonTrackers)[imageViewIndex]->track(
poseKeypoints, cvMatInput, (poseIds.empty() ? Array<long long>{1, 0} : poseIds));
}
}
......@@ -196,13 +200,17 @@ namespace op
{
try
{
if (!spPersonTrackers.empty() && spPersonTrackers.at(imageViewIndex))
if (!spPersonTrackers->empty())
{
// Resize if required
while (spPersonTrackers->size() <= imageViewIndex)
spPersonTrackers->emplace_back(std::make_shared<PersonTracker>(
(*spPersonTrackers)[0]->getMergeResults()));
// Security check
if (!poseKeypoints.empty() && poseIds.empty() && mNumberPeopleMax != 1)
error(errorMessage, __LINE__, __FUNCTION__, __FILE__);
// Run person ID extractor
spPersonTrackers[imageViewIndex]->trackLockThread(
(*spPersonTrackers)[imageViewIndex]->trackLockThread(
poseKeypoints, cvMatInput, (poseIds.empty() ? Array<long long>{1, 0} : poseIds),
frameId);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册