java 截图&识别

package com.example.demo;

import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.image.BufferedImage;
import java.io.File;

import javax.imageio.ImageIO;

import net.sourceforge.tess4j.ITesseract;
import net.sourceforge.tess4j.Tesseract;

/**
* 截屏,识别
* @author Administrator
*
*/
public class CutImage {

public static void main(String[] args) throws Exception{
Robot robot = new Robot();
//前两个参数为起始坐标,后两个为宽,高
BufferedImage image = robot.createScreenCapture(new Rectangle(100, 100, 100, 100));

ImageIO.write(image, "jpg", new File("D:/test/test.jpg"));

//tess4j.Tesseract
ITesseract instance = new Tesseract();
//基于Tesseract -ocr  ,主要需要tessdata文件夹下的.traineddata 文件 默认为eng.traineddata 
instance.setDatapath("C:\\Program Files (x86)\\Tesseract-OCR");
String result = instance.doOCR(image);
System.out.println(result);

}

}

 

 

posted @ 2018-06-20 21:16  笑对蓝天  阅读(352)  评论(0编辑  收藏  举报