这是我的代码,它有什么问题?
itc = contours.erase(itc)发出此错误。我在调试模式下运行它。 我使用open cv 2.4.10和visual studio 2013。 和调用堆栈是:
msvcp120d.dll!5bd8dfdd()未知 [下面的框架可能不正确和/或缺失,没有为msvcp120d.dll加载符号]
ConsoleApplication3.exe!main(int argc,char * * argv)第84行C ++
#include "stdafx.h"
#include "highgui.h"
#include "opencv2\opencv.hpp"
#include "opencv2\imgproc\imgproc.hpp"
using namespace cv;
using namespace std;
bool verifySizes(RotatedRect mr){
float error = 0.4;
//Spain car plate size: 52x11 aspect 4,7272
float aspect = 4.7272;
//Set a min and max area. All other patchs are discarded
int min = 15 * aspect * 15; // minimum area
int max = 125 * aspect * 125; // maximum area
//Get only patchs that match to a respect ratio.
float rmin = aspect - aspect*error;
float rmax = aspect + aspect*error;
int area = mr.size.height * mr.size.width;
float r = (float)mr.size.width / (float)mr.size.height;
if (r < 1)
r = (float)mr.size.height / (float)mr.size.width;
if ((area < min || area > max) || (r < rmin || r > rmax)){
return false;
}
else{
return true;
}
}
int main(int argc, char** argv)
{
cv::Mat image = imread("d://untitled.jpg", cv::IMREAD_GRAYSCALE);
cv::imshow("orginal", image);
cv::equalizeHist(image, image);
cv::imshow("histeq", image);
cv::Canny(image, image, 100, 300, 3, true);
cv::imshow("canny", image);
Mat img_sobel;
cv::Sobel(image, img_sobel, CV_8U, 1, 0, 3, 1, 0, BORDER_DEFAULT);
cv::imshow("sobel", img_sobel);
Mat element = getStructuringElement(MORPH_RECT, Size(17, 3));
morphologyEx(img_sobel, img_sobel, CV_MOP_CLOSE, element);
cv::imshow("morph", img_sobel);
vector< vector< Point> > contours;
findContours(img_sobel,
contours, // a vector of contours
CV_RETR_EXTERNAL, // retrieve the external contours
CV_CHAIN_APPROX_NONE);
vector<vector<Point>>::iterator itc = contours.begin();
vector<RotatedRect> rects;
while (itc != contours.end()) {
//Create bounding rect of object
RotatedRect mr = minAreaRect(Mat(*itc));
if (!verifySizes(mr)){
itc = contours.erase(itc);
}
else{
++itc;
rects.push_back(mr);
}
}
cv::waitKey();
}