是否有一种方法来查找两个cv :: Mat矩阵的元素是否在彼此的可接受范围内?如果A = [a,b,c,d,e,f]和B = [a±5%,b±5%,c±5%,d±5%,e±5% ,f±5%]Opencv cv ::垫公差间隔
我在想比较()函数可能会有用,但我不确定如何实现它。
是否有一种方法来查找两个cv :: Mat矩阵的元素是否在彼此的可接受范围内?如果A = [a,b,c,d,e,f]和B = [a±5%,b±5%,c±5%,d±5%,e±5% ,f±5%]Opencv cv ::垫公差间隔
我在想比较()函数可能会有用,但我不确定如何实现它。
我用这个,为了所需的效果:
cv::Mat Upperbound, Lowerbound;
cv::Mat Baseplus;
cv::Mat Baseminus;
Baseplus = 1.1*Base.clone();
Baseminus = 0.9*Base.clone();
compare(NewData, Baseminus, Lowerbound, CMP_GE);
compare(NewData, Baseplus, Upperbound, CMP_LE);
if (countNonZero(Lowerbound)>0)
{
if (countNonZero(Upperbound)>0)
{
if ((countNonZero(Upperbound)+countNonZero(Lowerbound))>4)
{
cout<<"Eye contact occurs in this frame"<<endl;
}
}
}
OpenCV的似乎并不具有可以做到这一点,我可以看到任何inbuilts,但敲东西了应该给予他们揭露迭代器是非常简单的:
template <typename T>
bool within_tolerance(const cv::Mat& m1, const cv::Mat& m2, const T& tolerance)
{
auto compare = [](const T& v1, const T& v2) -> bool
{ return std::abs(v1 - v2) < tolerance * v1; };
return std::equal(m1<T>.begin(), m1<T>.end(), m2<T>.begin(), compare);
}
编辑:我不认为硬足以说明比较;以上仅适用于无符号值。这可以用像v2 > (1 - tolerance) * v1 && v2 < (1 + tolerance) * v1
这样的东西来解决。