gpt4 book ai didi

c++ - OpenCV 2.4.0 C++ goodFeaturesToTrack 损坏堆?

转载 作者:太空宇宙 更新时间:2023-11-04 14:12:55 24 4
gpt4 key购买 nike

我刚刚开始学习如何使用 openCV 库。我已经下载并安装了 openCV 2.4.0,并运行了一些示例项目。在此代码块中,我试图从 goodFeaturesToTrack 获取输出并在图像上绘制点。代码可以编译,但每次运行时都会崩溃,并出现以下错误:


Windows 已在 Corner.exe 中触发断点。

这可能是由于堆损坏,这表明 Corner.exe 或它加载的任何 DLL 中存在错误。

这也可能是由于用户在 Corner.exe 具有焦点时按了 F12。

输出窗口可能有更多的诊断信息。


输出窗口没有更多的诊断信息。我已将错误追溯到 goodFeaturesToTrack 函数。这是有问题的代码:

// Corner.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <opencv.hpp>
#include <opencv_modules.hpp>
#include <opencv2\core\core.hpp>
#include <opencv2\highgui\highgui.hpp>

#include <iostream>
#include <string>
#include <iomanip>
#include <sstream>

using namespace cv; //If you don't have this, you won't be able to create a mat...
using namespace std;


#include <stdio.h>
#include <cv.h>
#include <highgui.h>
#include <math.h>

//Whole bunch of #defines to make editing the code a lot easier

#define MAX_FEATURES 5
#define FILENAME "C:/Users/Mitchell/Desktop/lol.jpg"

int main(void)
{
namedWindow("Out", CV_WINDOW_AUTOSIZE);
namedWindow("In", CV_WINDOW_AUTOSIZE);
Mat Img;
Img = cvLoadImage(FILENAME, CV_LOAD_IMAGE_GRAYSCALE);

if(!Img.data)
{
fprintf(stderr, "ERROR: Couldn't open picture.");
waitKey();
return -1;
}

else
{
imshow("In", Img);
waitKey();
}

std::vector<cv::Point2f> Img_features;
int number_of_features = MAX_FEATURES;

Mat Out = Mat::zeros(Img.cols, Img.rows, CV_32F);

goodFeaturesToTrack(Img, Img_features, MAX_FEATURES, .01, .1, noArray(), 3, false);

fprintf(stdout, "Got here...");

/*for (int i = 0; i < MAX_FEATURES; i++)
{
Point2f p = Img_features[i];
ellipse(Img, p, Size(1,1), 0, 0, 360, Scalar(255,0,0));
}*/

imshow("Out", Out);

waitKey(0);
return 0;


}

这是库中的错误,还是我在做一些愚蠢的事情?

最佳答案

可能是 Img_features vector 在调用 goodFeatures 之前应该有 MAX_FEATURES 项?即在调用 goodFeatures 之前尝试 Img_features.resize(MAX_FEATURES)

关于c++ - OpenCV 2.4.0 C++ goodFeaturesToTrack 损坏堆?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13302079/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com