spring boot项目pom文件中添加以下依赖
1 <dependency> 2 <groupId>org.bytedeco</groupId> 3 <artifactId>javacv-platform</artifactId> 4 <version>1.5.5</version> 5 </dependency>
OCR方法参数说明,
1.lng 语言类型 分为两种 1.eng 英语 2.chi_sim 中文简体
2.dataPath 语言数据集文件夹路径
3.imagePath 需要识别的图片文件路径
1 2 import org.bytedeco.javacpp.BytePointer; 3 import org.bytedeco.leptonica.PIX; 4 import org.bytedeco.leptonica.global.lept; 5 import org.bytedeco.tesseract.TessBaseAPI; 6 7 public class OcrTest { 8 9 public static String OCR(String lng,String dataPath,String imagePath) { 10 TessBaseAPI api=new TessBaseAPI(); 11 if (api.Init(dataPath, lng)!=0){ 12 System.out.println("error"); 13 } 14 PIX image= lept.pixRead(imagePath); 15 if (image==null){ 16 return ""; 17 } 18 api.SetImage(image); 19 BytePointer outText=api.GetUTF8Text(); 20 String result=outText.getString(); 21 api.End(); 22 outText.deallocate(); 23 lept.pixDestroy(image); 24 return result; 25 } 26 27 public static void main(String[] args) { 28 String text= OCR("chi_sim", "E:\\traineddata", "C:\\Users\\tarzan\\Desktop\\image\\test5.png"); 29 System.out.println(text); 30 } 31 }
转https://www.jb51.net/article/212646.htm
标签:识别,String,image,api,org,javaCV,OCR,bytedeco From: https://www.cnblogs.com/liuswi/p/18513855