| 16 | DEFINE_string(image_path, "examples/media/COCO_val2014_000000000192.jpg", "Process the desired image."); |
| 17 | |
| 18 | cv::Mat gpuResize(cv::Mat& img, const cv::Size& newSize) |
| 19 | { |
| 20 | #if defined USE_CAFFE && defined USE_CUDA |
| 21 | // Upload to Source to GPU |
| 22 | float* cpuPtr = &img.at<float>(0); |
| 23 | float* gpuPtr; |
| 24 | cudaMallocHost((void **)&gpuPtr, img.size().width * img.size().height * sizeof(float)); |
| 25 | cudaMemcpy(gpuPtr, cpuPtr, img.size().width * img.size().height * sizeof(float), |
| 26 | cudaMemcpyHostToDevice); |
| 27 | |
| 28 | // Upload to Dest to GPU |
| 29 | cv::Mat newImg = cv::Mat(newSize,CV_32FC1,cv::Scalar(0)); |
| 30 | float* newCpuPtr = &newImg.at<float>(0); |
| 31 | float* newGpuPtr; |
| 32 | cudaMallocHost((void **)&newGpuPtr, newSize.width * newSize.height * sizeof(float)); |
| 33 | cudaMemcpy(newGpuPtr, newCpuPtr, newSize.width * newSize.height * sizeof(float), |
| 34 | cudaMemcpyHostToDevice); |
| 35 | |
| 36 | std::vector<const float*> sourcePtrs; |
| 37 | sourcePtrs.emplace_back(gpuPtr); |
| 38 | std::array<int, 4> targetSize = {1,1,newImg.size().height,newImg.size().width}; |
| 39 | std::array<int, 4> sourceSize = {1,1,img.size().height,img.size().width}; |
| 40 | std::vector<std::array<int, 4>> sourceSizes; |
| 41 | sourceSizes.emplace_back(sourceSize); |
| 42 | op::resizeAndMergeGpu(newGpuPtr, sourcePtrs, targetSize, sourceSizes); |
| 43 | cudaMemcpy(newCpuPtr, newGpuPtr, newImg.size().width * newImg.size().height * sizeof(float), |
| 44 | cudaMemcpyDeviceToHost); |
| 45 | |
| 46 | cudaFree(gpuPtr); |
| 47 | cudaFree(newGpuPtr); |
| 48 | return newImg; |
| 49 | #else |
| 50 | UNUSED(img); |
| 51 | UNUSED(newSize); |
| 52 | op::error("OpenPose must be compiled with the `USE_CAFFE` & `USE_CUDA` macro definitions in order to run" |
| 53 | " this functionality.", __LINE__, __FUNCTION__, __FILE__); |
| 54 | return cv::Mat(); |
| 55 | #endif |
| 56 | } |
| 57 | |
| 58 | cv::Mat cpuResize(cv::Mat& img, cv::Size newSize) |
| 59 | { |
no test coverage detected