0

我在 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. 如果我删除该行代码有效。

4

1 回答 1

4

ORB描述符提取器返回 8 位描述符。使用Hamming这个描述符的距离:

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

具有 L2 规范的 BruteForceMatcher_GPU 仅支持浮点描述符(如 from SURF)。

于 2013-09-04T12:21:13.737 回答