功能描述教程不工作opencv

时间:2015-10-19 08:13:54

标签: c++ debugging opencv crash

我尝试了关于opencv.com上的功能描述的教程,程序崩溃并出现错误:

Debug assertion failed , Expression: vector iterator outside range
第_

detector.detect(img_1, keypoints_1);

我使用OpenCV 2.4.11,使用Visual Studio 2010,并且我链接到库目录opencv_<module>2411d.lib中的C:\opencv\build\x86\vc10\lib个库

代码在这里:

#include <iostream>
#include <stdio.h>
#include <opencv2\core\core.hpp>
#include <opencv2\features2d\features2d.hpp>
#include <opencv2\highgui\highgui.hpp>
#include <opencv2\nonfree\features2d.hpp>
#include <opencv2\legacy\legacy.hpp>

using namespace cv;
using namespace std;



int main(int argc, char ** argv)
{
    Mat img_1 = imread("3.jpg", CV_LOAD_IMAGE_GRAYSCALE);
    Mat img_2 = imread("2.jpg", CV_LOAD_IMAGE_GRAYSCALE);

    if (!img_1.data || !img_2.data)
    {
        cout << " Nu au fost afisate imaginile" << endl;
        return -1;
    }

    int minHessian = 400;
    imshow("1.png", img_1);
    imshow("2.png", img_2);


    SurfFeatureDetector detector(minHessian);

    vector<KeyPoint> keypoints_1, keypoints_2;

    detector.detect(img_1, keypoints_1);
    detector.detect(img_2, keypoints_2);

    //-- Step 2: Calculate descriptors (feature vectors)
    SurfDescriptorExtractor extractor;

    Mat descriptors_1, descriptors_2;

    extractor.compute(img_1, keypoints_1, descriptors_1);
    extractor.compute(img_2, keypoints_2, descriptors_2);

    //-- Step 3: Matching descriptor vectors with a brute force matcher
    BFMatcher matcher(NORM_L2);
    vector< DMatch > matches;
    matcher.match(descriptors_1, descriptors_2, matches);

    //-- Draw matches
    Mat img_matches;
    drawMatches(img_1, keypoints_1, img_2, keypoints_2, matches, img_matches);

    //-- Show detected matches
    imshow("Matches", img_matches);

    waitKey(0);

    return 0;
}

这是它开始崩溃的时候:

0 个答案:

没有答案