提交 78531bd8 编写于 作者: G gineshidalgo99

Display of id

上级 5e22e43f
......@@ -13,7 +13,9 @@ namespace op
GuiInfoAdder(const int numberGpus, const bool guiEnabled = false);
void addInfo(cv::Mat& cvOutputData, const int numberPeople, const unsigned long long id,
const std::string& elementRenderedName, const unsigned long long frameNumber);
const std::string& elementRenderedName, const unsigned long long frameNumber,
const Array<long long>& poseIds = Array<long long>{},
const Array<float>& poseKeypoints = Array<float>{});
private:
// Const variables
......
......@@ -58,7 +58,8 @@ namespace op
for (auto& tDatum : *tDatums)
spGuiInfoAdder->addInfo(tDatum.cvOutputData, std::max(tDatum.poseKeypoints.getSize(0),
tDatum.faceKeypoints.getSize(0)),
tDatum.id, tDatum.elementRendered.second, tDatum.frameNumber);
tDatum.id, tDatum.elementRendered.second, tDatum.frameNumber,
tDatum.poseIds, tDatum.poseKeypoints);
// Profiling speed
Profiler::timerEnd(profilerKey);
Profiler::printAveragedTimeMsOnIterationX(profilerKey, __LINE__, __FUNCTION__, __FILE__);
......
......@@ -7,6 +7,9 @@
namespace op
{
// Used colors
const cv::Scalar WHITE_SCALAR{255, 255, 255};
void updateFps(unsigned long long& lastId, double& fps, unsigned int& fpsCounter,
std::queue<std::chrono::high_resolution_clock::time_point>& fpsQueue,
const unsigned long long id, const int numberGpus)
......@@ -49,6 +52,54 @@ namespace op
}
}
void addPeopleIds(cv::Mat& cvOutputData, const Array<long long>& poseIds, const Array<float>& poseKeypoints,
const int borderMargin)
{
try
{
if (!poseIds.empty())
{
const auto poseKeypointsArea = poseKeypoints.getSize(1)*poseKeypoints.getSize(2);
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)
{
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);
}
}
}
}
catch (const std::exception& e)
{
error(e.what(), __LINE__, __FUNCTION__, __FILE__);
}
}
GuiInfoAdder::GuiInfoAdder(const int numberGpus, const bool guiEnabled) :
mNumberGpus{numberGpus},
mGuiEnabled{guiEnabled},
......@@ -59,7 +110,8 @@ namespace op
}
void GuiInfoAdder::addInfo(cv::Mat& cvOutputData, const int numberPeople, const unsigned long long id,
const std::string& elementRenderedName, const unsigned long long frameNumber)
const std::string& elementRenderedName, const unsigned long long frameNumber,
const Array<long long>& poseIds, const Array<float>& poseKeypoints)
{
try
{
......@@ -70,15 +122,13 @@ namespace op
const auto borderMargin = intRound(fastMax(cvOutputData.cols, cvOutputData.rows) * 0.025);
// Update fps
updateFps(mLastId, mFps, mFpsCounter, mFpsQueue, id, mNumberGpus);
// Used colors
const cv::Scalar white{255, 255, 255};
// Fps or s/gpu
char charArrayAux[15];
std::snprintf(charArrayAux, 15, "%4.1f fps", mFps);
// Recording inverse: sec/gpu
// std::snprintf(charArrayAux, 15, "%4.2f s/gpu", (mFps != 0. ? mNumberGpus/mFps : 0.));
putTextOnCvMat(cvOutputData, charArrayAux, {intRound(cvOutputData.cols - borderMargin), borderMargin},
white, true, cvOutputData.cols);
WHITE_SCALAR, true, cvOutputData.cols);
// Part to show
// Allowing some buffer when changing the part to show (if >= 2 GPUs)
// I.e. one GPU might return a previous part after the other GPU returns the new desired part, it looks
......@@ -92,18 +142,20 @@ namespace op
}
mLastElementRenderedCounter = fastMin(mLastElementRenderedCounter, std::numeric_limits<int>::max() - 5);
mLastElementRenderedCounter++;
// Add each person ID
addPeopleIds(cvOutputData, poseIds, poseKeypoints, borderMargin);
// OpenPose name as well as help or part to show
putTextOnCvMat(cvOutputData, "OpenPose - " +
(!mLastElementRenderedName.empty() ?
mLastElementRenderedName : (mGuiEnabled ? "'h' for help" : "")),
{borderMargin, borderMargin}, white, false, cvOutputData.cols);
{borderMargin, borderMargin}, WHITE_SCALAR, false, cvOutputData.cols);
// Frame number
putTextOnCvMat(cvOutputData, "Frame: " + std::to_string(frameNumber),
{borderMargin, (int)(cvOutputData.rows - borderMargin)}, white, false, cvOutputData.cols);
{borderMargin, (int)(cvOutputData.rows - borderMargin)}, WHITE_SCALAR, false, cvOutputData.cols);
// Number people
putTextOnCvMat(cvOutputData, "People: " + std::to_string(numberPeople),
{(int)(cvOutputData.cols - borderMargin), (int)(cvOutputData.rows - borderMargin)},
white, true, cvOutputData.cols);
WHITE_SCALAR, true, cvOutputData.cols);
}
catch (const std::exception& e)
{
......
......@@ -189,9 +189,9 @@ ifeq ($(USE_OPENCV), 1)
LIBRARIES += opencv_core opencv_highgui opencv_imgproc opencv_objdetect
ifeq ($(OPENCV_VERSION), 3)
LIBRARIES += opencv_imgcodecs opencv_videoio
LIBRARIES += opencv_imgcodecs opencv_videoio opencv_cudawarping
else
LIBRARIES += opencv_contrib
LIBRARIES += opencv_contrib opencv_gpu
endif
endif
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册