Mat 统计白点数(未完成)

来源:互联网 发布:思考的艺术 知乎 编辑:程序博客网 时间:2024/06/08 07:21

留给自己看的一个存根。。大家忽略


//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;}



0 0
原创粉丝点击