最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

opencv+tesseract實(shí)現(xiàn)驗(yàn)證碼識(shí)別的示例

 更新時(shí)間:2022年06月28日 10:48:27   作者:peng_wei_kang  
本文主要介紹了opencv+tesseract實(shí)現(xiàn)驗(yàn)證碼識(shí)別的示例,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧

一、需要識(shí)別的內(nèi)容

需要識(shí)別的驗(yàn)證碼內(nèi)容如下  驗(yàn)證碼下載下載地址。

二、直接調(diào)用tesseract來(lái)完成識(shí)別(識(shí)別率很差)

識(shí)別的圖片內(nèi)容為:

在window系統(tǒng)鐘打開(kāi)cmd命令窗口,執(zhí)行識(shí)別命令如下:

tesseract.exe 01.png output.txt -l eng

識(shí)別結(jié)果為:519}       該識(shí)別準(zhǔn)確率遠(yuǎn)遠(yuǎn)達(dá)不到預(yù)期

三、訓(xùn)練數(shù)據(jù)樣本,提升識(shí)別率

1、下載10份樣本(樣本數(shù)量越多,識(shí)別率越高),然后通過(guò)jTessBoxEditor來(lái)進(jìn)行樣本數(shù)據(jù)矯正(該步驟耗時(shí)較長(zhǎng))。

 2、打開(kāi) jTessBoxEditor,將所有的樣本數(shù)據(jù)生成一個(gè)總的tif文件(tif就是所有圖片的集合)。操作如下:

1)jTessBoxEditor->Tools->Merge TIFF

2 )全選所有的樣本文件,之后生成的tif命名為 jtbnum.font.exp0.tif

3)進(jìn)行數(shù)據(jù)識(shí)別調(diào)整,如下圖:

 四、生成樣本庫(kù)字體

將所有的樣本識(shí)別內(nèi)容都調(diào)整正確后(調(diào)整的參數(shù)保存在jtbnum.font.exp0.box文件鐘),我們需要將我們生成的樣本文件封裝成我們的 jtbnum.traineddata 字體庫(kù),生成方式如下:

1)創(chuàng)建 font_properties 文件,內(nèi)容為 font 0 0 0 0 0

2)在同級(jí)目錄創(chuàng)建 run.bat 文件 內(nèi)容如下

rem 執(zhí)行改批處理前先要目錄下創(chuàng)建font_properties文件  
  
echo Run Tesseract for Training..  
tesseract.exe jtbnum.font.exp0.tif jtbnum.font.exp0 nobatch box.train  
  
echo Compute the Character Set..  
unicharset_extractor.exe jtbnum.font.exp0.box  
mftraining -F font_properties -U unicharset -O jtbnum.unicharset jtbnum.font.exp0.tr  
  
echo Clustering..  
cntraining.exe jtbnum.font.exp0.tr  
  
echo Rename Files..  
 
del jtbnum.normproto
rename normproto jtbnum.normproto
 
del jtbnum.inttemp
rename inttemp jtbnum.inttemp
 
del jtbnum.pffmtable
rename pffmtable jtbnum.pffmtable
 
del jtbnum.shapetable
rename shapetable jtbnum.shapetable
  
echo Create Tessdata..  
combine_tessdata.exe jtbnum. 
 
pause

 3)雙擊執(zhí)行 run.bat 文件,系統(tǒng)執(zhí)行完成后,將會(huì)生成 jtbnum.traineddata 文件。

4)將 jtbnum.traineddata 拷貝到tesseract安裝目錄下的tessdata文件夾下。

5)測(cè)試識(shí)別率:

 識(shí)別的圖片內(nèi)容為:

tesseract.exe 01.png output.txt -l jtbnum

 識(shí)別結(jié)果為:51915       識(shí)別結(jié)果已經(jīng)很準(zhǔn)確率,但是驗(yàn)證碼圖片中的雜質(zhì)沒(méi)有清除,導(dǎo)致會(huì)識(shí)別出多余內(nèi)容來(lái)。

五、通過(guò)Opencv清除圖片的多余雜質(zhì)(Java實(shí)現(xiàn))

if(!hasLoad){
            System.load(opencvPath+"/build/java/x64/opencv_java440.dll");
            hasLoad = true;
        }
 
        byte [] bytes = Base64Utils.decodeFromString(base64);
        String path = savePath+"/"+System.currentTimeMillis()+".png";
        try {
            OutputStream outputStream = new FileOutputStream(new File(path));
            outputStream.write(bytes);
            outputStream.flush();
            outputStream.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
 
        Mat image0 = Imgcodecs.imread(path);
        Mat image1 = new Mat();
        //灰度處理
        Imgproc.cvtColor(image0, image1, Imgproc.COLOR_BGR2GRAY);
        Imgproc.adaptiveThreshold(image1,image1,255,Imgproc.ADAPTIVE_THRESH_MEAN_C,Imgproc.THRESH_BINARY,11, 2);
        Core.bitwise_not(image1,image1);
        Mat kernel = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(2, 2), new Point(-1, -1));
        Mat temp = new Mat();
        Imgproc.erode(image1, temp, kernel);
        Imgproc.dilate(temp, temp, kernel);
        String newPath = path.substring(0,path.lastIndexOf(".")) +"_1.png";
        Imgcodecs.imwrite(newPath,temp);

圖片處理結(jié)果如下(雜質(zhì)已經(jīng)清除):

5)測(cè)試識(shí)別率:

 識(shí)別的圖片內(nèi)容為:

tesseract.exe 01.png output.txt -l jtbnum

 識(shí)別結(jié)果為:5191       識(shí)別已經(jīng)很精確

到此這篇關(guān)于opencv+tesseract實(shí)現(xiàn)驗(yàn)證碼識(shí)別的示例的文章就介紹到這了,更多相關(guān)opencv tesseract 驗(yàn)證碼識(shí)別內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論

忻城县| 宣恩县| 鄯善县| 泰来县| 淮滨县| 宾阳县| 淮阳县| 慈溪市| 焉耆| 佛山市| 嘉鱼县| 高唐县| 阿拉善左旗| 伊春市| 曲周县| 台山市| 大同市| 定结县| 孝昌县| 阿瓦提县| 梅州市| 容城县| 沾化县| 吴旗县| 宜阳县| 门头沟区| 遂平县| 延川县| 双鸭山市| 海南省| 伊吾县| 林口县| 嘉鱼县| 安龙县| 克拉玛依市| 桃源县| 教育| 鄂伦春自治旗| 本溪| 寿宁县| 天峨县|