OpenCV 2.4.0 C++ goodFeaturesToTrack corrupts heap?
我现在才开始学习如何使用openCV库。我已经下载并安装了openCV 2.4.0,并运行了一些示例项目。在这段代码中,我试图从goodFeaturesToTrack获取输出并在图像上绘制点。代码可以编译,但是每次运行它都会崩溃,并且出现以下错误:
Windows在Corner.exe中触发了一个断点。
这可能是由于堆损坏所致,这表明Corner.exe或其已加载的任何DLL中都有错误。
这也可能是由于用户在Corner.exe具有焦点时按下了F12。
输出窗口可能包含更多诊断信息。
输出窗口没有更多的诊断信息。我已将错误跟踪到goodFeaturesToTrack函数。这是令人反感的代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | // 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; } |
这是库中的错误,还是我在做一些愚蠢的事情?
在调用goodFeatures之前,