java下OCR的实现[j4l简单使用]

昨天在做一些验证码识别,因为主要用的语言是java,所以也是用java来做了。

 

刚开始自然是思路全无,后来在网上找到了J4L 这个工具jar

 

网站:http://www.java4less.com/ocrtools/ocrtools.php?info=guide

 

使用起来也是很简单:

这边先下载他的jar包:

http://www.java4less.com/ocrtools/ocrtools.php?info=download

 

下载后解压 得到一堆文件:



 运行一下那三个bat文件就可以看到效果:



 

如果你是64位的机器 请把bits64里的dll复制到这个目录并且覆盖掉 不然会有平台不支持的错误

 

在代码里使用也很简单 把lib下的jar包导入到build path

并且把tess3WrapperDLL.dll  leptonlibd.dll  放到path下(%java_home%/bin啊之类的 就是环境变量里设置的path)

 

接下去就可以简单使用了:

我这边的代码为了处理一下验证码 直接拿来用基本上用不了 所以用了http://ykf.iteye.com/blog/212431 里面图像的处理类

代码很简单 如下:

	public static String getVerifyText(InputStream ins) throws MalformedURLException,
			IOException {
		OCRFacade facade = new OCRFacade();

		BufferedImage bi = ImageIO.read(ins);

		ImageFilter ifter = new ImageFilter(bi); 

		bi = ifter.changeGrey(); //这里只用了一个二值化 可以再多加几个

		ByteArrayOutputStream bao = new ByteArrayOutputStream();
		ImageIO.write(bi, "png", bao);

		String text = facade.recognizeImage(bao.toByteArray(), "png", "eng");

		System.out.println("Text in the image is: ");
		System.out.println(text);
		return text;
	}

 结果:



 

试了一下 这类简单的识别 正确率虽然不是特别高 但是差不多足够用了

 

 

不过由于用到了外部的dll 实际使用中如果使用多线程(就算是单线程也一样) 识别的图片一多(单线程下 几百个) 虚拟机就会崩溃...不适合进行批量工作  不过这是找到最好的了...

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要将ptp4l配置为slave-only模式,需要进行以下步骤: 1. 编辑ptp4l的配置文件,通常在/etc/ptp4l.conf或/etc/linuxptp/ptp4l.conf中: ``` # /etc/ptp4l.conf # Config file for ptp4l(8) # # The following parameters are not mandatory. They are shown here for # reference only. # Specify the PTP clock device. # Note that the default value of clock_device is the first PTP clock # that is found on the system. #clock_device=/dev/ptp0 # Specify the network interface to be used for PTP communication. # Note that the default value of iface is the first Ethernet interface # that is found on the system. #iface=eth0 # Specify the PTP domain number. # Note that the default value of domain is 0. #domain=0 # Specify the delay mechanism. # Note that the default value of delay_mechanism is E2E. #delay_mechanism=P2P # Specify the unicast destination address and port. # Note that the default value of unicast_destinations is empty. #unicast_destinations=192.168.1.10:319 # Specify the network transport protocol. # Note that the default value of transport is UDPv4. #transport=UDPv6 # Specify the PTP operating mode. # Note that the default value of mode is E2E. mode=slaveonly # Specify the preferred PTP clock source. # Note that the default value of preferred is empty. #preferred=192.168.1.10:319 # Specify the log level. # Note that the default value of log_level is NORMAL. #log_level=ALL ``` 2. 设置ptp4l的工作模式为slave-only,修改ptp4l.conf文件中的mode参数为slaveonly: ``` mode=slaveonly ``` 3. 保存配置文件并重启ptp4l服务: ``` sudo systemctl restart ptp4l ``` 这样,ptp4l就会以slave-only模式运行,并且只接收来自master的PTP消息,不会发送PTP消息。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值