感谢所有反馈。我是一个白痴,因为答案非常耐心地指出:问题在于mParams.amount的值,该界面没有正确更新。我不知道为什么我没有明确地检查它或在调试器中注意到它。只是其中一天。
我提供整个功能的原因是因为我完全感到困惑的是为什么事情不起作用并且担心围绕迭代器可能存在某种上下文问题 - 但正如上面所说它只需要更多一点常识。
我正在尝试使用迭代器在四通道规范化的float cv :: Mat上实现对比度过滤器,如下所示:
void FilterDepthContrast::process(cv::Mat& data)
{
typedef cv::Vec<float, 4> V;
V mid = V(.5, .5, .5, .5);
for (auto v=data.begin<V>(); v!=data.end<V>(); ++v)
{
V distanceFromMiddle = *v - mid;
cout << "v before " << *v << endl;
*v = mid + mParams.amount * distanceFromMiddle;
cout << "added on " << (mParams.amount * distanceFromMiddle) << endl;
cout << "v after " << *v << endl;
}
}
但是,* v的赋值似乎不起作用。这是印刷的内容:
v before (0.94902,0.960784,0.929412,0.211765)
added on (0.44902,0.460784,0.429412,-0.288235)
v after (0.94902,0.960784,0.929412,0.211765)
任何人都可以解释我对这个迭代器的错误以及如何修复它吗?
答案 0 :(得分:2)
您有V = (0.94902,0.960784,0.929412,0.211765)
和mid = (.5, .5, .5, .5)
所以distanceFromMiddle = V - mid = (0.44902,0.460784,0.429412,-0.288235)
但cout << "added on " << (mParams.amount * distanceFromMiddle) << endl;
的输出
与distanceFromMiddle== (mParams.amount * distanceFromMiddle)
结论:mParams.amount == 1
答案 1 :(得分:1)
迭代器没有问题。 使用您的公式,您将在打印时获得结果。
了解具体方法:
V mid = V(.5, .5, .5, .5);
印刷初始* v = 0.94902,0.960784,0.929412,0.211765
申请
V distanceFromMiddle = *v - mid;
distanceFromMiddle =(0.44902,0.460784,0.429412,-0.288235)
同样印刷, (mParams.amount * distanceFromMiddle)=(0.44902,0.460784,0.429412,-0.288235)
现在申请
*v = mid + mParams.amount * distanceFromMiddle;
(。5,.5,.5,.5)+(0.44902,0.460784,0.429412,-0.288235)=(0.94902,0.960784,0.929412,0.211765)
我认为问题出现是因为mParams.amount = 1。