package per.zh.tess4j;
import com.recognition.software.jdeskew.ImageDeskew;
import net.sourceforge.tess4j.ITessAPI.TessPageIteratorLevel;
import net.sourceforge.tess4j.ITesseract;
import net.sourceforge.tess4j.ITesseract.RenderedFormat;
import net.sourceforge.tess4j.Tesseract;
import net.sourceforge.tess4j.Word;
import net.sourceforge.tess4j.util.ImageHelper;
import net.sourceforge.tess4j.util.LoggHelper;
import net.sourceforge.tess4j.util.Utils;
import org.apache.commons.codec.binary.StringUtils;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.junit.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
public class Tess4JTest {
private static final Logger logger = LoggerFactory.getLogger(new LoggHelper().toString());
static final double MINIMUM_DESKEW_THRESHOLD = 0.05d;
ITesseract instance;
private final String datapath = "src/test/resources";
private final String testResourcesDataPath = "src/test/resources/test-data";
private final String testResourcesLanguagePath = "src/test/resources/tessdata";
@BeforeClass
public static void setUpClass() throws Exception {
}
@AfterClass
public static void tearDownClass() throws Exception {
}
@Before
public void setUp() {
instance = new Tesseract();
instance.setDatapath(new File(datapath).getPath());
}
@After
public void tearDown() {
}
/**
* 获取cqccms电动自行车信息接口数据
*/
public String robotWorker(String vin) throws Exception {
String verifyCodeUrl = "http://mv.cqccms.com.cn/incoc/servlet/verifyCode";
String baseInfoUrl = "http://mv.cqccms.com.cn/incoc/GSViewEbike!doViewCocEbike.action";
//1. 打开浏览器 创建httpclient对象
CloseableHttpClient httpClient = HttpClients.createDefault();
//2. 输入网址
HttpGet httpGet = new HttpGet(verifyCodeUrl);
//3. 发送请求
CloseableHttpResponse httpResponse = httpClient.execute(httpGet);
//4. 响应结果
HttpEntity httpEntity = httpResponse.getEntity();
//5. 解析结果
InputStream verifyImageStream = httpEntity.getContent();
String imageFileName = "temp.gif";
File imageFile = null;
OutputStream os = null;
try {
imageFile = File.createTempFile("net_url", imageFileName);
os = new FileOutputStream(imageFile);
int bytesRead = 0;
byte[] buffer = new byte[8192];
while ((bytesRead = verifyImageStream.read(buffer, 0, 8192)) != -1) {
os.write(buffer, 0, bytesRead);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (null != os) {
os.close();
}
if (null != verifyImageStream) {
verifyImageStream.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
BufferedImage bi = ImageIO.read(imageFile);
// 设置语言
instance.setDatapath(testResourcesLanguagePath);
instance.setLanguage("chi_sim");
// 解析验证码
String verifyCode = instance.doOCR(bi);
if(!verifyCode.isEmpty() && !verifyCode.trim().isEmpty()) {
verifyCode = verifyCode.replace("\n", "");
logger.info(verifyCode);
}
//删除缓存图片
imageFile.delete();
String infoUrl = baseInfoUrl+"?vinCode=" + vin + "&engineNo=" + verifyCode;
/// 获取车辆信息
HttpGet httpGet1 = new HttpGet(infoUrl);
httpResponse = httpClient.execute(httpGet1);
httpEntity = httpResponse.getEntity();
String result = EntityUtils.toString(httpEntity, "GBK");
// 关闭连接
httpClient.close();
return result;
}
@Test
public void bicycleRobot() throws Exception {
String vin = "122421958708445";
String info = robotWorker(vin);
logger.info(info);
}
}
Tess4J-master.rar
版权申诉
5星 · 超过95%的资源 145 浏览量
2021-12-08
11:06:09
上传
评论
收藏 71.84MB RAR 举报
core512
- 粉丝: 481
- 资源: 78
最新资源
- 毕业设计基于STM32的测量温度与压力的数据处理设计C语言完整源码+论文.zip
- 基于MATLAB的PCA算法人脸识别项目源码+GUI界面+说明文档.zip
- 基于STM32的测量温度与压力的数据处理设计源码+论文(毕业设计).zip
- Vision Transformer 网络对不同氨气氧气浓度轨迹RAS 图像数据集的分类,包含训练权重和数据集、迁移学习
- 基于C51带字库LCD12864(ST7920)的keil工程源码,只支持8位并口通讯(不支持串口),可显示中文.zip
- 基于SI4463射频模块433MD-SMA无线模块软硬件技术资料及(SI4463)IC技术资料文档.zip
- (GPS+北斗+GSM)HLK-GS2503模块软硬件开发资料包硬件参考设计(原理图PCB)+技术文档资料.zip
- 基于BERT+Biaffine结构的关系抽取模型源码+文档说明.zip
- 利用c语言编写的冒泡排序代码
- 基于Ansoft-HFSS知识总结hfss中文教程HFSS培训教材等技术资料合集(50个).zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈