C++ drawMatches时OpenCv BruterForceMatcher失败

C++ drawMatches时OpenCv BruterForceMatcher失败,c++,opencv,sift,C++,Opencv,Sift,使用以下OpenCV代码,我尝试测试BruteForceMatcher并获得错误消息: OpenCV错误:cv::drawKeypoints文件C中的断言失败(!outImage.empty()): \buildslave64\win64\u amdocl\2\u 4\u PackSlave-win32-vc11-shared\opencv\modules\featur es2d\src\draw.cpp,第115行 #include <iostream> #include <

使用以下OpenCV代码,我尝试测试BruteForceMatcher并获得错误消息: OpenCV错误:cv::drawKeypoints文件C中的断言失败(!outImage.empty()): \buildslave64\win64\u amdocl\2\u 4\u PackSlave-win32-vc11-shared\opencv\modules\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;
}
#包括
#包括
#包括“opencv2/highgui/highgui.hpp”
#包括“opencv2/stitching/stitcher.hpp”
#包括
#包括
#包括
#包括
使用名称空间std;
使用名称空间cv;
#定义MAX_PICNUM 18
bool try\u use\u gpu=false;
向量imgs;
字符串result\u name=“result.jpg”;
int main(int argc,char*argv[]){
initModule_nonfree();
int picNum=2;
Mat imgs[MAX_PICNUM];
对于(int i=0;iiStr;
imgs[i]=imread(“../”+iStr+“.jpg”);
}
SiftFeatureDetector siftdtc;
向量keyPointVec[MAX_PICNUM];
对于(int i=0;i

似乎是drawMatches中的错误?

最好检查keyPointVec[0]或keyPointVec[1]或matches是否为空。但是看起来您的输出图像可能不是空的而不是错误,但是请更改cvSaveImage(“matchs.jpg”,&(IplImage)(img_matches));到cv::imwrite(“matchs.jpg”,(img_matches));尝试一下:drawMatches(imgs[0],keyPointVec[0],imgs[1],keyPointVec[1],matches,img_matches,Scalar::all(-1),Scalar::all(-1),vector(),DrawMatchesFlags::DEFAULT);看起来关键点不应该存储在数组中,我使用了变量名,比如keyPoints1、keyPoints2,问题就解决了。谢谢