SURF_CUDA不断陷入无限循环

时间:2019-09-09 13:54:48

标签: opencv surf

我想使用我的GPU来执行SURF算法,但是当我对cuda版本使用surf时。该过程总是在

处陷入无限循环
surf(img1, GpuMat(), keypoints1GPU, descriptors1GPU);

仍具有100%的GPU使用率。我使用RTX2080ti GPU,cuda版本10.1,opencv版本3.4.1。 我检查图像尺寸为1688x950,并且图像显示良好。

#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[])
{
    cv::cuda::printShortCudaDeviceInfo(cv::cuda::getDevice());

    GpuMat img1, img2;
    img1.upload(imread("1.png", IMREAD_GRAYSCALE));
    img2.upload(imread("2.png", IMREAD_GRAYSCALE));


    SURF_CUDA surf(400);
    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;

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

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

    // draw 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);

    return 0;
}

0 个答案:

没有答案