閱讀656 返回首頁    go 技術社區[雲棲]


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

  上一篇:go Java4Android之BlockingQueue
  下一篇:go WordPress主題後門嚴重威脅網站安全