⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ocrsource.java

📁 java编写的OCR软件
💻 JAVA
字号:
/*
    Jacson
    Copyright (C) 2003 Patrick Carl, patrick.carl@web.de
 
    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.
 
    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.
 
    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package de.spieleck.app.jacson.source;

import de.spieleck.app.jacson.JacsonException;
import de.spieleck.app.jacson.JacsonReport;

/**
 * This Sources uses images as input and delievers chunks which are taken
 * from OCR. <br/>
 * Don't see a use case at the moment, but let's have a try!<br/>
 * What you need is a OCR tool with a command-line-interface like GOCR, which
 * I use.
 * @author  Patrick Carl
 * @version $Id: OCRSource.java 13 2005-09-28 06:02:56Z pcs $
 */

public class OCRSource extends LineChunkSource {
    
    /** Holds value of property imageFile. */
    private String imageFile;
    
    /** Holds value of property ocrPath. */
    private String ocrPath;
    
    /**
     * Creates a new instance of OCRSource using the imageFile as input and
     * the parameter ocrPath as path to your OCR-tool with
     * command-line-interface.
     */
    public OCRSource(String imageFile, String ocrPath) {
        setImageFile(imageFile);
        setOcrPath(ocrPath);
        try{
            Process p = Runtime.getRuntime().exec(ocrPath + " " + imageFile);
            setStream(p.getInputStream(), false);
        }
        catch (Exception e) {
            e.printStackTrace();
        }
    }
    
    
    /** Getter for property imageFile.
     * @return Value of property imageFile.
     *
     */
    public String getImageFile() {
        return this.imageFile;
    }
    
    /** Setter for property imageFile.
     * @param imageFile New value of property imageFile.
     *
     */
    public void setImageFile(String imageFile) {
        this.imageFile = imageFile;
    }
    
    /** Getter for property ocrPath.
     * @return Value of property ocrPath.
     *
     */
    public String getOcrPath() {
        return this.ocrPath;
    }
    
    /** Setter for property ocrPath.
     * @param ocrPath New value of property ocrPath.
     *
     */
    public void setOcrPath(String ocrPath) {
        this.ocrPath = ocrPath;
    }
    
    public String message()
    {
        JacsonReport jr = getRegReport();
        jr.begin("ocrsource");
        jr.report("imagefile", getImageFile());
        jr.report("ocrpath", getOcrPath());
        return getImageFile();
    }    
    
    public static void main(String[] args) throws Exception{
        OCRSource s = new OCRSource("/home/pcs/tmp/gocr.tiff", "/usr/local/bin/gocr");
        String c = s.nextChunk();
        while(c != null){
            System.out.println(c);
            c = s.nextChunk();
        }
        
    }
    
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -