我刚刚开始学习如何使用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;
}
这是库中的错误,还是我做了一些愚蠢的事情?
答案 0 :(得分:0)
在调用goodFeatures之前,Img_features
向量可能有MAX_FEATURES
项吗?即在调用goodFeatures之前尝试Img_features.resize(MAX_FEATURES)
。