默卿 2018-02-04 11:42 采纳率: 0%
浏览 1121
已结题

新手OpenCV2.4.9运行SURF跳错debug assertion failed。

百度上说时野指针或者内存溢出,怎么解决?
#include "stdafx.h"
#include
#include
#include
#include
using namespace cv;
using namespace std;

int main(int argc, char** argv)
{
system("color 6F");

Mat trainImage = imread("1.jpg"), trainImage_gray;
imshow("原始图", trainImage);
cvtColor(trainImage, trainImage_gray, CV_BGR2GRAY);

//检测surf关键点,提取训练图像描述符
vector<KeyPoint>train_keyPoint;
Mat trainDescriptor;
SurfFeatureDetector featureDetector(80);
featureDetector.detect(trainImage_gray, train_keyPoint);
SurfDescriptorExtractor featureExtractor;
featureExtractor.compute(trainImage_gray, train_keyPoint, trainDescriptor);

//创建基于FLANN的描述符匹配对象
FlannBasedMatcher matcher;
vector<Mat> train_desc_collection(1, trainDescriptor);
matcher.add(train_desc_collection);
matcher.train();

//创建视屏对象、定义帧率
VideoCapture cap(0);
unsigned int frameCount = 0;//帧数

vector<KeyPoint> test_keyPoint;
vector<vector<DMatch>> matches;
vector<DMatch> goodMatches;
//不断循环直到q键被按下
while (char(waitKey(1)) != 'q')
{
    //<1>参数设置
    int64 time0 = getTickCount();
    Mat testImage, testImage_gray;
    cap >> testImage;//采集视屏到testImage中
    if (testImage.empty())
    {
        continue;
    }
    //<2>转化图像到灰度
    cvtColor(testImage, testImage_gray, CV_BGR2GRAY);
    //<3>检测S关键点、提取测试图像描述符
    Mat testDescriptor;
    featureDetector.detect(testImage_gray, test_keyPoint);
    featureExtractor.compute(testImage_gray, test_keyPoint, testDescriptor);

    //<4>匹配训练和测试描述符
    matcher.knnMatch(testDescriptor, matches, 2);
    //<5>根据劳氏算法得到优秀的匹配点
    for (unsigned int i = 0; i < matches.size(); i++)
    {
        if (matches[i][0].distance < 0.6 * matches[i][1].distance)
            goodMatches.push_back(matches[i][0]);
    }

    //<6>绘制匹配点并显示窗口
    Mat dstImage;
    drawMatches(testImage, test_keyPoint, trainImage, train_keyPoint, goodMatches, dstImage);
    imshow("匹配窗口", dstImage);

    cout << "当前帧率为:" << getTickFrequency() / (getTickCount() - time0) << endl;
    test_keyPoint.clear();
    matches.clear();
    goodMatches.clear();
}
return 0;

}

图片说明

  • 写回答

2条回答

  • lfcxjcxj 2018-02-04 12:27
    关注

    你罗列了这么一大堆代码,不知道是哪行出的问题啊。你单步,然后把运行到那一行的代码指出来,这样大家可能会有针对性的看了~

    评论

报告相同问题?

悬赏问题

  • ¥15 matlab实现基于主成分变换的图像融合。
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊