使用opencv在GPU上调整图像大小会产生空的输出矩阵

Resizing image on GPU with opencv produces empty output matrix

本文关键字:输出 GPU opencv 调整 图像 使用      更新时间:2023-10-16

我正在运行这个简单的应用程序,以在GTX1080ti GPU:上执行图像大小调整

#include <opencv2/opencv.hpp>
#include "opencv2/cudaimgproc.hpp"
#include "opencv2/cudawarping.hpp"
using namespace std;
using namespace cv;
using namespace cv::cuda;
static void gpuResize(Mat in, Mat out){
double k = in.cols/416.;
cuda::GpuMat gpuInImage;
cuda::GpuMat gpuOutImage;
gpuInImage.upload(in);
const Size2i &newSize = Size(416, in.rows / k);
cout << "newSize " << newSize<< endl;
cuda::resize(gpuInImage, gpuOutImage, newSize);
gpuOutImage.download(out);
}
int main(){
Mat im = Mat::zeros(Size(832,832),CV_8UC3);
Mat out;
if (getCudaEnabledDeviceCount() == 0){
return cerr << "No GPU found or the library is compiled without CUDA support" << endl, -1;
}
cv::cuda::printShortCudaDeviceInfo(cv::cuda::getDevice());
gpuResize(im,out);
cout << "real size="<<out.size() <<endl;
}

我得到的输出:

Device 0:  "GeForce GTX 1080 Ti"  11177Mb, sm_61, Driver/Runtime ver.10.10/10.10
newSize [416 x 416]
real size=[0 x 0]

为什么输出矩阵的大小为0x0,我应该如何修复?

这看起来像是一个解析函数的问题。函数将修改其本地副本,一旦函数返回。原始输出尚未修改。尝试通过引用进行解析。