#ifndef OPENPOSE_3D_W_POSE_TRIANGULATION_HPP #define OPENPOSE_3D_W_POSE_TRIANGULATION_HPP #include #include #include namespace op { template class WPoseTriangulation : public Worker { public: explicit WPoseTriangulation(const std::shared_ptr& poseTriangulation); virtual ~WPoseTriangulation(); void initializationOnThread(); void work(TDatums& tDatums); private: const std::shared_ptr spPoseTriangulation; DELETE_COPY(WPoseTriangulation); }; } // Implementation #include namespace op { template WPoseTriangulation::WPoseTriangulation(const std::shared_ptr& poseTriangulation) : spPoseTriangulation{poseTriangulation} { } template WPoseTriangulation::~WPoseTriangulation() { } template void WPoseTriangulation::initializationOnThread() { try { spPoseTriangulation->initializationOnThread(); } catch (const std::exception& e) { error(e.what(), __LINE__, __FUNCTION__, __FILE__); } } template void WPoseTriangulation::work(TDatums& tDatums) { try { if (checkNoNullNorEmpty(tDatums)) { // Debugging log opLogIfDebug("", Priority::Low, __LINE__, __FUNCTION__, __FILE__); // Profiling speed const auto profilerKey = Profiler::timerInit(__LINE__, __FUNCTION__, __FILE__); // 3-D triangulation and reconstruction std::vector cameraMatrices; std::vector> poseKeypointVector; std::vector> faceKeypointVector; std::vector> leftHandKeypointVector; std::vector> rightHandKeypointVector; std::vector> imageSizes; for (auto& tDatumPtr : *tDatums) { poseKeypointVector.emplace_back(tDatumPtr->poseKeypoints); faceKeypointVector.emplace_back(tDatumPtr->faceKeypoints); leftHandKeypointVector.emplace_back(tDatumPtr->handKeypoints[0]); rightHandKeypointVector.emplace_back(tDatumPtr->handKeypoints[1]); cameraMatrices.emplace_back(tDatumPtr->cameraMatrix); imageSizes.emplace_back( Point{tDatumPtr->cvInputData.cols(), tDatumPtr->cvInputData.rows()}); } // Pose 3-D reconstruction auto poseKeypoints3Ds = spPoseTriangulation->reconstructArray( {poseKeypointVector, faceKeypointVector, leftHandKeypointVector, rightHandKeypointVector}, cameraMatrices, imageSizes); // Assign to all tDatums for (auto& tDatumPtr : *tDatums) { tDatumPtr->poseKeypoints3D = poseKeypoints3Ds[0]; tDatumPtr->faceKeypoints3D = poseKeypoints3Ds[1]; tDatumPtr->handKeypoints3D[0] = poseKeypoints3Ds[2]; tDatumPtr->handKeypoints3D[1] = poseKeypoints3Ds[3]; } // Profiling speed Profiler::timerEnd(profilerKey); Profiler::printAveragedTimeMsOnIterationX(profilerKey, __LINE__, __FUNCTION__, __FILE__); // Debugging log opLogIfDebug("", Priority::Low, __LINE__, __FUNCTION__, __FILE__); } } catch (const std::exception& e) { this->stop(); tDatums = nullptr; error(e.what(), __LINE__, __FUNCTION__, __FILE__); } } COMPILE_TEMPLATE_DATUM(WPoseTriangulation); } #endif // OPENPOSE_3D_W_POSE_TRIANGULATION_HPP