Ask Your Question
1

CUDA with OpenCV, STL transformation

asked 2013-03-21 04:32:11 -0600

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!

edit retag flag offensive close merge delete

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.

Vladislav Vinogradov gravatar imageVladislav Vinogradov ( 2013-03-21 05:16:37 -0600 )edit
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 ( 2013-03-21 05:36:27 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
4

answered 2013-03-21 06:10:52 -0600

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.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2013-03-21 04:32:11 -0600

Seen: 599 times

Last updated: Mar 21 '13