简体   繁体   中英

Rotate image with opencv GPU

I'm using gpu::rotate from opencv lib to rotate clockwize an image.

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/gpu/gpu.hpp>

int main()
{
    cv::Mat im_in = cv::imread( "test.png" );

    //upload image to GPU
    cv::gpu::GpuMat gpu_im ;

    gpu_im.upload( im_in ); // RAM => GPU

    //Rotate from 90
    cv::Size size = im_in.size();
    cv::gpu::GpuMat gpu_im_rot ;
    cv::gpu::rotate( gpu_im, gpu_im_rot, cv::Size( size.height, size.width ), -90, size.height-1, 0, cv::INTER_LINEAR  );

    gpu_im_rot.download(im_in); //GPU => RAM

    cv::imwrite( "out.png", im_in );

}

Input Image

在此处输入图片说明

Output Image

在此处输入图片说明

I have always black line, I have tested multiple shift coordinate, and interpolation method.

I cannot find real cuda corresponding code in opencv source opencv\\modules\\gpu\\src\\imgproc.cpp

I have opencv-3.4 built with cuda-10.0 and the following code works fine on my ubuntu-16.04 system.

#include <iostream>
#include <iomanip>
#include "opencv2/objdetect.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/cudaobjdetect.hpp"
#include "opencv2/cudaimgproc.hpp"
#include "opencv2/cudawarping.hpp"
#include <opencv2/cudaarithm.hpp>
#include <stdio.h>

using namespace std;
using namespace cv;
using namespace cv::cuda;

int main()
{
    cv::Mat im_in = cv::imread( "test.png" );

    //upload image to GPU
    cv::cuda::GpuMat gpu_im ;

    gpu_im.upload( im_in ); // RAM => GPU

    //Rotate from 90
    cv::Size size = im_in.size();
    cv::cuda::GpuMat gpu_im_rot ;
    cv::cuda::rotate( gpu_im, gpu_im_rot, cv::Size( size.height, size.width ), -90, size.height-1, 0, cv::INTER_LINEAR  );

    gpu_im_rot.download(im_in); //GPU => RAM

    cv::imwrite( "out.png", im_in );

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM