目录
说明
检查这个Mat是否为Vector,用来确认传入的数据格式是否正确。
源码
int Mat::checkVector(int _elemChannels, int _depth, bool _requireContinuous) const
{
return data && (depth() == _depth || _depth <= 0) &&
(isContinuous() || !_requireContinuous) &&
((dims == 2 && (((rows == 1 || cols == 1) && channels() == _elemChannels) ||
(cols == _elemChannels && channels() == 1))) ||
(dims == 3 && channels() == 1 && size.p[2] == _elemChannels && (size.p[0] == 1 || size.p[1] == 1) &&
(isContinuous() || step.p[1] == step.p[2]*size.p[2])))
? (int)(total()*channels()/_elemChannels) : -1;
}
分析
这个函数就一句话,用的是三目运算符:?
? 之前的所有条件都满足了才能返回矩阵中元素的个数,否则返回-1.
注意:一个元素可能有多个通道。
下面是OpenCV中关于此函数的说明,大家可以参考。
-1 if the requirement is not satisfied.
Otherwise, it returns the number of elements in the matrix.
Note that an element may have multiple channels.
@param elemChannels Number of channels or number of columns the matrix should have.
* For a 2-D matrix, when the matrix has only 1 column, then it shou