我剛剛開始學習如何使用openCV庫。我已經下載並安裝了openCV 2.4.0,並運行了一些示例項目。在這段代碼中,我試圖從goodFeaturesToTrack獲取輸出並繪製圖像上的點。該代碼編譯,但我每次運行它的時候,它崩潰了,我收到以下錯誤:OpenCV 2.4.0 C++ 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;
}
是這個庫中的一個bug,還是我做了愚蠢的事情?
如果你沒有在代碼中的任何地方使用它,你爲什麼最終會顯示'Out'? – sgarizvi