www.久久久久|狼友网站av天堂|精品国产无码a片|一级av色欲av|91在线播放视频|亚洲无码主播在线|国产精品草久在线|明星AV网站在线|污污内射久久一区|婷婷综合视频网站

當(dāng)前位置:首頁 > > 充電吧
[導(dǎo)讀]最近工作中遇到身份證上次需要驗(yàn)證問題,在網(wǎng)上搜索了大量信息,大概都是用tess-two庫實(shí)現(xiàn),但識別率不是很高,在它基礎(chǔ)上,做了點(diǎn)優(yōu)化,識別率比它高那么點(diǎn)所做的優(yōu)化方式就是,對圖片進(jìn)行二值化以及灰度化

最近工作中遇到身份證上次需要驗(yàn)證問題,在網(wǎng)上搜索了大量信息,大概都是用tess-two庫實(shí)現(xiàn),但識別率不是很高,在它基礎(chǔ)上,做了點(diǎn)優(yōu)化,識別率比它高那么點(diǎn)


所做的優(yōu)化方式就是,對圖片進(jìn)行二值化以及灰度化,然后再獲取圖片上的信息,至少能獲取到身份證號碼,其他中文字實(shí)在是無法匹配。


編程工具為:eclipse


首先需要做的步驟是:1、有下載tess-two庫,當(dāng)然,需要包括.so文件的,不然你還需要編譯一遍,編譯步驟需要在網(wǎng)上找,在上篇文章中寫了編譯過程中出現(xiàn)的問題,可以借鑒下, 現(xiàn)在提供下未做修改的代碼下載地址:http://download.csdn.net/detail/a1031359915/9523864

將chi_sim.traineddata文件拷貝到/mnt/sdcard/tesseract/目錄下。


下面是優(yōu)化的代碼:



import?java.io.File;

import?com.googlecode.tesseract.android.TessBaseAPI;
import?com.googlecode.tesseract.android.test.R;

import?android.app.Activity;
import?android.graphics.Bitmap;
import?android.graphics.BitmapFactory;
import?android.os.Bundle;
import?android.widget.ImageView;
import?android.widget.TextView;

public?class?TestActivity?extends?Activity?{
	private?static?final?String?TESSBASE_PATH?=?"/mnt/sdcard/tesseract/";??
????private?static?final?String?DEFAULT_LANGUAGE?=?"eng";??
????private?static?final?String?CHINESE_LANGUAGE?=?"chi_sim";?//?chi_tra?chi_sim
	@Override
	protected?void?onCreate(Bundle?savedInstanceState)?{
		//?TODO?Auto-generated?method?stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.test);
		ImageView?img?=?(ImageView)?findViewById(R.id.img);
	???????
	?????????
	??????????????TessBaseAPI?baseApi?=?new?TessBaseAPI();??
	??????????????baseApi.init(TESSBASE_PATH,?CHINESE_LANGUAGE);??
//	???????baseApi.setPageSegMode(TessBaseAPI.PageSegMode.PSM_AUTO);??
//	???????File?file?=?new?File("/mnt/sdcard/sf.jpg");
//	???????if?(file.exists()){
//	????	???baseApi.setImage(file);??
//	???????}
	?????????Bitmap?bitmap?=?BitmapFactory.decodeFile("/mnt/sdcard/sf.jpg");
	?????????bitmap?=??ImageFilter.gray2Binary(bitmap);//?圖片二值化
	?????????bitmap?=??ImageFilter.grayScaleImage(bitmap);//?圖片灰度化
	?????????img.setImageBitmap(bitmap);
	?????????baseApi.setImage(bitmap);??
	???????//?Ensure?that?the?result?is?correct.??
	???????final?String?outputText?=?baseApi.getUTF8Text();??
	???????TextView?view?=?(TextView)?findViewById(R.id.tv_test);
	???????view.setText(outputText);
	???????baseApi.end();?
	}
}


圖片處理類:



import?android.graphics.Bitmap;
import?android.graphics.Bitmap.Config;
import?android.graphics.Canvas;
import?android.graphics.Color;
import?android.graphics.ColorMatrix;
import?android.graphics.ColorMatrixColorFilter;
import?android.graphics.Paint;
import?android.util.Log;

public?class?ImageFilter?{

	//?圖像灰度化
	public?static?Bitmap?bitmap2Gray(Bitmap?bmSrc)?{
		//?得到圖片的長和寬
		int?width?=?bmSrc.getWidth();
		int?height?=?bmSrc.getHeight();
		//?創(chuàng)建目標(biāo)灰度圖像
		Bitmap?bmpGray?=?null;
		bmpGray?=?Bitmap.createBitmap(width,?height,?Bitmap.Config.ARGB_8888);
		//?創(chuàng)建畫布
		Canvas?c?=?new?Canvas(bmpGray);
		Paint?paint?=?new?Paint();
		ColorMatrix?cm?=?new?ColorMatrix();
		cm.setSaturation(0);
		ColorMatrixColorFilter?f?=?new?ColorMatrixColorFilter(cm);
		paint.setColorFilter(f);
		c.drawBitmap(bmSrc,?0,?0,?paint);
		return?bmpGray;
	}
	
	//?圖像灰度化
	public?static?Bitmap?grayScaleImage(Bitmap?src)?{
????????//?constant?factors
????????final?double?GS_RED?=?0.299;
????????final?double?GS_GREEN?=?0.587;
????????final?double?GS_BLUE?=?0.114;
		
//??????final?double?GS_RED?=?0.235;
//??????final?double?GS_GREEN?=?0.589;
//??????final?double?GS_BLUE?=?0.119;
????????
????????//?create?output?bitmap
????????Bitmap?bmOut?=?Bitmap.createBitmap(src.getWidth(),?src.getHeight(),?src.getConfig());
????????//?pixel?information
????????int?A,?R,?G,?B;
????????int?pixel;
????????
????????//?get?image?size
????????int?width?=?src.getWidth();
????????int?height?=?src.getHeight();
????????
????????//?scan?through?every?single?pixel
????????for(int?x?=?0;?x?<?width;?++x)?{
?????????for(int?y?=?0;?y?<?height;?++y)?{
??????????//?get?one?pixel?color
??????????pixel?=?src.getPixel(x,?y);
??????????//?retrieve?color?of?all?channels
??????????A?=?Color.alpha(pixel);
??????????R?=?Color.red(pixel);
??????????G?=?Color.green(pixel);
??????????B?=?Color.blue(pixel);
??????????//?take?conversion?up?to?one?single?value
??????????R?=?G?=?B?=?(int)(GS_RED?*?R?+?GS_GREEN?*?G?+?GS_BLUE?*?B);
??????????//?set?new?pixel?color?to?output?bitmap
??????????bmOut.setPixel(x,?y,?Color.argb(A,?R,?G,?B));
?????????}
????????}
????????
????????//?return?final?image
????????return?bmOut;
???????}

	//?對圖像進(jìn)行線性灰度變化
	public?static?Bitmap?lineGrey(Bitmap?image)?{
		//?得到圖像的寬度和長度
		int?width?=?image.getWidth();
		int?height?=?image.getHeight();
		//?創(chuàng)建線性拉升灰度圖像
		Bitmap?linegray?=?null;
		linegray?=?image.copy(Config.ARGB_8888,?true);
		//?依次循環(huán)對圖像的像素進(jìn)行處理
		for?(int?i?=?0;?i?<?width;?i++)?{
			for?(int?j?=?0;?j?<?height;?j++)?{
				//?得到每點(diǎn)的像素值
				int?col?=?image.getPixel(i,?j);
				int?alpha?=?col?&?0xFF000000;
				int?red?=?(col?&?0x00FF0000)?>>?16;
				int?green?=?(col?&?0x0000FF00)?>>?8;
				int?blue?=?(col?&?0x000000FF);
				//?增加了圖像的亮度
				red?=?(int)?(1.1?*?red?+?30);
				green?=?(int)?(1.1?*?green?+?30);
				blue?=?(int)?(1.1?*?blue?+?30);
				//?對圖像像素越界進(jìn)行處理
				if?(red?>=?255)?{
					red?=?255;
				}

				if?(green?>=?255)?{
					green?=?255;
				}

				if?(blue?>=?255)?{
					blue?=?255;
				}
				//?新的ARGB
				int?newColor?=?alpha?|?(red?<<?16)?|?(green?<<?8)?|?blue;
				//?設(shè)置新圖像的RGB值
				linegray.setPixel(i,?j,?newColor);
			}
		}
		return?linegray;
	}

	//?該函數(shù)實(shí)現(xiàn)對圖像進(jìn)行二值化處理
	public?static?Bitmap?gray2Binary(Bitmap?graymap)?{
		//?得到圖形的寬度和長度
		int?width?=?graymap.getWidth();
		int?height?=?graymap.getHeight();
		//?創(chuàng)建二值化圖像
		Bitmap?binarymap?=?null;
		binarymap?=?graymap.copy(Config.ARGB_8888,?true);
		//?依次循環(huán),對圖像的像素進(jìn)行處理
		for?(int?i?=?0;?i?<?width;?i++)?{
			for?(int?j?=?0;?j?<?height;?j++)?{
				//?得到當(dāng)前像素的值
				int?col?=?binarymap.getPixel(i,?j);
				//?得到alpha通道的值
				int?alpha?=?col?&?0xFF000000;
				//?得到圖像的像素RGB的值
				int?red?=?(col?&?0x00FF0000)?>>?16;
				int?green?=?(col?&?0x0000FF00)?>>?8;
				int?blue?=?(col?&?0x000000FF);
				//?用公式X?=?0.3×R+0.59×G+0.11×B計(jì)算出X代替原來的RGB
				int?gray?=?(int)?((float)?red?*?0.3?+?(float)?green?*?0.59?+?(float)?blue?*?0.11);
				//?對圖像進(jìn)行二值化處理
				if?(gray?<=?95)?{
					gray?=?0;
				}?else?{
					gray?=?255;
				}
				//?新的ARGB
				int?newColor?=?alpha?|?(gray?<<?16)?|?(gray?<<?8)?|?gray;
				//?設(shè)置新圖像的當(dāng)前像素值
				binarymap.setPixel(i,?j,?newColor);
			}
		}
		return?binarymap;
	}

	/**
?????*?將彩色圖轉(zhuǎn)換為黑白圖
?????*?
?????*?@param?位圖
?????*?@return?返回轉(zhuǎn)換好的位圖
?????*/
????public?static?Bitmap?convertToBlackWhite(Bitmap?bmp)?{
????????int?width?=?bmp.getWidth();?//?獲取位圖的寬
????????int?height?=?bmp.getHeight();?//?獲取位圖的高
????????int[]?pixels?=?new?int[width?*?height];?//?通過位圖的大小創(chuàng)建像素點(diǎn)數(shù)組
????????bmp.getPixels(pixels,?0,?width,?0,?0,?width,?height);
????????int?alpha?=?0xFF?<<?24;
????????for?(int?i?=?0;?i?<?height;?i++)?{
????????????for?(int?j?=?0;?j?<?width;?j++)?{
????????????????int?grey?=?pixels[width?*?i?+?j];
????????????????int?red?=?((grey?&?0x00FF0000)?>>?16);
????????????????int?green?=?((grey?&?0x0000FF00)?>>?8);
????????????????int?blue?=?(grey?&?0x000000FF);
????????????????grey?=?(int)?(red?*?0.3?+?green?*?0.59?+?blue?*?0.11);
????????????????grey?=?alpha?|?(grey?<<?16)?|?(grey?<<?8)?|?grey;
????????????????pixels[width?*?i?+?j]?=?grey;
????????????}
????????}
????????Bitmap?newBmp?=?Bitmap.createBitmap(width,?height,?Config.ARGB_8888);
????????newBmp.setPixels(pixels,?0,?width,?0,?0,?width,?height);
????????return?newBmp;
????}
????
????/**
?????*?圖片銳化(拉普拉斯變換)
?????*?
?????*?@param?bmp
?????*?@return
?????*/
????public?static?Bitmap?sharpenImageAmeliorate(Bitmap?bmp)?{
????????//?拉普拉斯矩陣
????????int[]?laplacian?=?new?int[]?{?-1,?-1,?-1,?-1,?9,?-1,?-1,?-1,?-1?};
????????int?width?=?bmp.getWidth();
????????int?height?=?bmp.getHeight();
????????Bitmap?bitmap?=?Bitmap.createBitmap(width,?height,
????????????????Bitmap.Config.ARGB_8888);
????????int?pixR?=?0;
????????int?pixG?=?0;
????????int?pixB?=?0;
????????int?pixColor?=?0;
????????int?newR?=?0;
????????int?newG?=?0;
????????int?newB?=?0;
????????int?idx?=?0;
????????float?alpha?=?0.3F;
????????int[]?pixels?=?new?int[width?*?height];
????????bmp.getPixels(pixels,?0,?width,?0,?0,?width,?height);
????????for?(int?i?=?1,?length?=?height?-?1;?i?<?length;?i++)?{
????????????for?(int?k?=?1,?len?=?width?-?1;?k?<?len;?k++)?{
????????????????idx?=?0;
????????????????for?(int?m?=?-1;?m?<=?1;?m++)?{
????????????????????for?(int?n?=?-1;?n?<=?1;?n++)?{
????????????????????????pixColor?=?pixels[(i?+?n)?*?width?+?k?+?m];
????????????????????????pixR?=?Color.red(pixColor);
????????????????????????pixG?=?Color.green(pixColor);
????????????????????????pixB?=?Color.blue(pixColor);
????????????????????????newR?=?newR?+?(int)?(pixR?*?laplacian[idx]?*?alpha);
????????????????????????newG?=?newG?+?(int)?(pixG?*?laplacian[idx]?*?alpha);
????????????????????????newB?=?newB?+?(int)?(pixB?*?laplacian[idx]?*?alpha);
????????????????????????idx++;
????????????????????}
????????????????}
????????????????newR?=?Math.min(255,?Math.max(0,?newR));
????????????????newG?=?Math.min(255,?Math.max(0,?newG));
????????????????newB?=?Math.min(255,?Math.max(0,?newB));
????????????????pixels[i?*?width?+?k]?=?Color.argb(255,?newR,?newG,?newB);
????????????????newR?=?0;
????????????????newG?=?0;
????????????????newB?=?0;
????????????}
????????}
????????bitmap.setPixels(pixels,?0,?width,?0,?0,?width,?height);
????????return?bitmap;
????}
}


至此,身份證號碼應(yīng)該能獲取到,再聲明下,識別率不是很好,希望能有大神能夠完善下,謝謝!



本站聲明: 本文章由作者或相關(guān)機(jī)構(gòu)授權(quán)發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點(diǎn),本站亦不保證或承諾內(nèi)容真實(shí)性等。需要轉(zhuǎn)載請聯(lián)系該專欄作者,如若文章內(nèi)容侵犯您的權(quán)益,請及時聯(lián)系本站刪除。
換一批
延伸閱讀

LED驅(qū)動電源的輸入包括高壓工頻交流(即市電)、低壓直流、高壓直流、低壓高頻交流(如電子變壓器的輸出)等。

關(guān)鍵字: 驅(qū)動電源

在工業(yè)自動化蓬勃發(fā)展的當(dāng)下,工業(yè)電機(jī)作為核心動力設(shè)備,其驅(qū)動電源的性能直接關(guān)系到整個系統(tǒng)的穩(wěn)定性和可靠性。其中,反電動勢抑制與過流保護(hù)是驅(qū)動電源設(shè)計(jì)中至關(guān)重要的兩個環(huán)節(jié),集成化方案的設(shè)計(jì)成為提升電機(jī)驅(qū)動性能的關(guān)鍵。

關(guān)鍵字: 工業(yè)電機(jī) 驅(qū)動電源

LED 驅(qū)動電源作為 LED 照明系統(tǒng)的 “心臟”,其穩(wěn)定性直接決定了整個照明設(shè)備的使用壽命。然而,在實(shí)際應(yīng)用中,LED 驅(qū)動電源易損壞的問題卻十分常見,不僅增加了維護(hù)成本,還影響了用戶體驗(yàn)。要解決這一問題,需從設(shè)計(jì)、生...

關(guān)鍵字: 驅(qū)動電源 照明系統(tǒng) 散熱

根據(jù)LED驅(qū)動電源的公式,電感內(nèi)電流波動大小和電感值成反比,輸出紋波和輸出電容值成反比。所以加大電感值和輸出電容值可以減小紋波。

關(guān)鍵字: LED 設(shè)計(jì) 驅(qū)動電源

電動汽車(EV)作為新能源汽車的重要代表,正逐漸成為全球汽車產(chǎn)業(yè)的重要發(fā)展方向。電動汽車的核心技術(shù)之一是電機(jī)驅(qū)動控制系統(tǒng),而絕緣柵雙極型晶體管(IGBT)作為電機(jī)驅(qū)動系統(tǒng)中的關(guān)鍵元件,其性能直接影響到電動汽車的動力性能和...

關(guān)鍵字: 電動汽車 新能源 驅(qū)動電源

在現(xiàn)代城市建設(shè)中,街道及停車場照明作為基礎(chǔ)設(shè)施的重要組成部分,其質(zhì)量和效率直接關(guān)系到城市的公共安全、居民生活質(zhì)量和能源利用效率。隨著科技的進(jìn)步,高亮度白光發(fā)光二極管(LED)因其獨(dú)特的優(yōu)勢逐漸取代傳統(tǒng)光源,成為大功率區(qū)域...

關(guān)鍵字: 發(fā)光二極管 驅(qū)動電源 LED

LED通用照明設(shè)計(jì)工程師會遇到許多挑戰(zhàn),如功率密度、功率因數(shù)校正(PFC)、空間受限和可靠性等。

關(guān)鍵字: LED 驅(qū)動電源 功率因數(shù)校正

在LED照明技術(shù)日益普及的今天,LED驅(qū)動電源的電磁干擾(EMI)問題成為了一個不可忽視的挑戰(zhàn)。電磁干擾不僅會影響LED燈具的正常工作,還可能對周圍電子設(shè)備造成不利影響,甚至引發(fā)系統(tǒng)故障。因此,采取有效的硬件措施來解決L...

關(guān)鍵字: LED照明技術(shù) 電磁干擾 驅(qū)動電源

開關(guān)電源具有效率高的特性,而且開關(guān)電源的變壓器體積比串聯(lián)穩(wěn)壓型電源的要小得多,電源電路比較整潔,整機(jī)重量也有所下降,所以,現(xiàn)在的LED驅(qū)動電源

關(guān)鍵字: LED 驅(qū)動電源 開關(guān)電源

LED驅(qū)動電源是把電源供應(yīng)轉(zhuǎn)換為特定的電壓電流以驅(qū)動LED發(fā)光的電壓轉(zhuǎn)換器,通常情況下:LED驅(qū)動電源的輸入包括高壓工頻交流(即市電)、低壓直流、高壓直流、低壓高頻交流(如電子變壓器的輸出)等。

關(guān)鍵字: LED 隧道燈 驅(qū)動電源
關(guān)閉