JM9*_*M92 12 c++ opencv compare matrix
我有一个根据以下代码动态更改的矩阵;
for( It=all_frames.begin(); It != all_frames.end(); ++It)
{
ItTemp = *It;
subtract(ItTemp, Base, NewData);
cout << "The size of the new data for ";
cout << " is \n" << NewData.rows << "x" << NewData.cols << endl;
cout << "The New Data is: \n" << NewData << endl << endl;
NewData_Vector.push_back(NewData.clone());
}
Run Code Online (Sandbox Code Playgroud)
我想要做的是确定cv :: Mat NewData是零矩阵的帧.我已经尝试将它与具有相同大小的零矩阵进行比较,使用cv :: compare()函数和简单运算符(即NewData == NoData),但我甚至无法编译程序.
有一种简单的方法可以确定cv :: Mat何时被零填充?
JM9*_*M92 23
我用了
if (countNonZero(NewData) < 1)
{
cout << "Eye contact occurs in this frame" << endl;
}
Run Code Online (Sandbox Code Playgroud)
这是一个非常简单(如果不是最优雅)的方式.
tom*_*234 14
要检查mat是否为空,请使用empty(),如果NewData是cv :: Mat,NewData.empty()如果NewData中没有元素,则返回true.
要检查它是否全为零,简单地说,NewData == Mat::zeros(NewData.size(), NewData.type()).
更新:
检查OpenCV源代码后,您实际上NewData == 0可以检查所有元素是否等于0.
| 归档时间: |
|
| 查看次数: |
33984 次 |
| 最近记录: |