Java写的答题助手项目分析与总结

针对最近火热的直播问答,所制作的答题助手.

首先,对项目有一个分析,如何来实现我们想要的功能.我们需要的功能有:

1. 识别答题过程中的题目与答案

2. 将题目在浏览器中进行搜索

3. 统计分析搜索到的结果

先来解决第一个问题:识别题目与答案

使用百度的OCR文字识别https://cloud.baidu.com/product/ocr.html,可以很方便的识别图片中的文字

所以第一步,对屏幕截图,第二部调用接口识别.

一. 对屏幕截图,Java代码如下:

Rectangle screenRectangle = new Rectangle((int) x, (int) y, (int) width, (int) height);
Robot robot = null;
FileOutputStream out = null;
try {
robot = new Robot();
} catch (AWTException e1) {
e1.printStackTrace();
}
BufferedImage image = robot.createScreenCapture(screenRectangle);
try {
File file = new File(fileName + ".png");
out = new FileOutputStream(file);
ImageIO.write(image, "png", out);
image.flush();
} catch (IOException e) {
e.printStackTrace(Log.getPw());
} finally {
try {
if (out != null) {
out.close();
}
} catch (IOException e) {
e.printStackTrace(Log.getPw());
}
}

代码首先指定一个矩形区域,就是要识别的文字区域---可以把手机屏幕投影到电脑上,然后截图识别.

之后BufferedImage image = robot.createScreenCapture(screenRectangle);开始截图

将截图保存到文件中,等待文字识别.

二. 识别图片文字

我们可以下载百度的文字识别SDK,在本地很方便的调用

// 初始化一个AipOcr,百度的APP_ID, API_KEY, SECRET_KEY
AipOcr client = new AipOcr(APP_ID, API_KEY, SECRET_KEY);

JSONObject res = client.basicGeneral("图片路径", new HashMap<String, String>());
JSONArray jsonArray = res.getJSONArray("words_result");

返回识别结果.

后续.........

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值