resizeAndMergeBase.cpp 3.2 KB
Newer Older
G
gineshidalgo99 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
// #include <opencv2/imgproc/imgproc.hpp>
#include "openpose/utilities/errorAndLog.hpp"
#include "openpose/utilities/macros.hpp"
#include "openpose/core/resizeAndMergeBase.hpp"

namespace op
{
    template <typename T>
    void resizeAndMergeCpu(T* targetPtr, const T* const sourcePtr, const std::array<int, 4>& targetSize, const std::array<int, 4>& sourceSize, const T scaleGap)
    {
        try
        {
            UNUSED(targetPtr);
            UNUSED(sourcePtr);
            UNUSED(scaleGap);
            UNUSED(targetSize);
            UNUSED(sourceSize);
            error("CPU version not completely implemented.", __LINE__, __FUNCTION__, __FILE__);

            // TODO: THIS CODE IS WORKING, BUT IT DOES NOT CONSIDER THE SCALES (I.E. SCALE NUMBER, START AND GAP) 
            // const int num = bottom->shape(0);
            // const int channel = bottom->shape(1);
            // const int sourceHeight = bottom->shape(2);
            // const int sourceWidth = bottom->shape(3);
            // const int targetHeight = top->shape(2);
            // const int targetWidth = top->shape(3);

            // //stupid method
            // for (int n = 0; n < num; n++)
            // {
            //     for (int c = 0; c < channel; c++)
            //     {
            //         //fill source
            //         cv::Mat source(sourceWidth, sourceHeight, CV_32FC1);
            //         const auto sourceOffsetChannel = sourceHeight * sourceWidth;
            //         const auto sourceOffsetNum = sourceOffsetChannel * channel;
            //         const auto sourceOffset = n*sourceOffsetNum + c*sourceOffsetChannel;
            //         const T* const sourcePtr = bottom->cpu_data();
            //         for (int y = 0; y < sourceHeight; y++)
            //             for (int x = 0; x < sourceWidth; x++)
            //                 source.at<T>(x,y) = sourcePtr[sourceOffset + y*sourceWidth + x];

            //         // spatial resize
            //         cv::Mat target;
            //         cv::resize(source, target, {targetWidth, targetHeight}, 0, 0, CV_INTER_CUBIC);

            //         //fill top
            //         const auto targetOffsetChannel = targetHeight * targetWidth;
            //         const auto targetOffsetNum = targetOffsetChannel * channel;
            //         const auto targetOffset = n*targetOffsetNum + c*targetOffsetChannel;
            //         T* targetPtr = top->mutable_cpu_data();
            //         for (int y = 0; y < targetHeight; y++)
            //             for (int x = 0; x < targetWidth; x++)
            //                 targetPtr[targetOffset + y*targetWidth + x] = target.at<T>(x,y);
            //     }
            // }
        }
        catch (const std::exception& e)
        {
            error(e.what(), __LINE__, __FUNCTION__, __FILE__);
        }
    }

    template void resizeAndMergeCpu(float* targetPtr, const float* const sourcePtr, const std::array<int, 4>& targetSize, const std::array<int, 4>& sourceSize, const float scaleGap);
    template void resizeAndMergeCpu(double* targetPtr, const double* const sourcePtr, const std::array<int, 4>& targetSize, const std::array<int, 4>& sourceSize, const double scaleGap);
}