使用STD :: MAP在直方图峰周围的平均值
Averaging value around the histogram peak using std::map
我试图平均直方图周围的键。因此,我首先找到峰值,然后我的尝试是添加一个峰并从峰值索引中减去一个峰,以找到峰周围的平均键。我使用距离函数找到索引。但是,我找不到正确的解决方案,因为代码无法编译。有人可以帮忙吗?
int iterator_distance;
for ( std::map<float, int>::iterator it = histogram_x.begin(); it != histogram_x.end(); it++) {
if (max_occurence.x <= it->second ) {
max_occurence.x = it->second;
max_voted.x = it->first;
iterator_distance = std::distance(histogram_x.begin(), it);
//std::cout << x.first << " histogram " << x.second << "endxn";
}
}
// Average around the peak
if ( iterator_distance > 2 ) {
max_voted.x = (histogram_x.begin()+iterator_distance-1)->first + (histogram_x.begin()+iterator_distance)->first + (histogram_x.begin()+iterator_distance+1)->first;
}
以下是错误。错误说,加上运算符不能与迭代器和浮动一起使用。但这就是我的问题,我该如何解决这个问题?
error: no match for ‘operator+’ (operand types are ‘std::map<float, int>::iterator {aka std::_Rb_tree_iterator<std::pair<const float, int> >}’ and ‘int’)
max_voted.x = (histogram_x.begin()+iterator_distance)->first + (histogram_x.begin()+iterator_distance-1)->first;
这应该在C 11中起作用:
assert(histogram_x.size() > 0);
auto peak_it = std::max_element(histogram_x.cbegin(), histogram_x.cend(),
[](const pair<float, int>& lhs, const pair<float, int>& rhs) {
reutrn lhs.second < rhs.second; });
max_voted.x = peak_it->first;
if ((peak_it != histogram_x.begin()) && (peak_it != std::prev(histogram_x.end()))
max_voted.x += std::prev(peak_it)->first + std::next(peak_it)->first /* / 3.0f ??? */;
相关文章:
- 计算数组c++的平均值
- 计算平均值,不包括上次得分
- 彩色图像的卤化物处理平均值
- 如何创建一个函数来计算并返回平均值、最大值和最小值
- 按平均值替换数组中的元素
- 如何返回多个矢量对象的平均值?C++
- 将随机生成的数字添加到数组 + 对这些数组求平均值
- 查找数组中第一个最小值和最后一个最大值元素之间的算术平均值
- 制作具有平均值的随机数生成器
- 变量周围的堆栈'...'已损坏
- 运行时检查失败 #2 变量"A"周围的堆栈已损坏
- C++ 函数,用于查找传入的 N 个数字的平均值、总和、最小值和最大值
- OpenCV代码不会检测人脸的数量,也不会在脸周围放一个圆圈
- 如何使用对象制作分数列表并获得平均值
- 为什么我的 VS 代码调试器在我的C++代码周围弹跳?
- 浮点格式数组的平均值
- 在二叉搜索树C++中计算平均值
- 运行时检查失败 #2 - 变量"e"周围的堆栈已损坏。发生
- 变量周围的堆栈'sortArray'已损坏
- 使用STD :: MAP在直方图峰周围的平均值