opencv功能检测访问冲突

时间:2016-05-26 23:02:02

标签: c++ qt opencv feature-detection surf

我有一项任务是在QT中使用opencv实现图像对齐代码。所以我尝试用SURF特征检测器来做。 有趣的代码如下:

我的QT .pro文件

INCLUDEPATH += E:\Programme\opencv\build\include\opencv2
LIBS += -LE:\Programme\opencv\build\x64\vc12\lib\opencv_calib3d2413d.lib \
    E:\Programme\opencv\build\x64\vc12\lib\opencv_nonfree2413d.lib \
    E:\Programme\opencv\build\x64\vc12\lib\opencv_highgui2413d.lib \
    E:\Programme\opencv\build\x64\vc12\lib\opencv_features2d2413d.lib \
    E:\Programme\opencv\build\x64\vc12\lib\opencv_core2413d.lib \
    E:\Programme\opencv\build\x64\vc12\lib\opencv_flann2413d.lib \
    E:\Programme\opencv\build\x64\vc12\lib\opencv_imgproc2413d.lib \

是的,我试图将它们相对联系并用一条长路径然后只用文件名来做,但是没有运行。但我认为那不是那么重要......

my includes

#include "opencv2/core/core.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/nonfree/features2d.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/nonfree/nonfree.hpp"
#include "opencv2/calib3d/calib3d.hpp"
#include "cvmatandqimage.h"  
#include "opencv2/opencv.hpp"

cvmatandqimage.h来自这个项目:QImage to OpenCV matrix

主文件

void MainWindow::on_pushButton_4_clicked()
{
    using namespace cv;

    initModule_nonfree();

    SurfFeatureDetector detector(400);
    FlannBasedMatcher matcher;

    QImageReader reader(inputFiles.at(0));
    QImage image1 = reader.read();
    reader.setFileName(inputFiles.at(1));
    QImage image2 = reader.read();

    Mat cvColorImage1 = QtOcv::image2Mat(image1, CV_8UC3, QtOcv::MCO_RGB);
    Mat cvColorImage2 = QtOcv::image2Mat(image2, CV_8UC3, QtOcv::MCO_RGB);
    Mat cvGrayscaleImage1;
    Mat cvGrayscaleImage2;
    cvtColor(cvColorImage1,cvGrayscaleImage1,CV_RGB2GRAY);
    cvtColor(cvColorImage2,cvGrayscaleImage2,CV_RGB2GRAY);

    std::vector<KeyPoint> current_keypoints1, current_keypoints2;
    Mat current_descriptors1, current_descriptors2;

    detector.detect( cvGrayscaleImage1, current_keypoints1);
    detector.detect( cvGrayscaleImage2, current_keypoints2);


...
}

确定。现在来我的问题: 在调试时,它在detector.detect( cvGrayscaleImage1, current_keypoints1);

崩溃

错误大多数时候是Exception at 0x..., code: 0xc0000005: read access violation at: 0x0, flags=0x0

有时只会说error detected: execution can not be coninued 还有一些时候它会进入下一行并在那里崩溃。

opencv灰度图像在调试时看起来不错。所以我认为探测器是假的。但我大多数都使用与opencv文档相同的代码。 我包括了nonfree库,链接它并初始化它。 我不知道我做错了什么。

希望你能给我一些提示。

修改

好的,我想通了。 这是错误的链接。 这适用于调试模式:

LIBS += -LE:\Programme\opencv\build\x64\vc12\lib\
        -lopencv_calib3d2413d \
        -lopencv_nonfree2413d \
        -lopencv_highgui2413d \
        -lopencv_features2d2413d \
        -lopencv_core2413d \
        -lopencv_flann2413d \
        -lopencv_imgproc2413d \

但为什么这只适用于调试呢?

CONFIG(debug) {
   LIBS += -LE:\Programme\opencv\build\x64\vc12\lib\
        -lopencv_calib3d2413d \
        -lopencv_nonfree2413d \
        -lopencv_highgui2413d \
        -lopencv_features2d2413d \
        -lopencv_core2413d \
        -lopencv_flann2413d \
        -lopencv_imgproc2413d \
} else {
    LIBS += -LE:\Programme\opencv\build\x64\vc12\lib\
        -lopencv_calib3d2413 \
        -lopencv_nonfree2413 \
        -lopencv_highgui2413 \
        -lopencv_features2d2413 \
        -lopencv_core2413 \
        -lopencv_flann2413 \
        -lopencv_imgproc2413 \
}

0 个答案:

没有答案