Ask Your Question
0

How to resize image with nvidia GPU?

asked 2019-11-07 13:57:13 -0600

stiv-yakovenko gravatar image

I am running this simple application to perform image resize on 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;
}

the output I'm getting:

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]

why output matrix has 0x0 size, how should I fix that?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
3

answered 2019-11-08 04:07:34 -0600

updated 2019-11-08 04:24:52 -0600

It looks like a typo, you are not passing out by reference (or pointer), therefore everything is working as expected inside gpuResize() but Mat out; in main does not occupy the same memory location as Mat out in static void gpuResize(Mat in, Mat out). You can check this is the problem by moving cout << "real size="<<out.size() <<endl; inside gpuResize().

For simplicity I would pass by reference, that is change

static void gpuResize(Mat in, Mat out)

to

static void gpuResize(Mat in, Mat &out)

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2019-11-07 13:57:13 -0600

Seen: 4,045 times

Last updated: Nov 08 '19