How to find in CMAKE file if OpenCV is compiled with CUDA - opencv

i am using opencv with another library. So i would like to compile a class if OpenCV has CUDA.
i need to acheive this in Cmake file. But i cannot find any variable that tells whether OpenCV
has CUDA or not.
FindOpenCV.cmake defines these variables
OpenCV_FOUND
OpenCV_LIBS
OpenCV_INCLUDE_DIR
OpenCV_VERSION
now how can i find out if OpenCV is compiled with CUDA or not from this cmake file?

Here is the list of CMake variables, that can help you:
OpenCV_COMPUTE_CAPABILITIES - compute capability from which OpenCV has been compiled, can be added to nvcc flags.
list(APPEND CUDA_NVCC_FLAGS ${OpenCV_COMPUTE_CAPABILITIES})
OpenCV_CUDA_VERSION - CUDA toolkit version which was used to build OpenCV, if OpenCV was built without CUDA support, the variable is empty. You can check this variable:
if(OpenCV_CUDA_VERSION)
# Have CUDA support
endif()
OpenCV_USE_CUBLAS - true if OpenCV was built with CUBLAS support
OpenCV_USE_CUFFT - true if OpenCV was built with CUFFT support
OpenCV_USE_NVCUVID - true if OpenCV was built with NVCUVID support

Related

Using GPU in OpenCV

If I want to use my computer's GPU with OpenCV, is it necessary that I build OpenCV from source with CUDA enabled? Or can I install OpenCV with CUDA support via apt-get? I noticed the following 2 packages in apt-get:
libopencv-gpu-dev - development files for libopencv-gpu2.4v5
libopencv-gpu2.4v5 - computer vision GPU library
But I am not sure if these will work with OpenCV3 or if they are only compatible with OpenCV2. I know that the gpu module in Opencv2 was split up into multiple CUDA modules in OpenCV3.
Yes it is necessary that you build opencv from the source with CUDA option enabled. The apt-get packages won't work with OpenCV3 and above versions. I suggest you install the CUDA Toolkit first and then attempt installation of OpenCV or the GPU functions won't work.

How to build openCV 3.3.0 with GStreamer on Windows

Having Gstreamer 1.22 successfully installed I'm not able to configure the project to build OpenCV. CMake isn't able to find GStreamer on my machine. Any ideas how two address this issue?
Just found the solution:
Cmake is using FindGstreamerWindows.cmake to find GStreamer on Windows, which is using internal an environment variable called "GSTREAMER_DIR" pointing to ..\gstreamer\1.0\x86_64.
Please make sure GSTREAMER_DIR exists on your machine.
I recently compile Opencv 4.2 with GStreamer on Windows. I use settings for GStreamer as on the following pictures. Make sure you point to correct .lib and include directories. all_Library is gstapp-1.0.lib etc, when configuraing CMAKE to compile OpenCV.
I use Opencv 4.2, CMake 3.17.0 release candidate and Gstreamer 1.16.2 MSVC 64-bit (VS 2019) developer and runtime installer. The whole process is described here install OpenCV on windows GStreamer tutorial
The important part is to set up environmental variables to find Gstreamer Runtime. Into system variable path: add
xxx\1.0\x86_64\bin
xxx\1.0\x86_64\lib
xxx\1.0\x86_64\lib\gstreamer-1.0
Gstreamer pipe from c++ opencv program to the web.

OpenCV error: No GPU support, cannot build with WITH_CUDA=ON

I am trying to make OpenCV project using GPU. I installed OpenCV v2.4.13 and NVidia CUDA Toolkit. I added additional include and library directories in configuration and OpenCV project works correctly without GPU functions. But when I'm trying to run openCV with GPU I get an error like this:
OpenCV Error: No GPU support (The library is compiled without CUDA support) in EmptyFuncTable::mallocPitch, file C:\builds\2_4_PackSlave_win32_vc12-shared\opencv\modules\dynamicuda\include\opencv2/dynamicuda/dynamicuda.hpp, line 126
Libary has been compiled without CUDA, so i tried to build the sources myself, with WITH_CUDA=ON in CMake, but when building Visual Studio 2013 has been giving me an errors that he cannot find opencv_core2413d.lib.
What can I do with this?

Forcing cmake to use a specific OpenCV version

My Ubuntu 14.04 has OpenCV 2.4.8 installed by default, and I also have a hand-built OpenCV 2.4.11 that I need for the cv::fisheye classes, which I build with cmake to produce my executable. The problem is that I am using ROS, which also defaults to 2.4.8, but I need to link with 2.4.11. The hack I have in place is:
find_package(OpenCV REQUIRED)
# Needed to force OpenCV 2.4 to link with 2.4.11
#message("Initial value for ${OpenCV_VERSION}: ${OpenCV_LIBS}")
if(OpenCV_VERSION VERSION_LESS "3.0")
set(OpenCV_VERSIONED_LIBS "")
macro(set_opencv_version version)
foreach( LIB_FILE ${ARGN} )
set(OpenCV_VERSIONED_LIBS ${OpenCV_VERSIONED_LIBS} :lib${LIB_FILE}.so.${version})
endforeach()
endmacro()
set_opencv_version("2.4.11" ${OpenCV_LIBS})
else()
set(OpenCV_VERSIONED_LIBS ${OpenCV_LIBS})
endif()
#message("Updated value: ${OpenCV_VERSIONED_LIBS}")
target_link_libraries(my_fisheye_application
${OpenCV_VERSIONED_LIBS}
${catkin_LIBRARIES}
cv_bridge # This by default pulls in OpenCV 2.4.8 libraries
# ...etc...
)
As this script needs to work on different machines and with OpenCV 3.0 as well as 2.4.11, I cannot really make any assumptions about the directories in use. Is there a better way to do this?
If you want to force CMake (the FindOpenCV module) to search for an OpenCV library different from the package/system installed one,
you need to set OpenCV_ROOT_DIR variable to the base directory of OpenCV tree to use.
Also, because you want at least a specific minimum version of the OpenCV library, it's better to state it in the find_package() function, as the following:
find_package(OpenCV 2.4.11 REQUIRED)

CMake error: BUILD_TBB option supports Windows on ARM only

I am trying to build libraries with CMake for a vision detection system to be built in OpenCV using Visual Studio 2012's C++ compiler. After a lot of fixing of configurations, installation of Qt 5 and also Openni, I am still getting the following errors from the CMake configuration step:
Checking for Windows (Phone) Platform SDK 8.0/8.1
Checking for Visual Studio 2012/2013
WARNING, OpenNI library directory (set by OPENNI_LIB_DIR variable) is not found or does not have OpenNI libraries.
WARNING, OpenNI include directory (set by OPENNI_INCLUDE_DIR variable) is not found or does not have OpenNI include files.
WARNING, PrimeSensor Module binaries directory (set by OPENNI_PRIME_SENSOR_MODULE_BIN_DIR variable) is not found or does not have PrimeSensor Module binaries.
Looking for Mfapi.h
Looking for Mfapi.h - found
Warning at cmake/OpenCVFindIntelPerCSDK.cmake:17 (message):
Intel Perceptual Computing SDK library directory (set by INTELPERC_LIB_DIR
variable) is not found or does not have Intel Perceptual Computing SDK
libraries.
Call Stack (most recent call first):
cmake/OpenCVFindLibsVideo.cmake:291 (include)
CMakeLists.txt:482 (include)
CMake Error at 3rdparty/tbb/CMakeLists.txt:5 (message):
BUILD_TBB option supports Windows on ARM only!
Use regular official TBB build instead of the BUILD_TBB option!
Configuring incomplete, errors occurred!
See also "C:/OpenCV/opencv/lib/CMakeFiles/CMakeOutput.log".
From cmake_gui, you can quickly disable BUILD_TBB variable. If you want TBB, you have to build it separately by yourself, and then you can use this guide to activate it in OpenCV.

Resources