First time here? Check out the FAQ!

Ask Your Question
1

CUDA with OpenCV, STL transformation

asked Mar 21 '13

mada gravatar image

Hi,

I am writing my own CUDA kernel that should operate on matches I got using BFMatcher_GPU, with knnMatch algorithm in OpenCV. Matches are stored in std::vector<std::vector<cv::DMatch>> structure.

What would be the easiest and most efficient way to use those matches in my own CUDA kernel? Is the transfer to GpuMat necessary and how would it be done? Could Thrust library be used somehow?

Thanks!

Preview: (hide)

Comments

1

What method do you use : match, knnMatch or radiusMatch? BFMatcher_GPU returns results in GPU memory and have download* methods to convert GPU results into CPU std::vector<cv::DMatch> structure. If you want to use result of BFMatcher_GPU in your CUDA kernel you don't need to download results to CPU, you can use GPU results.

1

Ok, so here is the code (using knnMatch):

gpu::BFMatcher_GPU matcher(NORM_L2);

matcher.knnMatch( descriptors1GPU,descriptors2GPU, matches1, 2);

Which automatically gives results in std::vector<cv::DMatch>. Should I use knnMatchSingle then or? Does it calculates the results without "downloading" to CPU.

mada gravatar imagemada (Mar 21 '13)edit

1 answer

Sort by » oldest newest most voted
4

answered Mar 21 '13

Vladislav Vinogradov gravatar image

Use:

gpu::BFMatcher_GPU matcher(NORM_L2);
GpuMat trainIdxMat, distanceMat, allDist;
matcher.knnMatchSingle(descriptors1GPU, descriptors2GPU, trainIdxMat, distanceMat, allDist, 2);
int2* trainIdx = trainIdxMat.ptr<int2>();
float2* distance = distanceMat.ptr<float2>();

trainIdx[i] will contain indexes of two nearest matched points for i-th keypoint. distance[i] will contain distances.

I. e. descriptors1GPU[i] matches with descriptors2GPU[trainIdx[i].x] with distance = distance[i].x and with descriptors2GPU[trainIdx[i].y] with distance = distance[i].y.

You can use trainIdx and distance pointers in your CUDA kernels.

Preview: (hide)

Question Tools

Stats

Asked: Mar 21 '13

Seen: 651 times

Last updated: Mar 21 '13