Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用OpenCV和CUDA编译高斯滤波器代码时出错_Opencv_Cmake - Fatal编程技术网

使用OpenCV和CUDA编译高斯滤波器代码时出错

使用OpenCV和CUDA编译高斯滤波器代码时出错,opencv,cmake,Opencv,Cmake,当我使用Cmake编译此代码时。。这个错误向我表明了。。。。 我试图删除CUDA并重新安装,但它是一样的 #include "iostream" #include "stdio.h" #include "stdlib.h" #include "opencv2/imgproc.hpp" #include "opencv2/highgui.hpp" #include "opencv2/core/cuda.hpp" #include "opencv2/cudaimgproc.hpp" #include

当我使用Cmake编译此代码时。。这个错误向我表明了。。。。 我试图删除CUDA并重新安装,但它是一样的

#include "iostream"
#include "stdio.h"
#include "stdlib.h"
#include "opencv2/imgproc.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/core/cuda.hpp"
#include "opencv2/cudaimgproc.hpp"
#include "opencv2/cudafilters.hpp" // cv::cuda::Filter
#include "opencv2/cudaarithm.hpp" // cv::cuda::abs orcv::cuda::addWeighted
#include "timer.h"


using namespace std;
using namespace cv;

void processUsingOpenCvCpu(std::string nput_file, std::string output_file);
void processUsingOpenCvGpu(std::string input_file, std::string output_file);
void processUsingCuda(std::string input_file, std::string output_file);

int main(int argc, char **argv) {

const string input_file = argc >= 2 ? argv[1] : "evarest.jpg";
const string output_file_OpenCvCpu = argc >= 3 ? argv[2] : "output_OpenCvCpu.jpg";
const string output_file_OpenCvGpu = argc >= 4 ? argv[3] : "output_OpenCvGpu.jpg";
const string output_file_Cuda = argc >= 5 ? argv[2] : "output_Cuda.jpg";

for (int i=0; i<5; ++i) {
    processUsingOpenCvCpu(input_file, output_file_OpenCvCpu);
    processUsingOpenCvGpu(input_file, output_file_OpenCvGpu);
    //processUsingCuda(input_file, output_file_Cuda);
}
return 0;
}

void processUsingOpenCvGpu(std::string input_file, std::string output_file) {
//Read input image from the disk
Mat input = imread(input_file, CV_LOAD_IMAGE_COLOR);
Mat output;
if(input.empty())
{
    std::cout<<"Image Not Found: "<< input_file << std::endl;
    return;
}

GpuTimer timer;
timer.Start();

// copy the input image from CPU to GPU memory
cuda::GpuMat gpuInput = cuda::GpuMat(input);

// blur the input image to remove the noise
Ptr<cv::cuda::Filter> filter = cv::cuda::createGaussianFilter(gpuInput.type(), gpuInput.type(), Size(3,3), 0);
filter->apply(gpuInput, gpuInput);

// convert it to grayscale (CV_8UC3 -> CV_8UC1)
cv::cuda::GpuMat gpuInput_gray;
cv::cuda::cvtColor( gpuInput, gpuInput_gray, COLOR_RGB2GRAY );

// compute the gradients on both directions x and y
cv::cuda::GpuMat gpuGrad_x, gpuGrad_y;
cv::cuda::GpuMat abs_gpuGrad_x, abs_gpuGrad_y;
int scale = 1;
int ddepth = CV_16S; // use 16 bits unsigned to avoid overflow

// gradient x direction
filter = cv::cuda::createSobelFilter(gpuInput_gray.type(), ddepth, 1, 0, 3, scale, BORDER_DEFAULT);
filter->apply(gpuInput_gray, gpuGrad_x);
cv::cuda::abs(gpuGrad_x, gpuGrad_x);
gpuGrad_x.convertTo(abs_gpuGrad_x, CV_8UC1); // CV_16S -> CV_8U

// gradient y direction
filter = cv::cuda::createSobelFilter(gpuInput_gray.type(), ddepth, 0, 1, 3, scale, BORDER_DEFAULT);
filter->apply(gpuInput_gray, gpuGrad_y);
cv::cuda::abs(gpuGrad_y, gpuGrad_y);
gpuGrad_y.convertTo(abs_gpuGrad_y, CV_8UC1); // CV_16S -> CV_8U

// create the output by adding the absolute gradient images of each x and y direction
cv::cuda::GpuMat gpuOutput;
cv::cuda::addWeighted( abs_gpuGrad_x, 0.5, abs_gpuGrad_y, 0.5, 0, gpuOutput );

// copy the result gradient from GPU to CPU and release GPU memory
gpuOutput.download(output);
gpuOutput.release();
gpuInput.release();
gpuInput_gray.release();
gpuGrad_x.release();
gpuGrad_y.release();
abs_gpuGrad_x.release();
abs_gpuGrad_y.release();

timer.Stop();
printf("OpenCV GPU code ran in: %f msecs.\n", timer.Elapsed());

 //show image
imshow("Image", output);

// wait until user press a key
waitKey(0);

//imwrite(output_file, output);
}
当我移除CUDA时。。。他不认识CUDA的所有功能。。。。但现在错误只出现在cudaEventSynchronize上。

请在代码中重新检查:

cv::cuda::addWeighted(gpugrad_x, 0.5, gpugrad_y, 0.5, 0, gpuoutput);
修正:

您忘记在
addWeighted()
函数中放入
double gamma
; 见:

我尝试了您代码的某些部分,但效果良好。

请重新检查您的代码:

cv::cuda::addWeighted(gpugrad_x, 0.5, gpugrad_y, 0.5, 0, gpuoutput);
修正:

您忘记在
addWeighted()
函数中放入
double gamma
; 见:


我尝试了您的部分代码,但效果良好。

您需要修改生成系统以链接CUDA运行时库(libcudart)。感谢您的回复。。。。。但我想我已经做到了。。。我认为问题在于链接器。。。不是编译器。。。你觉得呢?我就是这么说的。您必须链接CUDA运行库。您必须修改用于执行此操作的生成系统。我也遇到了同样的问题,您解决了吗?您需要修改生成系统以链接CUDA运行库(libcudart)谢谢您的回复。。。。。但我想我已经做到了。。。我认为问题在于链接器。。。不是编译器。。。你觉得呢?我就是这么说的。您必须链接CUDA运行库。你必须修改你用来做这件事的make系统。我也遇到了同样的问题,你解决了吗?我格式化了你的答案,但这更清楚了,你的“修复”不包含对原始代码的任何更改。你能请你的答案来纠正它吗?我格式化了你的答案,但这更清楚地表明你的“修复”没有包含对原始代码的任何更改。请你把你的答案改正一下好吗?
cv::cuda::addWeighted(gpugrad_x, 0.5, gpugrad_y, 0.5, 0, gpuoutput);