0
votes

This is my first time to run OpenCV3.0 with CUDA. The thing is if I run the sample code in the opencv source folder (e.g. test_features2d.cpp), I can get results from CUDA function. However, if I create a standalone program and used CUDA code, it issues run time error (it does not have compiler error): (I DID USE GPUMAT !!)

OpenCV Error: The function/feature is not implemented (getGpuMat is available only for center code hereuda::GpuMat and cuda::HostMem) in getGpuMat, file /home/lixx2938/opencv-3.0.0/modules/core/src/matrix.cpp, line 1433 terminate called after throwing an instance of 'cv::Exception'
what(): /home/lixx2938/opencv-3.0.0/modules/core/src/matrix.cpp:1433: error: (-213) getGpuMat is available only for cuda::GpuMat and cuda::HostMem in function getGpuMat

Here is my trivial partial part of main function:

cv::Ptr<cv::cuda::ORB> orb = cv::cuda::ORB::create(200, 1.2, 4, 31, 0, 2, ORB::HARRIS_SCORE, 31, 20, true);

cv::Ptr<cv::cuda::FastFeatureDetector> fast = cv::cuda::FastFeatureDetector::create(threshold, nonmaxSuppression);

std::vector<cv::KeyPoint> fastkeypoints;

fast->detect(image, fastkeypoints);

std::vector<cv::KeyPoint> keypoints_cuda;

cv::cuda::GpuMat descriptors_cuda;

orb->detectAndCompute(image, noArray(), keypoints_cuda, descriptors2_gpu);

Here is my cmake file

cmake_minimum_required(VERSION 2.8)

project( test )

find_package( OpenCV REQUIRED )

add_executable( test test.cpp )

target_link_libraries( test ${OpenCV_LIBS} )

I think I lose some flags. Does anyone know what I should do to run the opencv code with CUDA?

2
Check make VERBOSE=1 whether youare really missing flags. - usr1234567

2 Answers

0
votes

You need to convert your image to grayscale (because the cuda detectAndCompute method only takes images in grayscale). Afterwards upload it to the GPU. So all in all it should look like that:

cv::Mat image, imageGray;
cv::cuda::GpuMat imageGpu;
cv::cvtColor(image, imageGray, CV_BGR2GRAY);
imageGpu.upload(imageGray);
orb->detectAndComputeAsync(imageGpu, cuda::GpuMat(), keyPointsGpu, descKeyPointsImageGpu);

Hope it helps.

0
votes

Assuming your image variable is a GpuMat, it could be your std::vector<cv::KeyPoint> keypoints_cuda;. I would try changing this to cv::cuda::GpuMat keypoints_cuda; and testing it out again.