Reputation: 2404
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
Upvotes: 3
Views: 3963
Reputation: 46
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 );
}
Upvotes: 1