java 调用tesseract-ocr识别图片
来源:互联网 发布:新一代网络架构 编辑:程序博客网 时间:2024/09/21 09:17
/** * ━━━━━━神兽出没━━━━━━ * ┏┓ ┏┓ * ┏┛┻━━━┛┻┓ * ┃ ┃ * ┃ ━ ┃ * ┃ ┳┛ ┗┳ ┃ * ┃ ┃ * ┃ ┻ ┃ * ┃ ┃ * ┗━┓ ┏━┛Code is far away from bug with the animal protecting * ┃ ┃ 神兽保佑,代码无bug * ┃ ┃ * ┃ ┗━━━┓ * ┃ ┣┓ * ┃ ┏┛ * ┗┓┓┏━┳┓┏┛ * ┃┫┫ ┃┫┫ * ┗┻┛ ┗┻┛ * * ━━━━━━感觉萌萌哒━━━━━━ */package gt.controller.ocr2;import java.io.BufferedReader;import java.io.File;import java.io.FileInputStream;import java.io.InputStreamReader;/** * 类名称:Test.java * 类描述: * 作 者:why * 时 间:2017年3月17日 */public class Test { public static synchronized String recognizeText(File imageFile, String imageFormat) throws Exception { String tessPath="D:\\ocr\\Tesseract-OCR"; File outputFile = new File(imageFile.getParentFile(), "output"); StringBuffer strB = new StringBuffer(); String[] cm=new String[]{tessPath+"/tesseract",imageFile.getAbsolutePath(),outputFile.getAbsolutePath(),"-l","normal"}; System.out.println("执行的命令是 "); for(String str:cm){ System.out.print(str+" "); } Process pb = Runtime.getRuntime().exec(cm); int w = pb.waitFor(); if (w == 0) { BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(outputFile .getAbsolutePath() + ".txt"), "UTF-8")); System.out.println("正在读取"+outputFile .getAbsolutePath() + ".txt 文件"); String str; while ((str = in.readLine()) != null) { strB.append(str); } System.out.println("读取完成 结果是 "+strB.toString()); in.close(); } else { String msg; switch (w) { case 1: msg = "Errors accessing files. There may be spaces in your image's filename."; break; case 29: msg = "Cannot recognize the image or its selected region."; break; case 31: msg = "Unsupported image format."; break; default: msg = "Errors occurred."; }// tempImage.delete(); throw new RuntimeException(msg); }// new File(outputFile.getAbsolutePath() + ".txt").delete(); return strB.toString(); } public static void main(String[] args) { try {System.out.println(recognizeText(new File("D://ocrpic//1.png"), "png"));} catch (Exception e) {e.printStackTrace();}}}
4 0
- java 调用tesseract-ocr识别图片
- tesseract-ocr图片识别
- java图片开源框架tesseract调用OCR实现图片文件识别代码下载
- Tesseract-ocr-图片文字识别
- java 利用Tesseract-OCR识别图片验证码
- Java OCR tesseract 图片识别技术(一)
- Java OCR tesseract 图片识别技术(二)
- java程序集成Tesseract-OCR识别图片信息
- JAVA调用tesseract 识别图片应用二
- tesseract-ocr 识别中文扫描图片
- tesseract-ocr 识别图片中的数字
- tesseract-ocr 实现图片识别功能
- 使用Tesseract OCR Engine识别图片文字
- tesseract-ocr 实现图片识别功能
- tesseract-ocr 实现图片识别功能
- tesseract-OCR识别图片中的数字
- Tesseract-OCR识别图片验证码
- tesseract-ocr 实现图片识别功能
- 第四周作业:Integer Replacement
- 全排列算法的递归实现
- VMvare虚拟机安装过程出现问题的解决方案
- bzoj 3998 弦论(后缀自动机, 后缀数组)
- TIPTOP ERP与通达OA工作流集成案例
- java 调用tesseract-ocr识别图片
- 关于DataGrid列表样式
- Android你基础知识归纳
- 一个简单易懂且实用的JQuery分页插件(jquery.page)(详解)
- C#委托——哪里用得着?
- ubuntu 安装qq
- Android逆向从未如此简单
- 机器学习知识点(十八)密度聚类DBSCAN算法Java实现
- 如何让 Finder 显示隐藏文件和文件夹