BruteForceMatcher_GPU匹配器错误

时间:2013-09-04 10:58:10

标签: opencv cuda gpu

我在Ubuntu 12.04上使用Opencv 2.4.6.0和Cuda 5.5 执行代码后,执行到达

时出现以下错误
atcher.knnMatch(descriptors_test_GPU, descriptors_tmp_GPU, matches, 2);

OpenCV Error: Assertion failed (func != 0) in knnMatchSingle, file /root/opencv-2.4.6.1/modules/gpu/src/brute_force_matcher.cpp, line 497

在抛出'cv :: Exception'的实例后终止调用   what():/ root /opencv-2.4.6.1/modules/gpu/src/brute_force_matcher.cpp:497:错误:(-215)func!= 0 in function knnMatchSingle

此处的代码示例:

Mat image = imread(argv[1]);
resize(image, image, Size(600,450), 0, 0, INTER_CUBIC);
Mat image_gray;
getGray(image, image_gray);

ORB_GPU orb(1000);

GpuMat descriptors_test_GPU, frame_g(image_gray);
vector<KeyPoint> keypoints_test_CPU;

GpuMat fullmask(frame_g.size(), CV_8U, 0xFF);

orb(frame_g, GpuMat(), keypoints_test_CPU, descriptors_test_GPU);

Mat descriptors_test_CPU_Mat(descriptors_test_GPU);

vector<Point2f> objs_corners(4);
BruteForceMatcher_GPU< L2<float> > matcher;

VideoCapture cap;
Mat currentFrame_c;
vector< vector<DMatch> > matches;
matches.clear();

if ( cap.open(argv[2]) ) {
    do
    {
        cap >> currentFrame_c;
        resize(currentFrame_c, currentFrame_c, Size(600,450), 0, 0, INTER_CUBIC);
        getGray(currentFrame_c, currentFrame_c);

        GpuMat currentFrame(currentFrame_c);
        //Get the corners from the object
        objs_corners[0] = cvPoint(0,0);
        objs_corners[1] = cvPoint( currentFrame.cols, 0 );
        objs_corners[2] = cvPoint( currentFrame.cols, currentFrame.rows );
        objs_corners[3] = cvPoint( 0, currentFrame.rows );

        //cout<<endl<<objs_corners[0]<<" "<<objs_corners[1]<<" "<<objs_corners[2]<<" "<<objs_corners[3]<<endl;
        GpuMat keypoints_tmp_GPU, descriptors_tmp_GPU;
        vector<KeyPoint> keypoints_tmp_CPU;
        orb(currentFrame, GpuMat(), keypoints_test_CPU, descriptors_tmp_GPU);
        GpuMat trainIdx, distance;

        matcher.knnMatch(descriptors_test_GPU, descriptors_tmp_GPU, matches, 2);

        std::vector<DMatch > good_matches;

        for(int k = 0; k < min(descriptors_test_CPU_Mat.rows-1,(int) matches.size()); k++) //THIS LOOP IS SENSITIVE TO SEGFAULTS
        {
            if((matches[k][0].distance < 0.6*(matches[k][1].distance)) && ((int) matches[k].size()<=2 && (int) matches[k].size()>0))
            {
                good_matches.push_back(matches[k][0]);
            }
        }                    

        matcher.clear();

    } while (!currentFrame_c.empty());
}

我无法理解,我甚至没有使用knnMatchSingle。 如果我删除该代码的行。

1 个答案:

答案 0 :(得分:4)

ORB描述符提取器返回8位描述符。对此描述符使用Hamming距离:

BruteForceMatcher_GPU<Hamming> matcher;
matcher.knnMatch(descriptors_test_GPU, descriptors_tmp_GPU, matches, 2);

带有L2规范的BruteForceMatcher_GPU仅支持浮点描述符(例如来自SURF)。