Explorerli 2019-03-02 14:26 采纳率: 0%
浏览 6758
已结题

VS2017下opencv_4.0.1使用SIFT算法时为何总是在detect函数(detectAndCompute也是)处报内存错误?

环境:

  • windows
  • vistual studio2017
  • opencv_4.0.1

前提:

  • 已配置过opencv_contrib-4.0.1
  • 使用 debug ✖64

问题描述:

总是在detect(detectAndCompute也是)这个函数位置处出现错误:

0x00007FFB87B3A388 处(位于 image.exe 中)有未经处理的异常: Microsoft C++ 异常: cv::Exception,位于内存位置 0x0000001D36F1E9F0 处。

代码如下:

#include <iostream>
#include <opencv2/opencv.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/xfeatures2d.hpp>
#include <opencv2/xfeatures2d/nonfree.hpp>
#include <opencv2/features2d/features2d.hpp>
#include <vector>

using namespace std;
using namespace cv;
using namespace xfeatures2d;
using namespace cv::xfeatures2d;

int main()
{
    //Feature2D siftfd;
    SIFT siftfd;
    //Ptr<SIFT> siftfd = SIFT::create();
    //SiftFeatureDetector  siftfd;
    //sift s;
    //s.create();
    Mat image1 = imread("car1.jpg");
    Mat image2 = imread("car2.jpg");
    namedWindow("car1_before", WINDOW_FREERATIO);
    namedWindow("car2_before", WINDOW_FREERATIO);
    imshow("car1_before", image1);
    imshow("car2_before", image2);

    //ptr<siftfeaturedetector> siftfd = siftfeaturedetector::create();
    //ptr<sift> siftfd = sift::create();
    //feature2d siftfd;
    //vector<KeyPoint>kp1, kp2; //keypoint类型的容器
    vector<KeyPoint>kp1;
    Mat draw;
    //kp1.resize(100);
    //kp2.resize(100);

    //siftfd.detectAndCompute(image1, Mat(), kp1, draw);
    siftfd.detect(image1, kp1);
    Mat outimage1;
    drawKeypoints(image1, kp1, outimage1);
    namedWindow("car1_after", WINDOW_FREERATIO);
    imshow("car1_after", outimage1);

    waitKey();
    return 0;

报错情况:
图片说明

  • 写回答

3条回答 默认 最新

  • Black_Friend 2019-08-13 15:13
    关注

    因为使用了智能指针....Ptr,而且为他进行了初始化。。。
    而且在新的版本中用SIFT和SURF都需要用到nofree模块,在用Cmake重新编译opencv库后,使用SURF,SIFT定义的时候直接写类名会报错,使用智能指针Ptr就可以解决。。。。这里我也是有疑惑的.....具体不是很理解,望各位大佬给个解释.

    评论

报告相同问题?

悬赏问题

  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码