Exemplo n.º 1
0
 void WKeypointScaler<TDatums>::work(TDatums& tDatums)
 {
     try
     {
         if (checkNoNullNorEmpty(tDatums))
         {
             // Debugging log
             dLog("", Priority::Low, __LINE__, __FUNCTION__, __FILE__);
             // Profiling speed
             const auto profilerKey = Profiler::timerInit(__LINE__, __FUNCTION__, __FILE__);
             // Rescale pose data
             for (auto& tDatum : *tDatums)
             {
                 std::vector<Array<float>> arraysToScale{tDatum.poseKeypoints, tDatum.handKeypoints[0],
                                                         tDatum.handKeypoints[1], tDatum.faceKeypoints};
                 spKeypointScaler->scale(arraysToScale, tDatum.scaleInputToOutput, tDatum.scaleNetToOutput,
                                         Point<int>{tDatum.cvInputData.cols, tDatum.cvInputData.rows});
                 // Rescale part candidates
                 spKeypointScaler->scale(tDatum.poseCandidates, tDatum.scaleInputToOutput, tDatum.scaleNetToOutput,
                                         Point<int>{tDatum.cvInputData.cols, tDatum.cvInputData.rows});
             }
             // Profiling speed
             Profiler::timerEnd(profilerKey);
             Profiler::printAveragedTimeMsOnIterationX(profilerKey, __LINE__, __FUNCTION__, __FILE__);
             // Debugging log
             dLog("", Priority::Low, __LINE__, __FUNCTION__, __FILE__);
         }
     }
     catch (const std::exception& e)
     {
         this->stop();
         tDatums = nullptr;
         error(e.what(), __LINE__, __FUNCTION__, __FILE__);
     }
 }
Exemplo n.º 2
0
 void WHandRenderer<TDatums>::work(TDatums& tDatums)
 {
     try
     {
         if (checkNoNullNorEmpty(tDatums))
         {
             // Debugging log
             dLog("", Priority::Low, __LINE__, __FUNCTION__, __FILE__);
             // Profiling speed
             const auto profilerKey = Profiler::timerInit(__LINE__, __FUNCTION__, __FILE__);
             // Render people hands
             for (auto& tDatum : *tDatums)
                 spHandRenderer->renderHand(tDatum.outputData, tDatum.handKeypoints);
             // Profiling speed
             Profiler::timerEnd(profilerKey);
             Profiler::printAveragedTimeMsOnIterationX(profilerKey, __LINE__, __FUNCTION__, __FILE__);
             // Debugging log
             dLog("", Priority::Low, __LINE__, __FUNCTION__, __FILE__);
         }
     }
     catch (const std::exception& e)
     {
         this->stop();
         tDatums = nullptr;
         error(e.what(), __LINE__, __FUNCTION__, __FILE__);
     }
 }
Exemplo n.º 3
0
 void WJointAngleEstimation<TDatums>::work(TDatums& tDatums)
 {
     try
     {
         if (checkNoNullNorEmpty(tDatums))
         {
             // Debugging log
             dLog("", Priority::Low, __LINE__, __FUNCTION__, __FILE__);
             // Profiling speed
             const auto profilerKey = Profiler::timerInit(__LINE__, __FUNCTION__, __FILE__);
             // Input
             auto& datum = tDatums->at(0);
             const auto& poseKeypoints3D = datum.poseKeypoints3D;
             const auto& faceKeypoints3D = datum.faceKeypoints3D;
             const auto& handKeypoints3D = datum.handKeypoints3D;
             // Running Adam model
             spJointAngleEstimation->adamFastFit(
                 datum.adamPose, datum.adamTranslation, datum.vtVec, datum.j0Vec,
                 datum.adamFaceCoeffsExp, poseKeypoints3D, faceKeypoints3D, handKeypoints3D);
             // Profiling speed
             Profiler::timerEnd(profilerKey);
             Profiler::printAveragedTimeMsOnIterationX(profilerKey, __LINE__, __FUNCTION__, __FILE__);
             // Debugging log
             dLog("", Priority::Low, __LINE__, __FUNCTION__, __FILE__);
         }
     }
     catch (const std::exception& e)
     {
         this->stop();
         tDatums = nullptr;
         error(e.what(), __LINE__, __FUNCTION__, __FILE__);
     }
 }
Exemplo n.º 4
0
 void WPoseSaver<TDatums>::workConsumer(const TDatums& tDatums)
 {
     try
     {
         if (checkNoNullNorEmpty(tDatums))
         {
             // Debugging log
             dLog("", Priority::Low, __LINE__, __FUNCTION__, __FILE__);
             // Profiling speed
             const auto profilerKey = Profiler::timerInit(__LINE__, __FUNCTION__, __FILE__);
             // T* to T
             auto& tDatumsNoPtr = *tDatums;
             // Record people pose keypoint data
             std::vector<Array<float>> keypointVector(tDatumsNoPtr.size());
             for (auto i = 0u; i < tDatumsNoPtr.size(); i++)
                 keypointVector[i] = tDatumsNoPtr[i].poseKeypoints;
             const auto fileName = (!tDatumsNoPtr[0].name.empty() ? tDatumsNoPtr[0].name : std::to_string(tDatumsNoPtr[0].id));
             spKeypointSaver->saveKeypoints(keypointVector, fileName, "pose");
             // Profiling speed
             Profiler::timerEnd(profilerKey);
             Profiler::printAveragedTimeMsOnIterationX(profilerKey, __LINE__, __FUNCTION__, __FILE__);
             // Debugging log
             dLog("", Priority::Low, __LINE__, __FUNCTION__, __FILE__);
         }
     }
     catch (const std::exception& e)
     {
         this->stop();
         error(e.what(), __LINE__, __FUNCTION__, __FILE__);
     }
 }
Exemplo n.º 5
0
 void WFaceExtractor<TDatums>::work(TDatums& tDatums)
 {
     try
     {
         if (checkNoNullNorEmpty(tDatums))
         {
             // Debugging log
             dLog("", Priority::Low, __LINE__, __FUNCTION__, __FILE__);
             // Profiling speed
             const auto profilerKey = Profiler::timerInit(__LINE__, __FUNCTION__, __FILE__);
             // Extract people face
             for (auto& tDatum : *tDatums)
             {
                 spFaceExtractor->forwardPass(tDatum.faceRectangles, tDatum.cvInputData, tDatum.scaleInputToOutput);
                 tDatum.faceKeypoints = spFaceExtractor->getFaceKeypoints();
             }
             // Profiling speed
             Profiler::timerEnd(profilerKey);
             Profiler::printAveragedTimeMsOnIterationX(profilerKey, __LINE__, __FUNCTION__, __FILE__, Profiler::DEFAULT_X);
             // Debugging log
             dLog("", Priority::Low, __LINE__, __FUNCTION__, __FILE__);
         }
     }
     catch (const std::exception& e)
     {
         this->stop();
         tDatums = nullptr;
         error(e.what(), __LINE__, __FUNCTION__, __FILE__);
     }
 }
Exemplo n.º 6
0
 void WCvMatToOpInput<TDatums>::work(TDatums& tDatums)
 {
     try
     {
         if (checkNoNullNorEmpty(tDatums))
         {
             // Debugging log
             dLog("", Priority::Low, __LINE__, __FUNCTION__, __FILE__);
             // Profiling speed
             const auto profilerKey = Profiler::timerInit(__LINE__, __FUNCTION__, __FILE__);
             // cv::Mat -> float*
             for (auto& tDatum : *tDatums)
                 tDatum.inputNetData = spCvMatToOpInput->createArray(tDatum.cvInputData,
                                                                     tDatum.scaleInputToNetInputs,
                                                                     tDatum.netInputSizes);
             // Profiling speed
             Profiler::timerEnd(profilerKey);
             Profiler::printAveragedTimeMsOnIterationX(profilerKey, __LINE__, __FUNCTION__, __FILE__);
             // Debugging log
             dLog("", Priority::Low, __LINE__, __FUNCTION__, __FILE__);
         }
     }
     catch (const std::exception& e)
     {
         this->stop();
         tDatums = nullptr;
         error(e.what(), __LINE__, __FUNCTION__, __FILE__);
     }
 }
Exemplo n.º 7
0
 void WIdGenerator<TDatums>::work(TDatums& tDatums)
 {
     try
     {
         if (checkNoNullNorEmpty(tDatums))
         {
             // Debugging log
             dLog("", Priority::Low, __LINE__, __FUNCTION__, __FILE__);
             // Profiling speed
             const auto profilerKey = Profiler::timerInit(__LINE__, __FUNCTION__, __FILE__);
             // Add ID
             for (auto& tDatum : *tDatums)
                 // To avoid overwritting ID if e.g., custom input has already filled it
                 if (tDatum.id == std::numeric_limits<unsigned long long>::max())
                     tDatum.id = mGlobalCounter;
             // Increase ID
             const auto& tDatum = (*tDatums)[0];
             if (tDatum.subId == tDatum.subIdMax)
                 mGlobalCounter++;
             // Profiling speed
             Profiler::timerEnd(profilerKey);
             Profiler::printAveragedTimeMsOnIterationX(profilerKey, __LINE__, __FUNCTION__, __FILE__);
             // Debugging log
             dLog("", Priority::Low, __LINE__, __FUNCTION__, __FILE__);
         }
     }
     catch (const std::exception& e)
     {
         this->stop();
         tDatums = nullptr;
         error(e.what(), __LINE__, __FUNCTION__, __FILE__);
     }
 }
Exemplo n.º 8
0
 void WHandDetectorTracking<TDatums>::work(TDatums& tDatums)
 {
     try
     {
         if (checkNoNullNorEmpty(tDatums))
         {
             // Debugging log
             dLog("", Priority::Low, __LINE__, __FUNCTION__, __FILE__);
             // Profiling speed
             const auto profilerKey = Profiler::timerInit(__LINE__, __FUNCTION__, __FILE__);
             // Detect people hand
             for (auto& tDatum : *tDatums)
                 tDatum.handRectangles = spHandDetector->trackHands(tDatum.poseKeypoints);
             // Profiling speed
             Profiler::timerEnd(profilerKey);
             Profiler::printAveragedTimeMsOnIterationX(profilerKey, __LINE__, __FUNCTION__, __FILE__);
             // Debugging log
             dLog("", Priority::Low, __LINE__, __FUNCTION__, __FILE__);
         }
     }
     catch (const std::exception& e)
     {
         this->stop();
         tDatums = nullptr;
         error(e.what(), __LINE__, __FUNCTION__, __FILE__);
     }
 }
Exemplo n.º 9
0
 void WCvMatToOpOutput<TDatums>::work(TDatums& tDatums)
 {
     try
     {
         if (checkNoNullNorEmpty(tDatums))
         {
             // Debugging log
             dLog("", Priority::Low, __LINE__, __FUNCTION__, __FILE__);
             // T* to T
             auto& tDatumsNoPtr = *tDatums;
             // Profiling speed
             const auto profilerKey = Profiler::timerInit(__LINE__, __FUNCTION__, __FILE__);
             // cv::Mat -> float*
             for (auto& tDatum : tDatumsNoPtr)
                 std::tie(tDatum.scaleInputToOutput, tDatum.outputData) = spCvMatToOpOutput->format(tDatum.cvInputData);
             // Profiling speed
             Profiler::timerEnd(profilerKey);
             Profiler::printAveragedTimeMsOnIterationX(profilerKey, __LINE__, __FUNCTION__, __FILE__, Profiler::DEFAULT_X);
             // Debugging log
             dLog("", Priority::Low, __LINE__, __FUNCTION__, __FILE__);
         }
     }
     catch (const std::exception& e)
     {
         this->stop();
         tDatums = nullptr;
         error(e.what(), __LINE__, __FUNCTION__, __FILE__);
     }
 }
Exemplo n.º 10
0
 void WCocoJsonSaver<TDatums>::workConsumer(const TDatums& tDatums)
 {
     try
     {
         if (checkNoNullNorEmpty(tDatums))
         {
             // Check tDatums->size() == 1
             if (tDatums->size() > 1)
                 error("Function only ready for tDatums->size() == 1", __LINE__, __FUNCTION__, __FILE__);
             // Debugging log
             dLog("", Priority::Low, __LINE__, __FUNCTION__, __FILE__);
             // Profiling speed
             const auto profilerKey = Profiler::timerInit(__LINE__, __FUNCTION__, __FILE__);
             // T* to T
             const auto& tDatum = tDatums->at(0);
             // Record json in COCO format
             const std::string stringToRemove = "COCO_val2014_";
             const auto stringToRemoveEnd = tDatum.name.find(stringToRemove) + stringToRemove.size();
             const auto imageId = std::stoull(tDatum.name.substr(stringToRemoveEnd, tDatum.name.size() - stringToRemoveEnd));
             // Record json in COCO format if file within desired range of images
             spCocoJsonSaver->record(tDatum.poseKeypoints, imageId);
             // Profiling speed
             Profiler::timerEnd(profilerKey);
             Profiler::printAveragedTimeMsOnIterationX(profilerKey, __LINE__, __FUNCTION__, __FILE__, Profiler::DEFAULT_X);
             // Debugging log
             dLog("", Priority::Low, __LINE__, __FUNCTION__, __FILE__);
         }
     }
     catch (const std::exception& e)
     {
         this->stop();
         error(e.what(), __LINE__, __FUNCTION__, __FILE__);
     }
 }
Exemplo n.º 11
0
 void WVideoSaver<TDatums>::workConsumer(const TDatums& tDatums)
 {
     try
     {
         if (checkNoNullNorEmpty(tDatums))
         {
             // Debugging log
             dLog("", Priority::Low, __LINE__, __FUNCTION__, __FILE__);
             // Profiling speed
             const auto profilerKey = Profiler::timerInit(__LINE__, __FUNCTION__, __FILE__);
             // T* to T
             auto& tDatumsNoPtr = *tDatums;
             // Record video(s)
             std::vector<cv::Mat> cvOutputDatas(tDatumsNoPtr.size());
             for (auto i = 0u ; i < cvOutputDatas.size() ; i++)
                 cvOutputDatas[i] = tDatumsNoPtr[i].cvOutputData;
             spVideoSaver->write(cvOutputDatas);
             // Profiling speed
             Profiler::timerEnd(profilerKey);
             Profiler::printAveragedTimeMsOnIterationX(profilerKey, __LINE__, __FUNCTION__, __FILE__);
             // Debugging log
             dLog("", Priority::Low, __LINE__, __FUNCTION__, __FILE__);
         }
     }
     catch (const std::exception& e)
     {
         this->stop();
         error(e.what(), __LINE__, __FUNCTION__, __FILE__);
     }
 }
Exemplo n.º 12
0
long PAlgebra::coordinate(long i, long k) const
{
    long t = ith_rep(k); // element of Zm^* representing the k'th slot

    // dLog returns the representation of t along the generators, so the
    // i'th entry there is the coordinate relative to i'th geneator
    return dLog(t)[i];
}
Exemplo n.º 13
0
    void WUdpSender<TDatums>::workConsumer(const TDatums& tDatums)
    {
        try
        {
            if (checkNoNullNorEmpty(tDatums))
            {
                // Debugging log
                dLog("", Priority::Low, __LINE__, __FUNCTION__, __FILE__);
                // Profiling speed
                const auto profilerKey = Profiler::timerInit(__LINE__, __FUNCTION__, __FILE__);
                // Send though UDP communication
#ifdef USE_3D_ADAM_MODEL
                const auto& tDatum = (*tDatums)[0];
                if (!tDatum.poseKeypoints3D.empty())
                {
                    const auto& adamPose = tDatum.adamPose; // Eigen::Matrix<double, 62, 3, Eigen::RowMajor>
                    const auto& adamTranslation = tDatum.adamTranslation; // Eigen::Vector3d(3, 1)
                    const auto adamFaceCoeffsExp = tDatum.adamFaceCoeffsExp; // Eigen::VectorXd resized to (200, 1)
                    //const float mouth_open = tDatum.mouthOpening; // tDatum.mouth_open;
                    //const float leye_open = tDatum.rightEyeOpening; // tDatum.leye_open;
                    //const float reye_open = tDatum.leftEyeOpening; // tDatum.reye_open;
                    //const float dist_root_foot = Datum.distanceRootFoot; // tDatum.dist_root_foot;
                    // m_adam_t:
                    //     1. Total translation (centimeters) of the root in camera/global coordinate representation.
                    // m_adam_pose:
                    //     1. First row is global rotation, in AngleAxis representation. Radians (not degrees!)
                    //     2. Rest are joint-angles in Euler-Angle representation. Degrees.
                    spUdpSender->sendJointAngles(adamPose.data(), adamPose.rows(),
                                                 adamTranslation.data(),
                                                 adamFaceCoeffsExp.data(), adamFaceCoeffsExp.rows());
                }
#endif
                // Profiling speed
                Profiler::timerEnd(profilerKey);
                Profiler::printAveragedTimeMsOnIterationX(profilerKey, __LINE__, __FUNCTION__, __FILE__);
                // Debugging log
                dLog("", Priority::Low, __LINE__, __FUNCTION__, __FILE__);
            }
        }
        catch (const std::exception& e)
        {
            this->stop();
            error(e.what(), __LINE__, __FUNCTION__, __FILE__);
        }
    }