How to read image in cuda program? - opencv

Cant find opencv lib when run a cuda program.
I did some processing for my images by c++, and it works. But it is too slow for real-time system. Then I try to do it by cuda.
When I run my .cu file by "nvcc test.cu", it has an error that "identifier "Mat" is undefined" which means cuda cant find opencv lib. any idea to fix it?

The problem was fixed by using cmake rather than nvcc. OpenCV can be found by CmakeLists.

You need to use opencv_contrib modules with CUDA.
Make OpenCV with opencv_contrib, check -DWITH_CUDA=ON. And check -DBUILD_EXAMPLES=ON
Use cv::cuda::GpuMat instead cv::Mat
Learn about default CUDA examples.

Related

Why cv_bridge uses OpenCV 3.2 in ROS Melodic?

I have OpenCV 3.4 installed in Ubuntu 18. I also have installed ROS Melodic according to the website instructions. However, I keep on getting an error that libopencv_core.so.3.2 is required.
I already set my CMakeLists files to point to OpenCV 3.4.
However, I found out that in the file:
/ros/melodic/share/cv_bridge/cmake/cv_bridgeConfig.cmake
there is the following line hardcoded in opencv3.2:
set(libraries "cv_bridge;/usr/lib/x86_64-linux-gnu/libopencv_core.so.3.2.0;/usr/lib/x86_64-linux-gnu/libopencv_imgproc.so.3.2.0;/usr/lib/x86_64-linux-gnu/libopencv_imgcodecs.so.3.2.0").
I tried to change it to 3.4 but I can not rebuild it.
The error I am getting is:
/opt/ros/melodic/lib/image_view/image_view: error while loading shared libraries: libopencv_core.so.3.2: cannot open shared object file: No such file or directory
Why is OpenCV 3.2 hardcoded in cv_bridge and how can I rebuild it with OpenCV 3.4?
Update:
I eventually installed OpenCV 3.2 and it worked properly.
Because opencv development speed is much faster than ROS individual module. And a lot of ROS modules went depreciated after someone left the job.
But that's by no means the end of the day( maybe end of the day for noobs). You can build it directly with any version of opencv core function(besides imshow kind of function) others should perform just fine.
The easiest way is to do is: in the console before executing catkin_make try to execute the following
export CMAKE_PREFIX_PATH=/usr/local:$CMAKE_PREFIX_PATH
export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
This should give preference to your custom OpenCV installation when doing the find_package(OpenCV 3.X.0 REQUIRED). Then compile and use the function of that version.
Well if you do have to use 3.4 then I think you have to build ros version of opencv and image transport and cvbridge to the 3.4 if that's what you are targeting.
You can find the link here https://github.com/ros-gbp/opencv3-release The highest they provide seems to be 3.3

Issue building OpenCV with ccache and CUDA

Trying to build OpenCV 3.3.1 with CUDA support, using ccache:
Ubuntu 16.04 LTS
OpenCV 3.3.1
CUDA 8.0
CCACHE 3.2.4
Make fails for .cu files, giving error:
/usr/bin/ccache: invalid option -- 'E'
Usage:
ccache [options] ...
I've added the /usr/lib/ccache to PATH, which cc and which c++ outputs /usr/lib/ccache/cc and /usr/lib/ccache/c++ respectively. Manually added a symlink for nvcc in /usr/lib/ccache directory, but now OpenCV CMakeLists.txt cannot find CUDA.
But interestingly I can build this sample CUDA code, with this CMake file without any issue.
I've searched the net and read most posts on SO and other forums, but had no success. I've had this issue for previous versions of OpenCV as well, but always disabled ccache as a solution.
Can someone please explain the reason behind this error?
Trying to set
-DCUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda
seems to solve this problem for me.

opencv error: no GPU support

I have install Cuda 6.5 and opencv 2.4.9 with visual studio 2010, when I run gpu, I get error
Opencv Error: No GPU support(the library is compiled without PGU support) in the row_nogpu, file C:/builds/2_4_Packslave-win32-vc10-shared/opencv/modules/gpu/src/precomp.hpp line 135
I get this error, is any one can help what do I have to do?
Thanks
I believe, you have to actually build the libraries with CUDA support. I Imagine This Guide will be useful.
This can be caused because of following.
Use the flag WITH_CUDA=ON during cmake
You are trying to load the libraries which are compiled without GPU support, after you install opencv make sure you change the libraries path to that of GPU supported once.

EmguCV - nvcuda.dll could not be found

I've been asked to build a real-time face recognition application, and after some looking around I've decided to try EmguCV and OpenCV as the facial recognition library.
The issue I'm having at the moment is trying to get the SDK installed and working. I've followed the instructions found here to try and get it running, but I still can't run the samples. Whenever I try and run them, I get the error
The program can't start because nvcuda.dll is missing from your computer.
Try reinstalling the program to fix this problem.
I've tried most of the usual fixes, such as adding the bin folder to my environment path and copying the dll's into my system32 folder, but none of it seems to work.
EmguCV version 2.4.2.1777-windows-x64-gpu
Windows 8
AMD Radeon HD 6700 series graphics card.
I'm assuming this is an issue with the fact that I dont have an nVidia graphics card, but I'm not sure what I can do about it. For now, I'm going to try recompiling the source rather than using the downloaded .exe, and seeing if that helps.
Any suggestions?
Had the same problem, EmguCV 2.4.2 (no matter if x86 or x64) is compiled with GPU and you have to had nvidia GPU with CUDA support. So, if you want for eg. Fisherfaces from 2.4 in C# - wait for non-GPU release or buy/borrow CUDA card ;)
I happen to have the exact same problem as you. Everything is working fine on my computer (WinXP 32-bit) but not on Win7 64-bit computers.
This was because on my computer I already have OpenCV 2.4.2 installed and when I execute my program the path to the OpenCV dll points to the OpenCV folder and not to the dlls in the EmguCV folder. The original OpenCV dll don't have this dependency on NVidia's driver.
I used Dependency Walker to help me find out what was happening, as suggested here.
This link says that only the -gpu packages have gpu processing enabled but as you say the latest version (2.4.2) only a gpu package and no no-gpu package...
I read here that all I needed was to download the latest NVidia drivers to get the nvcuda.dll file but I downloaded many packages and never found this file: gpu computing sdk, cuda toolkit, display drivers, device drivers...
My workaround, instead of using an older version of EmguCV/OpenCV is to use the original dll from OpenCV 2.4.2.
I just used nvcuda.dll from dll-files.com.
It seems the issue is that the latest version on the site does not contain a non-GPU enhanced download, and that the GPU enhanced download requires an nVidia graphics card for CUDA integration.
I successfully downloaded and run the previous version which does not have GPU enhancements.
I had similar problem.
When I compile and run my application on computer with NVIDIA gpu it works fine.
Problem was when I moved app to another computer.
This second computer has no NVIDIA gpu and it threw 'Emgu.CV.CvInvoke' exception.
After many attempts I fortunately solved this problem.
As you mentioned before for now there is only gpu package for version 2.4.2.
I didn't notice this before.
For me solution was:
Copy files: 'cudart64_42_9.dll' and 'npp_42_9.dll' into Debug (application) folder
Copy file 'nvcuda.dll' into System32 folder.
After this steps aplication works on all computers even without NVIDIA gpu/ CUDA.
Other solution might be using opencv universal gpu version (for now is alpha 2.4.9) link: http://sourceforge.net/projects/emgucv/files/emgucv/2.4.9-alpha/
You can download source EmguCV from GIT and compile it, i have done this and works :
http://www.emgu.com/wiki/index.php/Download_And_Installation#Building_from_Git
It generates a non-GPU version of dlls
Regards.
here's also another copy of the dll's:
http://www.kimchiandchips.com/files/vvvv/nvcuda/
so 2 solutions:
Get NVidia CUDA DLL's from the above link. Ideally rename the 64 or 32bit version to nvcuda.dll based on your required platform. Put next to your opencv dll's
Upgrade to 2.4.9 which has universal GPU support
I also had some problems when doing my dissertation using EmguCV for face recognition.
Try to use the stablest version libemgucv-windows-x86-2.4.0.1717.exe
Try not to use the gpu download, this version has the least bugs and the 32-bit is better than the x64.
when compiling for the first time use visual studio 2012.
With this version you wont need to install all the above mentioned. You can see this example to know it really works : http://sourceforge.net/projects/emgufacerecog/

Getting webcam to work in OpenCV 2.3 with Cygwin

I have a problem trying to get a webcam in OpenCV 2.3 to work with Cygwin. I have a Windows 7 64-bit system and I use Notepad++ and cygwin compilers to do my C++ programming. I have seen other posts with similar problems:
Getting Webcam to work in OpenCV
Can't access webcam with OpenCV
I first tried installing OpenCV via the Cygwin Ports. This is rather easy to install, but alas I run into the webcam problem (always returns false when trying to find a device). I have also attempted to build OpenCV and install manually using the command line flavor of CMake. I tried adding the HAVE_VIDEOINPUT and HAVE_DSHOW flags, but no dice. All my programs compile nicely and I have all the functionality of OpenCV aside for this webcam thing.
Has anyone successfully built OpenCV 2.3 on Cygwin with webcam working?
It is unlikely that cygwin build of OpenCV will be able to access a webcam. At least it is not possible without hacking OpenCV cmake scripts. Under cygwin OpenCV build always follows the UNIX branch and videoinput/directshow is excluded from build.

Resources