cv::cuda::split 使用

x33g5p2x  于2021-12-17 转载在 其他  
字(1.6k)|赞(0)|评价(0)|浏览(422)

cv::cuda::split

error:‘split’ is not a member of ‘cv::cuda’…
error:‘resize’ is not a member of ‘cv::cuda’…

recipe for target ‘all’ faild
Incvking “make -j6 -l6” faild

这里可以通过添加对应的cv头文件解决error,比如

#include <opencv2/cudaimgproc.hpp> 
#include "opencv2/cudawarping.hpp" 
#include "opencv2/cudaarithm.hpp"
 

和tensorrt结合使用:

// preprocessing stage ------------------------------------------------------------------------------------------------
void preprocessImage(const std::string& image_path, float* gpu_input, const nvinfer1::Dims& dims)
{
    // read input image
    cv::Mat frame = cv::imread(image_path);
    if (frame.empty())
    {
        std::cerr << "Input image " << image_path << " load failed\n";
        return;
    }
    cv::cuda::GpuMat gpu_frame;
    // upload image to GPU
    gpu_frame.upload(frame);

    auto input_width = dims.d[2];
    auto input_height = dims.d[1];
    auto channels = dims.d[0];
    auto input_size = cv::Size(input_width, input_height);
    // resize
    cv::cuda::GpuMat resized;
    cv::cuda::resize(gpu_frame, resized, input_size, 0, 0, cv::INTER_NEAREST);
    // normalize
    cv::cuda::GpuMat flt_image;
    resized.convertTo(flt_image, CV_32FC3, 1.f / 255.f);
    cv::cuda::subtract(flt_image, cv::Scalar(0.485f, 0.456f, 0.406f), flt_image, cv::noArray(), -1);
    cv::cuda::divide(flt_image, cv::Scalar(0.229f, 0.224f, 0.225f), flt_image, 1, -1);
    // to tensor
    std::vector<cv::cuda::GpuMat> chw;
    for (size_t i = 0; i < channels; ++i)
    {
        chw.emplace_back(cv::cuda::GpuMat(input_size, CV_32FC1, gpu_input + i * input_width * input_height));
    }
    cv::cuda::split(flt_image, chw);
}

https://github.com/novaHardware/segmentation/blob/d86c237e1191f159d39e115df13d691ab65752c2/PyTorch-ONNX-TensorRT-CPP/trt_sample.cpp

相关文章