简体   繁体   English

如何在我的cuda代码中使用opencv?

[英]How can I use opencv in my cuda code?

I have installed opencv and Cuda.I have made some opencv code and now I wanna try to make it run faster using CUDA.The problem is that the opencv GPU module does not satisfy me. 我已经安装了opencv和Cuda。我编写了一些opencv代码,现在我想尝试使用CUDA使其更快地运行。问题是opencv GPU模块不满足我的要求。 How can I make a CUDA code to include and use opencv libraries and functions exactly like my .cpp files?I include the needed .h files (cv.h highgui.h) that I moved to the "include" CUDA folder in my CUDA code but when I try to compile it using nvcc it says Undefined symbols for architecture i386: 如何制作CUDA代码以完全像.cpp文件那样包含和使用opencv库和函数?我将所需的.h文件(cv.h highgui.h)包括在内,该文件已移至CUDA的“ include” CUDA文件夹中。代码,但是当我尝试使用nvcc对其进行编译时,它说体系结构i386的未定义符号:

"_cvLoadImage", referenced from: _main in tmpxft_000177b6_00000000-14_cuda.o ld: symbol(s) not found for architecture i386 collect2: ld returned 1 exit status “ _cvLoadImage”,引用自:tmpxft_000177b6_00000000-14_cuda.o中的_main ld:找不到体系结构i386的符号collect2:ld返回1退出状态

which means that it does not understand the functions so the libraries are not included the right way as far as I can see.How can I make it work? 这意味着它不了解功能,因此就我所知,没有正确地包含库。如何使它起作用?

As far as I know, you can't just include OpenCV functions direclty in CUDA code. 据我所知,您不能仅仅在CUDA代码中包含OpenCV函数的直接性。 CUDA has its own way of programming and code made for CPU can't run on GPU directly. CUDA拥有自己的编程方式,为CPU编写的代码无法直接在GPU上运行。

I would suggest you to look at the documentation to understand how works CUDA. 我建议您查看文档以了解CUDA的工作原理。

If the gpu build of OpenCV does not satisfy you maybe you should make your own implementation of those functions. 如果OpenCV的gpu构建不满意,也许您应该自己实现这些功能。

OR 要么

you just want to use openCV on CPU and also use CUDA for some other computation ? 您是否只想在CPU上使用openCV,还希望将CUDA用于其他计算?

In the case, I think you have to create a cpp file which wraps your CUDA functions. 在这种情况下,我认为您必须创建一个包装CUDA函数的cpp文件。 You will be able to use your wrapped functions as usual in your C or C++ code. 您将能够照常使用C或C ++代码中的包装函数。

I think, the "Getting Started with GPU-accelerated Computer Vision using OpenCV and CUDA" webinar materials should help. 我认为,“使用OpenCV和CUDA的GPU加速计算机视觉入门”网络研讨会材料应该会有所帮助。 You can find them here: link 您可以在这里找到它们: 链接

You better not try to mix between opencv headers and nvcc compiler, this is a bad practice. 您最好不要尝试在opencv标头和nvcc编译器之间混合使用,这是一种不好的做法。

Opencv is built in library which was build using CMAKE (usually in windows under visual studio) Opencv内置在使用CMAKE构建的库中(通常在Visual Studio下的Windows中)

When you include an opencv header in nvcc compiler, you have to include all the "presents" you get from opencv, eg: external dll, headers and extern function expected in opencv code. 在nvcc编译器中包含opencv标头时,必须包含从opencv获得的所有“表示”,例如:opencv代码中期望的外部dll,标头和extern函数。

What I find is the most appropriate solution in your case, would be to write a code which compiles in VS, refer to you CUDA code and Opencv's CUDA back and forth (you can always use primitives and extern functions). 在您的情况下,我发现最合适的解决方案是编写在VS中编译的代码,来回引用CUDA代码和Opencv的CUDA(您始终可以使用基元和外部函数)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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