OpenCV的 - 黑色像素数计数 [英] OpenCV - Counting number of black pixels

查看:621
本文介绍了OpenCV的 - 黑色像素数计数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个二进制图像。内的感兴趣的特定区域,我需要计数黑像素的数量。总是有通过像素循环计数他们的方式,但我正在寻找一个更有效的方法,因为我需要做的是实时的。

I have a binary image. Within a certain region of interest, I need to count the number of black pixels. There is always the way of looping through the pixels and counting them, but I'm looking for a more efficient method as I need to do it real-time.

我发现了一种计数非零像素的数量(使用cvCountNonZero())。是否有计数为零像素任何这样的等价功能(好像没有,据我见过的是)?如果没有,什么是最有效的方法来计算黑色像素?

I found a way to count the number of nonzero pixels(using cvCountNonZero()). Is there any such equivalent function for counting zero pixels (there doesn't seem to be as far as I've seen)? If not, what is the most efficient way to count the black pixels?

推荐答案

我相信数量的零像素的可以被看作是:

I believe the number of zero pixels could be seen as:

int TotalNumberOfPixels = width * height;
int ZeroPixels = TotalNumberOfPixels - cvCountNonZero(cv_image);

这篇关于OpenCV的 - 黑色像素数计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆