OpenCV C++ コードの一部に問題があります。
double getVectorMedian( vector<double> values )
{
size_t size = values.size();
double median;
sort(values.begin(), values.end());
if( size % 2 == 0 )
{
median = (values[size / 2 - 1] + values[size / 2]) / 2;
}
else
{
median = values[size / 2];
}
return median;
}
void cleanSquares( const vector<vector<Point> >& squares )
{
float tolerance = 0.2;
size_t size = squares.size();
vector<double> areas(size);
for( size_t i = 0; i < size; i++ )
{
areas[i] = fabs(contourArea(Mat(squares[i])));
}
double medianArea = getVectorMedian(areas);
double minArea = medianArea * (1 - tolerance);
double maxArea = medianArea * (1 + tolerance);
for( unsigned int i = size - 1; i >= 0; i--)
{
if( areas[i] > maxArea || areas[i] < minArea )
{
squares.erase(squares.begin() + i); // Here I get the error
}
}
}
私が得ているエラーは
no matching function for call to ‘std::vector<std::vector<cv::Point_<int> > >::erase(__gnu_cxx::__normal_iterator<const std::vector<cv::Point_<int> >*, std::vector<std::vector<cv::Point_<int> > > >) const’ main.cpp /find_notes/src line 154 C/C++ Problem
OpenCV squares.cpp サンプル プログラムを変更していて、画像にある正方形の中央値と大きく異なるすべての正方形を削除したいと考えています。
最後に cleanSquares で後方ループを作成し、各正方形が大きく異なるかどうかを確認します。その場合、そのベクトルを正方形ベクトルから消去します。私は何を間違っていますか?