更新时间:2022-06-25 20:56:28
假设 Color
单通道 cv :: Mat
,您可以使用重载的运算符==
和 cv :: countNonZero ()
做你想做的。 operator ==
返回一个掩码,其中如果 Color
中的值与 j
,否则为零。
Assuming Color
is a properly initialized single-channel cv::Mat
, you can use the combination of overloaded operator==
and cv::countNonZero()
to do what you wish. operator==
returns a mask where each element is one if the value in Color
matches j
, or zero otherwise.
if(cv::countNonZero(Color == j))
{
// Do something...
}