【发布时间】:2012-08-22 09:29:35
【问题描述】:
我想计算只有黑白的背景图像中白点的数量。我有这样的代码:
int count = 0;
for ( int j = 0; j < Image.rows; j ++ )
{
for ( int i = 0; i < Image.cols; i ++ )
{
if ( Image.at<int>(i,j) >= 150 )
{
count ++ ;
}
}
}
由于某种原因,上面的代码不起作用,它只是停止反应。我检查了一下,“if (Image.at(i,j) >= 150)”行导致了问题。我的“图像”是“cv::Mat”,类型为“CV_8UC3”。有人可以帮助我吗?谢谢你。
【问题讨论】:
-
做一个
Image.at<int>(i,j)的cout -
不应该是
Image.at<int>(j,i)吗? -
非常感谢您的回复。 cout 部分结果是这样的: 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1109311264,11117845974,9668574984 ,0,0,0,0,0,0,0,0,0,0,0,0,2514654812,1101231542,121415421,0,0,0,0,0,0,0... 我改了进入“Image.at
(j,i)”,cout的输出是这样的:7745580006,-1869970562,1835821674,-1987475062,...有什么想法吗?
标签: c++ opencv matrix background-image pixel