java 调用tesseract-ocr识别图片
2017-03-20 11:35
441 查看
/** * ━━━━━━神兽出没━━━━━━ * ┏┓ ┏┓ * ┏┛┻━━━┛┻┓ * ┃ ┃ * ┃ ━ ┃ * ┃ ┳┛ ┗┳ ┃ * ┃ ┃ * ┃ ┻ ┃ * ┃ ┃ * ┗━┓ ┏━┛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(); } } }
相关文章推荐
- JAVA调用tesseract 识别图片应用二
- java图片开源框架tesseract调用OCR实现图片文件识别代码下载
- tesseract-ocr识别中文扫描图片实例讲解 .
- tesseract-ocr识别中文扫描图片实例讲解
- 基于Tesseract-OCR实现的JAVA WEB版OCR(图片转文字)
- C#调用java WebService传递图片
- coco2dx jni 调用 java 相机返回 图片数据
- java调用.net webservice 返回图片
- tesseract-ocr识别中文扫描图片实例讲解
- Java调用OCR进行图片识别
- java调用pdfbox转pdf文件为图片文件,有中文时在windows上正常,部署到linux下乱码
- tesseract-ocr识别中文扫描图片实例讲解
- java调用打印机打印图片
- java如何调用本地打印机进行图片打印
- loadrunner使用system()函数调用Tesseract-OCR识别验证码遇到的问题
- java调用打印机打印自定义的图片
- tesseract-ocr识别中文扫描图片实例讲解
- tesseract-ocr识别中文扫描图片实例讲解
- Java乔晓松-android中调用系统拍照功能并显示拍照的图片
- Windows下Java调用OCR进行图片识别