当我运行以下代码时,我得到此异常向量下标超出范围,此代码在图像上成功运行,没有异常,但是当我更改图像时发生异常。
Mat bw;
inRange(output1, Scalar(low_h, low_s, low_v), Scalar(high_h, high_s, high_v), bw);
vector<vector<Point> > contours;
findContours(bw.clone(), contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE);
Mat dst = Mat::zeros(input_image.size(), input_image.type());
for(unsigned int i=0;i<contours.size();i++)
{
cout << "# of contour points: " << contours[i].size() << endl ;
for(unsigned int j=0;j<contours[i].size();j++)
{
cout << "Point(x,y)=" << contours[i][j]<< endl;
}
cout << " Area: " << cv::contourArea(cv::Mat(contours[i], false)) << endl;
std::vector<std::vector<cv::Point> >::iterator itc= contours.begin();
while (itc!=contours.end()) {
if (contours[i].size()>500 || contours[i].size()<20 )
itc= contours.erase(itc);
else
++itc;
}