資源簡(jiǎn)介
Niblack二值化算法在opencv2下的實(shí)現(xiàn)。參考文獻(xiàn):http://www.cnblogs.com/nani/archive/2012/12/12/2814324.html http://blog.csdn.net/lucayhaozi/article/details/9967963 僅供參考。歡迎寶貴意見。
代碼片段和文件信息
#include?“stdafx.h“
#include?
using?namespace?cv;
//using?namespace?std;
//參數(shù)Win_width窗口寬度,Win_height窗口高度,k為修正系數(shù)(通常取-0.1)
void?Niblack(Mat?&srcImg?Mat?&binImg?int?Win_width?int?Win_height?double?k)
{
srcImg.convertTo(srcImg?CV_64F);
int?width?=?srcImg.cols;
int?height?=?srcImg.rows;
binImg.create(height?width?CV_64FC1);
for(int?j?=?0;?j? {
double?*srcptr?=?srcImg.ptr(j);
double?*dstptr?=?binImg.ptr(j);
for(int?i?=?0;?i? {
int?begin_y?=?j?-?Win_height?begin_x?=?i?-?Win_width;
int?end_y?=?j?+?Win_height?end_x?=?i?+?Win_width;
if(begin_y?0)?begin_y?=?0;
if(begin_x?0)?begin_x?=?0;
if(end_y?>=?height)?end_y?=?height-1;
if(end_x?>=?width?)?end_x?=?width?-1;
int?total?=?(?end_y?-?begin_y?+1?)?*?(?end_x?-?begin_x?+1?);??//該窗口內(nèi)總的像素點(diǎn)數(shù)
double?mean?=?0;//均值
double?std??=?0;//標(biāo)準(zhǔn)差
for(int?y?=?begin_y;?y {
double?*ptrWin?=?sr
- 上一篇:2DPCA人臉識(shí)別
- 下一篇:minix源代碼
評(píng)論
共有 條評(píng)論