使用opencv在GPU上调整图像大小会产生空的输出矩阵
Resizing image on GPU with opencv produces empty output matrix
我正在运行这个简单的应用程序,以在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,我应该如何修复?
这看起来像是一个解析函数的问题。函数将修改其本地副本,一旦函数返回。原始输出尚未修改。尝试通过引用进行解析。
相关文章:
- 递归函数计算序列中的平方和(并输出过程)
- 如何使用 < 和 > 命令获取 c++ 中的输入和输出?
- 请解释"函数1(p1,p2,p3);"的输出
- C++:将控制台输出存储在宏中更好吗
- 创建一个函数以在输入为负数或零时输出字符串.第一次执行用户定义的函数
- 如何在OMNET++中指定与命令行参数组合的输出文件名
- 为什么我的代码在输出中增加了93天
- 如何从void函数输出字符串
- 输入到文件并输出到另一个文件,并将流文件传递给函数
- AES加密到解密未正确输出
- 如何将c++程序的一些输出传递给shell,以便在shell中使用
- 使用C++程序合并排序没有得到正确的输出
- 为什么我不能在不创建字符串变量的情况下使用函数的字符串输出
- C++格式化输出问题
- 将值从二维数组输出到文本文件
- 集合上的输出迭代器:assign和increment迭代器
- 在while循环中输入带有std::cin的字符串后,控制台会输出大量胡言乱语
- 为什么rk4.do_step不输出C++中的初始条件
- 有没有办法简单地从 GPU 调用多个 cpp 输出文件?
- 使用opencv在GPU上调整图像大小会产生空的输出矩阵