更新时间:2023-11-09 23:30:34
if(imageDataVector[i] < threshold)
imageDataVector.erase(imageDataVector.end()-j);
应该是:
if(imageDataVector[j] < threshold)
imageDataVector.erase(imageDataVector.begin()+j);
为完整起见,使用擦除删除方式和迭代器方式:
for completeness, the erase-remove way and the iterator way:
imageDataVector.erase(std::remove_if(imageDataVector.begin(), imageDataVector.end(), std::bind2nd(std::less<vector_data_type>(), threshold)), imageDataVector.end());
vector<type>::iterator it = imageDataVector.begin();
while (it != imageDataVector.end()) {
if (*it < threshold)
it = imageDataVector.erase(it);
else
++it;
}