OpenCV SIFT提取器失败

时间:2013-08-20 18:02:58

标签: opencv qt-creator sift

执行代码时出现以下错误:(OpenCV with Qt Creator)

  

OpenCV错误:断言失败(!outImage.empty())在drawKeypoints中,文件C:\ Ope nCV \ opencv \ modules \ features2d \ src \ draw.cpp,第115行   C:\ OpenCV \ opencv \ modules \ features2d \ src \ draw.cpp:115:错误:(-215)!outImage.em pty()函数drawKeypoints

代码:

#include <QCoreApplication>
#include <iostream>

#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv/cv.h"
#include <opencv2/nonfree/features2d.hpp>

using namespace std;
using namespace cv;

int main(int argc, char *argv[])
{
   // QCoreApplication a(argc, argv);
    cout << "Hello World!" << endl;

    try {
    cv::Mat image = cv::imread("lena.jpg",0);
    // Create smart pointer for SIFT feature detector.
     cv::Ptr<FeatureDetector> featureDetector = cv::FeatureDetector::create("SIFT");
     cv::vector<KeyPoint> keypoints;

     // Detect the keypoints
     featureDetector->detect(image, keypoints); // NOTE: featureDetector is a pointer hence the '->'.

     //Similarly, we create a smart pointer to the SIFT extractor.
     cv::Ptr<DescriptorExtractor> featureExtractor = cv::DescriptorExtractor::create("SIFT");

     // Compute the 128 dimension SIFT descriptor at each keypoint.
     // Each row in "descriptors" correspond to the SIFT descriptor for each keypoint
     cv::Mat descriptors;
     featureExtractor->compute(image, keypoints, descriptors);

     // If you would like to draw the detected keypoint just to check
     cv::Mat outputImage;
     cv::Scalar keypointColor = cv::Scalar(255, 0, 0);     // Blue keypoints.
     drawKeypoints(image, keypoints, outputImage, keypointColor, cv::DrawMatchesFlags::DEFAULT);

     cvNamedWindow("Output");
     cv::imshow("Output", outputImage);

     char c = ' ';
     cvWaitKey(0);

    }
    catch(cv::Exception e)
    {
        cout<< e.msg;
    }

    return 0;
}
<。ppro文件的内容

 INCLUDEPATH += "C:\\OpenCV\\opencv\\build\\x64\\mingw\\bin\\install\\include" \
                   "C:\\OpenCV\\opencv\\build\\x64\\mingw\\bin\\install\\include\\opencv"
     

\                          &#34; C:\的OpenCV \的OpenCV \建立\ 64 \ mingw的\ BIN \安装\包括\ opencv2&#34;

    LIBS += -L"C:\\OpenCV\\opencv\\build\\x64\\mingw\\bin\\install\\lib" \
        -lopencv_core244d \
        -lopencv_highgui244d \
        -lopencv_imgproc244d \
        -lopencv_features2d244d \
        -lopencv_nonfree244d

我已检查lena.jpg是否存在于工作目录中

1 个答案:

答案 0 :(得分:3)

调用cv :: initModule_nonfree();在主要方面,在做任何其他事情之前