OpenCV SIFT 提取器失败

标签 opencv qt-creator sift

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

OpenCV Error: Assertion failed (!outImage.empty()) in drawKeypoints,file C:\Ope nCV\opencv\modules\features2d\src\draw.cpp, line 115 C:\OpenCV\opencv\modules\features2d\src\draw.cpp:115: error: (-215) !outImage.em pty() in function 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;
}

.pro 文件的内容

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

\ "C:\OpenCV\opencv\build\x64\mingw\bin\install\include\opencv2"

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

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

最佳答案

调用 cv::initModule_nonfree();主要是在做其他事情之前

关于OpenCV SIFT 提取器失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18341971/

相关文章:

python - 使用 Opencv SIFT 时 matches1to2 出错

c++ - 如何在 qt 5.3.0 中使用 qml 分析器?

c++ - 只有 5 个并发线程的 Pthread_create 错误 11

python - OpenCV 在相机午餐时显示 err.message

c++ - 如何在 qt4 设计器中创建自定义插槽?

macos - Mac 上 Qt Creator 的单文档界面

python - 你能将 opencv SIFT 与 tensorflow 模型集成吗?

c++ - OpenCV 的 SiftDescriptorExtractor 如何转换描述符值?

python - OpenCV imread 透明度消失了

c++ - 从 body 提取掩码计算边界框