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

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 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler