`
100432177
  • 浏览: 16246 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

AspriseOCR破解用Java实现网络图片解析

阅读更多
前段时间做网络爬虫需要用到图片解析功能,个人从网络苦心搜索研究了一下,由此产生了以下的文档,博客一下,给有同样需要的人分享,呵呵



一、 开发环境配置

 

l          开发环境: jdk6.0

l          硬件环境: Windows XP 32bit

l          开发工具: eclipse3.4

l          开发用到外部 java 组件包: Asprise OCR v4.0 for Java

下载 Asprise OCR v4.0 for Java 到 http://asprise.com/product/ocr/download.php?lang=java

l          破解 Asprise OCR v4.0 for Java 工具: CloseWin.exe

(破解 Asprise OCR v4.0 for Java 的原因:由于利用 Asprise OCR v4.0 for Java 进行开发时,总是弹出提示购买的窗口,只有当点击该窗口后才会得到图片的解析结果,所以破解工具的作用就是实现销毁这个窗口,从而实现利用 Asprise OCR v4.0 for Java 进行图片的批量解析)

破解工具是C++写的工程源码等我已经上传了,有需要的下载了,得给点辛苦分哦,呵呵

l          配置 Asprise OCR v4.0 for Java

解压 Asprise-OCR-Java-Windows_XP_32bit-4.0.rar ,到解压后的文件内把 AspriseOCR.dll 、 DevIL.dll 、 ILU.dll 这三个 dll 库文件放到 windows/system32 ,开发中会用到开发用到 aspriseOCR.jar 组件

下面

 

二、代码开发

 

1 、流程如下:



 

2 、详细代码如下:

 

l          图片下载类

package net.crawler.common;

 

/**

  * 本程序的功能实现网络下载

  * 把指定 url 的文件下载到本地硬盘

  *

  */

import java.io.*;

import java.net.*;

 

/**

  * @todo 将网上获取的图像 ,mp3 等文件存储到本地

  *

  * @version 1.0

  */

 

public class DownLoadWithUrl {

 

       public static File downLoadFile(String fromUrl) {

              URL url;

              File file = null;

              try {

                     // url = new

                     // URL("http://count.koubei.com/showphone/showphone.php?f=jpg&w=96&h=10&bc=255,255,255&fc=0,0,0&fs=10&fn=arial&phone=NzMwNzIyNTE1%236aWCXtTNZYkxASrj");

                     url = new URL(fromUrl);

                     URLConnection uc = url.openConnection();

                     InputStream is = uc.getInputStream();

 

                     // 根据下载文件类型的不同,进行相应的文件命名

                     file = new File("D:\\showphone.jpg");

                     FileOutputStream out = new FileOutputStream(file);

 

                     /*

                       * 该注释内的也是一种写入文件的方法,不过通常下载 mp3 或者比 mp3 更小图片

                       * 等这些文件用这种带缓冲的方法写文件比较慢,所以说小文件下载通常用下面 的写文件方法就可以了 // byte[] b = new

                       * byte[102400*3]; // int size = 0; // // while ((size = is.read(b)) !=

                       * -1) { // out.write(b, 1, size); // // }

                       */

 

                     int i = 0;

                     while ((i = is.read()) != -1) {

                            out.write(i);

                     }

                     out.flush();

 

                     is.close();

              } catch (Exception e) {

                     System.out.println(" 图片下载或存盘失败! ");

              }

 

              return file;

 

       }

 

       /**

         * 删除本地磁盘指定路径的文件 create date:2009-5-13 author:Administrator

         *

         * @param file

         */

       public static void delFile(File file) {

             

              if (file.exists())

                     file.delete();

       }

 

       public static void main(String[] args) {

              // delFile("D:\\forever.mp3");

              downLoadFile("http://count.koubei.com/showphone/showphone.php?f=jpg&w=96&h=10&bc=255,255,255&fc=0,0,0&fs=10&fn=arial&phone=NzMwNzIyNTE1%236aWCXtTNZYkxASrj");

       }

}

 

l          图片文字解析类

package net.crawler.common;

 

/**

  * 本程序实现了图片文字解析 ( 识别图片中的文字信息)

  */

import java.awt.image.BufferedImage;

import java.io.File;

import java.io.IOException;

 

import javax.imageio.ImageIO;

 

import com.asprise.util.ocr.OCR;

 

public class ParseJPEG_withOCR {

 

       public static void main(String[] args) {

 

       }

 

       /**

         * 返回图片文字的识别结果 create date:2009-5-22 author:Administrator

         *

         * @param imageFile

         * @return

         */

       public static String getRecogniseStr(File imageFile) {

 

              String s = "";

              try {

 

                     BufferedImage image = ImageIO.read(imageFile);

                     int width = image.getTileWidth();

                     int height = image.getTileHeight();

                     image = image.getSubimage(0, 0, width, height);

                     s = new OCR().recognizeEverything(image);

 

              } catch (IOException e) {

                     e.printStackTrace();

                     System.out.println(" 图片识别失败! ");

              }

              return s;

       }

}

 

l          网络图片解析类

package net.crawler.common;

 

/**

  * 本程序实现功能:给出一个图片的具体网络地址,把该图片的进行解析,解析后把图片内容以字符串形式进行返回

  */

import java.io.File;

 

public class RecognisePicture {

 

    /**

      * create date:2009- 5- 22 author:Administrator

      *

      * @param args

      */

    public static void main(String[] args) {

       // TODO Auto-generated method stub

 

        recognise ( "http://count.koubei.com/showphone/showphone.php?f=jpg&w=96&h=10&bc=255,255,255&fc=0,0,0&fs=10&fn=arial&phone=NzMwNzIyNTE1%236aWCXtTNZYkxASrj" );

    }

 

    /**

      * 解析指定网络地址的图片信息 create date:2009- 5- 22 author:Administrator

      *

      * @param fromUrl

      * @return

      */

    public static String recognise(String fromUrl) {

 

       String result = "" ;

       // 下载图片文件到本地磁盘

       File file = DownLoadWithUrl.downLoadFile (fromUrl);

       if (file != null ) {

           // 解析下载到本地磁盘文件

           result = ParseJPEG_withOCR.getRecogniseStr (file);

           // 删除下载到本地磁盘的文件

           DownLoadWithUrl.delFile (file);

       }

       return result;

    }

}



本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/xumiaohua/archive/2009/06/25/4297140.aspx
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics