Sie sind auf Seite 1von 4

OpenCV_GPU

Contents 1. OpenCV_GPU 1. Request Feature 2. Getting Started 1. Compiling OpenCV with CUDA Support 2. Adding OpenCV to your project via Cmake 3. Warning!!! First Function Call Perfomance 4. Short Sample 3. Asking questions 4. List of Ported Functions 5. Documentation 6. Frequently Asked Questions 7. Leave Feedback

The OpenCV GPU module is a set of classes and functions to utilize GPU computational capabilities. It is implemented using NVidia CUDA Runtime API , so only that vendor GPUs are supported. It includes utility functions, low level vision primitives as well as high level algorithms. I.e. the module is being developed as a powerful infrastructure for fast vision algorithms building on GPU with some high level state of the art functionality.

Request Feature
OpenCV GPU Feature Request form

Getting Started
Compiling OpenCV with CUDA Support
Prerequisites: Sources from SVN or SourceForge NVIDIA Display Driver CMake (minimum 2.8.0) Cuda Toolkit 4.0 (the latest) Build steps: 1. Checkout the latest OpenCV from SVN: https://code.ros.org/svn/opencv/trunk/opencv. 2. Open CMake-Gui Set source and build folders Set WITH_CUDA flag Configure for your favorite IDE or for make files. If you want to generate for NMake, please run CMake-Gui from Visual Studio Command Prompt. If CMake can't find "FindCuda.cmake", please set environment variable

,p CMAKE_MODULE_PATH = <path to location of FindCUDA.cmake> Check that all CUDA paths are detected correctly. If not, specify CUDA_TOOLKIT_ROOT_DIR manually. Generate project for your favorite IDE. (Optional) You can reduce build time by setting target architecture variables (in order to build only for your GPU) CUDA_ARCH_BIN = "X.X", where XX is your GPU Compute Capability CUDA_ARCH_PTX = "empty" 3. Open and build project generated, or run make.

Adding OpenCV to your project via Cmake


If you use Cmake for your project, adding opencv libraries to it is a very easy. 1. Build OpenCV 2. Modify your "CMakeLists.txt" file as in the sample below 3. On "Configure" stage for you application, Cmake-Gui finds OpenCV automatically in last build place. If it can't find, specify OpenCV_Dir variable to OpenCV build directory (a place where OpenCVConfig.cmake is located)
cmake_minimum_required(VERSION 2.8) set(the_target YourProjName} set(src "main.cpp" "other.cpp") project( ${the_target} ) find_package( OpenCV REQUIRED ) include_directories( ${OpenCV_INCLUDE_DIR} ) add_executable( ${the_target} ${src} ) target_link_libraries( ${the_target} ${OpenCV_LIBS} )

Warning!!! First Function Call Perfomance


While using OpenCV GPU the following specific should be taken into consideration: GPU module uses CUDA Runtime API which runs initialization code on the first function call. Just-in-time compilation of GPU code can be run on the first function call if the GPU module wasn't built for the current GPU. Therefore first call of many functions may be quite slow. So for performance measuring, it is necessary to do dummy function call and only then perform time tests . If it is critical for an application to run GPU code only once, it is possible to use a compilation cache which is persistent over multiple runs. Please read nvcc documentation for details (CUDA_DEVCODE_CACHE environment variable).

Short Sample
#include <iostream> #include "opencv2/opencv.hpp" #include "opencv2/gpu/gpu.hpp" int main (int argc, char* argv[]) { try { cv::Mat src_host = cv::imread("file.png", CV_LOAD_IMAGE_GRAYSCALE); cv::gpu::GpuMat dst, src; src.upload(src_host); cv::gpu::threshold(src, dst, 128.0, 255.0, CV_THRESH_BINARY); cv::Mat result_host = dst; cv::imshow("Result", result_host); cv::waitKey(); } catch(const cv::Exception& ex) { std::cout << "Error: " << ex.what() << std::endl; } return 0; }

Asking questions
Send your question to OpenCV Yahoo Group using recommendations below:

Place [GPU] or [CUDA] in question's topic (OpenCV GPU team can't read the group entirely). In case of some strange problems, specify your GPU, OS, Cuda Toolkit, NPP, message from caught cv::Exception (if it is), etc.

List of Ported Functions


Initialization & information (getCudaEnabledDeviceCount, setDevice, getDevice, isCompatibleWith, freeMemory, totalMemory, getComputeCapability). Per-element operations with/without mask (add, subtract, multiply, divide, exp, log, absdiff, compare, bitwise_not, bitwise_or, bitwise_and, bitwise_xor, bitwise_xor, min, minS, max, maxS). Color conversion (almost all color spaces, cvtColor). Geometrical image transforms (rotate, resize, warpAffine, warpPerspective, remap, transpose) Mean shift-based transforms (meanShiftFiltering, meanShiftSegmentation) Corner detectors (cornerHarris, cornerMinEigenVal)

Reductions with/without mask ( meanStdDev, norm, sum, sqrSum, minMax, minMaxLoc, countNonZero, integral, sqrIntegral, columnSum, rectStdDev) Template matching (matchTemplate) Filter engine (low-level filter classes, middle-level filtering engines, and high level filtering functions: boxFilter, blur, erode, dilate, morphologyEx, filter2D, sepFilter2D, Sobel, Scharr, GaussianBlur, Laplacian) Histograms (evenLevels, histEven, histRange) Stereo correspondence (StereoBlockMatching, StereoBeliefPropagation, StereoConstantSpaceBP, DisparityBilateralFilter, drawColorDisp) Pedestrian detection (Histograms of oriented gradients (HOG) descriptor) Universal descriptor matcher (BruteForceMatcher) Haar features detection, face detection (CascadeClassifier based on code contributed by Anton Obukhov, NVidia) Feature detection for object recognition ( Speeded Up Robust Features, SURF ) Other image transforms (flip, LUT, merge, split, magnitude, magnitudeSqr, phase, cartToPolar, polarToCart, reprojectImageTo3D, graphcut, threshold, copyMakeBorder, dft, convolve, mulSpectrums, mulAndScaleSpectrums)

Documentation
Documenation is available here: https://code.ros.org/svn/opencv/trunk/opencv/doc/opencv.pdf (it contains GPU subsection). Or here: http://opencv.itseez.com (regenerated each night).

Frequently Asked Questions


FAQ list is available here: OpenCV GPU FAQ.

Leave Feedback
OpenCV GPU Feedback form Back to Main Wiki Page Back to the User Wiki Pages

OpenCVWiki: OpenCV_GPU (last edited 2011-07-19 08:40:23 by AnatolyBaksheev)

Das könnte Ihnen auch gefallen