當我運行下面的代碼我得到這個例外矢量下標超出範圍,該代碼成功地工作沒有例外的圖像上,但是當我改變的圖像發生異常。矢量標超出範圍C++誤差
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;
}
什麼'i'?您可以將其包含在此代碼段中,而不必提及它是什麼或來自哪裏。你應該在這裏使用迭代器而不是直接的下標訪問。 – mwigdahl
你在哪裏設置'我'? – Barmar
我是要找到的輪廓點#圖像中我嘗試過的圖像上的代碼無一例外但是當我改變形象它給了我矢量下標越界異常 – shahd