二值化图像中统计每列行白点的数量

opencv 统计一列或者一行种某个像素的数量
二值化种统计每列行白点的数量

int nRow = thresh.rows;
int nCol = thresh.cols;
int cnt =0;
for (int i = 0; i < nRow; i++)
{
uchar *data = thresh.ptr<uchar>(i);
for (int j = 0; j < nCol; j++)
{
if (*data == 255)
cnt ++;
*data++;
}
// 数量的阈值
if(cnt < 200)
{
uchar *da = thresh.ptr<uchar>(i);
for (int j = 0; j < nCol; j++)
{
*da =0;
*da++;
}
}else
{
uchar *da = thresh.ptr<uchar>(i);
for (int j = 0; j < nCol; j++)
{
*da =255;
*da++;
}
}
printf("%d point count: %d\n",i,cnt);
cnt =0;
}

sitemap