不到十行實現(xiàn)javaCV圖片OCR文字識別
spring boot項目pom文件中添加以下依賴
<!-- https://mvnrepository.com/artifact/org.bytedeco/javacv-platform --> <dependency> <groupId>org.bytedeco</groupId> <artifactId>javacv-platform</artifactId> <version>1.5.5</version> </dependency>
單類代碼實現(xiàn),復(fù)制到idea編輯器里,右鍵run運行即可。
OCR方法參數(shù)說明,
1.lng 語言類型 分為兩種 1.eng 英語 2.chi_sim 中文簡體
2.dataPath 語言數(shù)據(jù)集文件夾路徑

3.imagePath 需要識別的圖片文件路徑

import org.bytedeco.javacpp.BytePointer;
import org.bytedeco.leptonica.PIX;
import org.bytedeco.leptonica.global.lept;
import org.bytedeco.tesseract.TessBaseAPI;
public class OcrTest {
public static String OCR(String lng,String dataPath,String imagePath) {
TessBaseAPI api=new TessBaseAPI();
if (api.Init(dataPath, lng)!=0){
System.out.println("error");
}
PIX image= lept.pixRead(imagePath);
if (image==null){
return "";
}
api.SetImage(image);
BytePointer outText=api.GetUTF8Text();
String result=outText.getString();
api.End();
outText.deallocate();
lept.pixDestroy(image);
return result;
}
public static void main(String[] args) {
String text= OCR("chi_sim", "E:\\traineddata", "C:\\Users\\tarzan\\Desktop\\image\\test5.png");
System.out.println(text);
}
}
測試樣例結(jié)果
test1.jpg

test2.jpg

test3.jpg

test4.jpg

test5.jpg

到此這篇關(guān)于不到十行實現(xiàn)javaCV圖片OCR文字識別的文章就介紹到這了,更多相關(guān)javaCV OCR文字識別內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
SpringBoot用JdbcTemplates操作Mysql實例代碼詳解
JdbcTemplate是Spring框架自帶的對JDBC操作的封裝,目的是提供統(tǒng)一的模板方法使對數(shù)據(jù)庫的操作更加方便、友好,效率也不錯,這篇文章主要介紹了SpringBoot用JdbcTemplates操作Mysql2022-10-10
Java設(shè)計模塊系列之書店管理系統(tǒng)單機版(三)
這篇文章主要為大家詳細(xì)介紹了Java單機版的書店管理系統(tǒng)設(shè)計模塊和思想第三章,感興趣的小伙伴們可以參考一下2016-08-08
Spring Boot thymeleaf模板引擎的使用詳解
這篇文章主要介紹了Spring Boot thymeleaf模板引擎的使用詳解,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2021-03-03

