wKeypointScaler.hpp 2.7 KB
Newer Older
1 2
#ifndef OPENPOSE_CORE_W_KEYPOINT_SCALER_HPP
#define OPENPOSE_CORE_W_KEYPOINT_SCALER_HPP
G
gineshidalgo99 已提交
3

4 5
#include <openpose/core/common.hpp>
#include <openpose/core/keypointScaler.hpp>
G
Gines Hidalgo 已提交
6
#include <openpose/thread/worker.hpp>
G
gineshidalgo99 已提交
7 8 9 10

namespace op
{
    template<typename TDatums>
11
    class WKeypointScaler : public Worker<TDatums>
G
gineshidalgo99 已提交
12 13
    {
    public:
14
        explicit WKeypointScaler(const std::shared_ptr<KeypointScaler>& keypointScaler);
G
gineshidalgo99 已提交
15 16 17 18 19 20

        void initializationOnThread();

        void work(TDatums& tDatums);

    private:
21
        std::shared_ptr<KeypointScaler> spKeypointScaler;
G
gineshidalgo99 已提交
22 23 24 25 26 27 28 29
    };
}





// Implementation
G
Gines Hidalgo 已提交
30
#include <openpose/utilities/pointerContainer.hpp>
G
gineshidalgo99 已提交
31 32 33
namespace op
{
    template<typename TDatums>
34 35
    WKeypointScaler<TDatums>::WKeypointScaler(const std::shared_ptr<KeypointScaler>& keypointScaler) :
        spKeypointScaler{keypointScaler}
G
gineshidalgo99 已提交
36 37 38 39
    {
    }

    template<typename TDatums>
40
    void WKeypointScaler<TDatums>::initializationOnThread()
G
gineshidalgo99 已提交
41 42 43 44
    {
    }

    template<typename TDatums>
45
    void WKeypointScaler<TDatums>::work(TDatums& tDatums)
G
gineshidalgo99 已提交
46 47 48 49 50 51 52 53 54 55 56 57
    {
        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)
                {
G
gineshidalgo99 已提交
58 59 60 61
                    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});
62 63 64
                    // Rescale part candidates
                    spKeypointScaler->scale(tDatum.poseCandidates, tDatum.scaleInputToOutput, tDatum.scaleNetToOutput,
                                            Point<int>{tDatum.cvInputData.cols, tDatum.cvInputData.rows});
G
gineshidalgo99 已提交
65 66 67
                }
                // Profiling speed
                Profiler::timerEnd(profilerKey);
68
                Profiler::printAveragedTimeMsOnIterationX(profilerKey, __LINE__, __FUNCTION__, __FILE__);
G
gineshidalgo99 已提交
69 70 71 72 73 74 75 76 77 78 79 80
                // Debugging log
                dLog("", Priority::Low, __LINE__, __FUNCTION__, __FILE__);
            }
        }
        catch (const std::exception& e)
        {
            this->stop();
            tDatums = nullptr;
            error(e.what(), __LINE__, __FUNCTION__, __FILE__);
        }
    }

81
    COMPILE_TEMPLATE_DATUM(WKeypointScaler);
G
gineshidalgo99 已提交
82 83
}

84
#endif // OPENPOSE_CORE_W_KEYPOINT_SCALER_HPP