OpenCv BruterForceMatcher在drawMatches时失败

时间:2015-05-13 13:02:51

标签: c++ opencv sift

使用以下OpenCV代码,我尝试测试BruteForceMatcher并收到错误消息: OpenCV错误:断言失败(!outImage.empty())在cv :: drawKeypoints中,文件C: \ buildslave64 \ win64_amdocl \ 2_4_PackSlave-Win32的VC11共享\的OpenCV \模块\ featur es2d \ src \ draw.cpp,第115行

#include <iostream>
#include <fstream>
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/stitching/stitcher.hpp"
#include <opencv2/features2d/features2d.hpp>
#include <opencv2/nonfree/nonfree.hpp>
#include <opencv2/legacy/legacy.hpp>
#include <opencv2/opencv.hpp>

using namespace std;
using namespace cv;
#define MAX_PICNUM 18
bool try_use_gpu = false;
vector<Mat> imgs;
string result_name = "result.jpg";

int main(int argc, char* argv[]) {
    initModule_nonfree();
    int picNum = 2;
    Mat imgs[MAX_PICNUM];
    for (int i = 0; i < picNum; ++i) {
        stringstream ss;
        string iStr;
        ss << i;
        ss >> iStr;
        imgs[i] = imread("../" + iStr + ".jpg");
    }
    SiftFeatureDetector siftdtc;
    vector<KeyPoint> keyPointVec[MAX_PICNUM];
    for (int i = 0; i < picNum; ++i) {
        siftdtc.detect(imgs[i], keyPointVec[i]);
    }
    SiftDescriptorExtractor siftDesc;
    Mat descriptextractors[MAX_PICNUM];
    for (int i = 0; i < picNum; ++i) {
        siftDesc.compute(imgs[i], keyPointVec[i], descriptextractors[i]);
    }
    SiftDescriptorExtractor extractor;
    Mat descriptor1,descriptor2;
    BruteForceMatcher<L2<float>> matcher;
    vector<DMatch> matches;
    Mat img_matches;
    extractor.compute(imgs[0], keyPointVec[0], descriptor1);
    extractor.compute(imgs[1], keyPointVec[1], descriptor2);
    matcher.match(descriptor1,descriptor2,matches);
    drawMatches(imgs[0], keyPointVec[0], imgs[1], keyPointVec[1], matches, img_matches);

    cvSaveImage("matchs.jpg", &(IplImage)(img_matches));
    waitKey();
    return 0;
}

似乎是drawMatches中的错误?

0 个答案:

没有答案