Mat 统计白点数(未完成)
留给自己看的一个存根。。大家忽略
//opencv2.0风格
#include "cv.h"
#include "highgui.h"
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/core/core.hpp>
#include <iostream>
#include <string>
#include <cstdio>
using namespace std;
using namespace cv;
using namespace std;
void Image_Stat(Mat img)
{
int i,j,width,height,step,chanel;
unsigned char *dataX;
width = img.cols;
height = img.rows;
//存入矩阵数据
dataX = (unsigned char *)img.data;
//计算步长
step = img.step/sizeof(char);
chanel = img.channels();
int count=0;
//一个个数据处理
for(i=0; i<height; i++)
for(j=0; j<width*chanel; j++)
if(dataX[i*step+j] == 255)
count++;
int area=width*height;
cout<<"长 == "<<width<<" 宽 == "<<height<<endl;
cout<<"面积 == "<<area<<endl;
cout<<"count == "<<count<<endl;
cout<<"占比 == "<<(double)count/area<<endl;
}
int main()
{
Mat img;
//img = imread("mmr_out.jpg");
img = imread("zcr_out.jpg");
//图像差分,最最关键的一步
Image_Stat(img);
imshow("img",img);
cvWaitKey(0);
//销毁窗口
return 0;
}
最后更新:2017-04-03 05:40:12