从车牌识别到图片的相似度处理。开始的目的是识别车牌,以供研究opencv的,在接触车牌的识别的过程中,接触到java的tess4j以及java整合opencv的过程,但是车牌识别效率很低。人为识别是很清晰的但是仍然解析不出来。
1.Tess4j
引入依赖
<!-- https://mvnrepository.com/artifact/net.sourceforge.tess4j/tess4j -->
<dependency>
<groupId>net.sourceforge.tess4j</groupId>
<artifactId>tess4j</artifactId>
<version>3.4.8</version>
</dependency>
下载中文检索所需包否则会报错
Please make sure the TESSDATA_PREFIX environment variable is set to your “tessdata” directory
我是直接在gitee拉下来的包手动添加的 gitee.com/it_moon/tes…
2.Demo
public static void main(String[] args) throws IOException {
// 创建实例
ITesseract instance = new Tesseract();
// 设置识别语言
instance.setLanguage("chi_sim");
// 设置识别引擎
instance.setOcrEngineMode(0);
// 读取文件
BufferedImage image = ImageIO.read(TestTextOcr.class.getResourceAsStream("/2.jpg"));
try {
// 识别
String result = instance.doOCR(image);
System.out.println(result);
} catch (TesseractException e) {
System.err.println(e.getMessage());
}
}
车牌识别对应EL
String el ="/^[京津晋冀蒙辽吉黑沪苏浙皖闽赣鲁豫鄂湘粤桂琼渝川贵云藏陕甘青宁新][ABCDEFGHJKLMNPQRSTUVWXY][\\dABCDEFGHJKLNMxPQRSTUVWXYZ]{5}$/";
但是识别效率很低很低 参考其他的识别算法仍然识别不出来
public static void main(String[] args) throws TesseractException, IOException {
ITesseract instance = new Tesseract();
//如果未将tessdata放在根目录下需要指定绝对路径
//设置训练库的位置
//instance.setDatapath("the absolute path of tessdata");
//如果需要识别英文之外的语种,需要指定识别语种,并且需要将对应的语言包放进项目中
// chi_sim :简体中文, eng 根据需求选择语言库
instance.setLanguage("chi_sim");
// 指定识别图片
instance.setOcrEngineMode(0);
long startTime = System.currentTimeMillis();
String ocrResultNew = dealImage("C:\\Users\\Admin\\Desktop\\9-160514164SDY.jpg");
File imgDir = new File(ocrResultNew);
String ocrResult = instance.doOCR(imgDir);
String el ="/^[京津晋冀蒙辽吉黑沪苏浙皖闽赣鲁豫鄂湘粤桂琼渝川贵云藏陕甘青宁新][ABCDEFGHJKLMNPQRSTUVWXY][\\dABCDEFGHJKLNMxPQRSTUVWXYZ]{5}$/";
System.out.println("识别结果: \n" + ocrResult + "\n 耗时:" + (System.currentTimeMillis() - startTime) + "ms");
if(ocrResult.matches(el)){
// 输出识别结果
System.out.println("识别结果: \n" + ocrResult + "\n 耗时:" + (System.currentTimeMillis() - startTime) + "ms");
}else{
log.error("车牌识别有误");
}
}
然后我开始搜索java结合opencv的项目,但是仍然识别失败。 识别过程为:识别切图-->