怎样用opencv语句求二值化图像总的灰度值
展开全部
#include <iostream>
#include <cv.h>
#include <cxcore.h>
#include <highgui.h>
using namespace std;
void main()
{
IplImage* src_img=cvLoadImage("0.bmp"); //导入图片
size_t total=0; //图像总灰度值
size_t intensity = 0; //每个像素灰度值
size_t height=src_img->height;
size_t width =src_img->width;
for (size_t rows=0;rows<height;rows++)
{
uchar* ptr = (uchar*)src_img->imageData+rows*width;
for (size_t cols=0;cols<width;cols++)
{
intensity=(int)ptr[cols];
// cout<<intensity<<"\t";
if(intensity)
total+=intensity;
}
}
cout<<"图像总的灰度值为:"<<total<<endl;
}
#include <cv.h>
#include <cxcore.h>
#include <highgui.h>
using namespace std;
void main()
{
IplImage* src_img=cvLoadImage("0.bmp"); //导入图片
size_t total=0; //图像总灰度值
size_t intensity = 0; //每个像素灰度值
size_t height=src_img->height;
size_t width =src_img->width;
for (size_t rows=0;rows<height;rows++)
{
uchar* ptr = (uchar*)src_img->imageData+rows*width;
for (size_t cols=0;cols<width;cols++)
{
intensity=(int)ptr[cols];
// cout<<intensity<<"\t";
if(intensity)
total+=intensity;
}
}
cout<<"图像总的灰度值为:"<<total<<endl;
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询