Ask Your Question
4

SURF on CUDA: every execution produces different + weird results for some images?

asked 2016-02-09 10:09:15 -0600

strann gravatar image

updated 2016-02-09 10:32:36 -0600

Hello,

I faced the problem that running following code (taken from 'samples/gpu/surf_keypoint_matcher.cpp' ) produces weird results for some images: SURF on CUDA finds "a column of random points" always near the right edge of an image. Moreover processing such images (for example, seaman.jpg, uav.JPG ) with SURF on CUDA more than once produces different amount of keypoints, while SURF on CPU always finds the same number of keypoints without any "weird" points.

I've noticed that maximum number of keypoints found by SURF on CUDA is restricted to max value of 16-bit unsigned integer (65535), maybe there are more restrictions?

Any ideas why this is happening? Has someone else already reported the issue?... I'm using OpenCV 3.1.0.

#include <iostream>
#include "opencv2/core/core.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/cudafeatures2d.hpp"
#include "opencv2/xfeatures2d/cuda.hpp"
#include "opencv2/opencv_modules.hpp"

using namespace std;
using namespace cv;
using namespace cv::cuda;

int main(int argc, char *argv[])
{
    cuda::setDevice(0);

    GpuMat img1, img2;
    img1.upload(imread("seaman.jpg", IMREAD_GRAYSCALE));
    img2.upload(imread("seaman.jpg", IMREAD_GRAYSCALE));

    SURF_CUDA surf;
    GpuMat keypoints1GPU, keypoints2GPU;
    GpuMat descriptors1GPU, descriptors2GPU;

    surf(img1, GpuMat(), keypoints1GPU, descriptors1GPU);
    surf(img2, GpuMat(), keypoints2GPU, descriptors2GPU);

    cout << "FOUND " << keypoints1GPU.cols << " keypoints on first image" << endl;
    cout << "FOUND " << keypoints2GPU.cols << " keypoints on second image" << endl;

    // matching descriptors
    Ptr<cv::cuda::DescriptorMatcher> matcher = cv::cuda::DescriptorMatcher::createBFMatcher(surf.defaultNorm());
    vector<DMatch> matches;
    matcher->match(descriptors1GPU, descriptors2GPU, matches);

    // downloading results
    vector<KeyPoint> keypoints1, keypoints2;
    vector<float> descriptors1, descriptors2;
    surf.downloadKeypoints(keypoints1GPU, keypoints1);
    surf.downloadKeypoints(keypoints2GPU, keypoints2);
    surf.downloadDescriptors(descriptors1GPU, descriptors1);
    surf.downloadDescriptors(descriptors2GPU, descriptors2);

    // drawing the results
    Mat img_matches;
    drawMatches(Mat(img1), keypoints1, Mat(img2), keypoints2, matches, img_matches);

    imwrite("seaman_result.jpg", img_matches);

    namedWindow("matches", 0);
    imshow("matches", img_matches);
    waitKey(0);

    cuda::resetDevice();

    return 0;
}

image description

Running SURF on CUDA for seaman.jpg: 1) 693 keypoints and 2) 620 keypoints for the same image

image description

Running SURF on CPU for seaman.jpg: equal amount of points for identical images (513 keypoints)

edit retag flag offensive close merge delete

Comments

I observe the same issue than you with SURF_CUDA.

  • Two consecutives call of SURF_CUDA() produce different number of detected keypoints on the same image, no matter if it is the same instance or another instance.
  • At each run, the number of detected keypoints is different.

I think that you can open an issue here: https://github.com/Itseez/opencv_contrib/issues.

Another example of the issue with a png source image here.

Eduardo gravatar imageEduardo ( 2016-02-09 14:49:57 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2016-03-16 05:02:13 -0600

strann gravatar image
edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2016-02-09 10:09:15 -0600

Seen: 1,993 times

Last updated: Mar 16 '16