我正在使用opencv lib中的gpu::rotate来旋转clockwize图像。
#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 );
}
输入图片
输出图像
我总是黑线,我测试了多个移位坐标和插值方法。
我在opencv源代码中找不到真正的cuda对应代码opencv \ modules \ gpu \ src \ imgproc.cpp
答案 0 :(得分:0)
我已经使用cuda-10.0构建了opencv-3.4,并且以下代码在我的ubuntu-16.04系统上正常工作。
#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 );
}