简体   繁体   中英

Files/directories to include in Visual Studio C++ to use CUDA?

I want to use CUDA/GPU in OpenCV in Visual Studio. For example, cuda::GpuMat . I successfully build OpenCV with the extra modules with CUDA enabled

I tried the following code

#include <string>
#include <opencv2/core/core.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/photo/cuda.hpp>
#include <opencv2/photo.hpp>

using namespace std;
using namespace cv;

int main(){

   string imageName("input.bmp");

   //CPU version
   Mat image = imread(imageName.c_str(), IMREAD_GRAYSCALE);

   //CUDA version       
   cuda::GpuMat imageGPU;
   cuda::GpuMat downloadGPU;
   Mat buff;
   imageGPU.upload(image);
   cuda::fastNlMeansDenoising(imageGPU, downloadGPU, 2.5, 7, 31);
   downloadGPU.download(buff);
   imwrite("gpu.bmp", buff);

   return 0;
}

But I get an unhandled exception error.

I originally downloaded OpenCV in C:\Users\me\Downloads\opencv

I then downloaded and installed the latest OpenCV extra modules with CUDA on in C:\Users\me\Downloads\opencv-master1\opencv-master

In Property Pages->C/C++->General->Additional Include Directories , I have:

C:\Users\me\Downloads\opencv\build\include\opencv
C:\Users\me\Downloads\opencv\build\include\opencv2
C:\Users\me\Downloads\opencv\build\include\

In Property Pages->Linker->General->Additional Library Directories , I have:

C:\Users\me\Downloads\opencv\build\x64\vc15\lib

and in Property Pages->Linker->Input->Additional Dependencies , I have:

opencv_world343d.lib
opencv_world343.lib

what else am I supposed to include so I can get GpuMat to work properly?

Most of the cases, yes, but you need to know which library you need to add, it may be cufft.lib , cublas.lib , cudnn.lib , etc. It depends of the function you use inside your code.

Opencv includes a cmake include file that would set all of this up for you if you use cmake to build you VS test project. This file will be in the root of the opencv install directory, ie after building opencv running cmake --install or the equivalent in VS. The file is OpenCVConfig.cmake, and it would be included in the CMakeLists.txt file for your project. Then you would call FindPackage(OpenCV), which would locate the OpenCV install, setup a few variables, which you would then use to link against your app.

I can post a sample CMakeList.txt file if you feel that would help.

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