当前位置: 首页 > news >正文

广东炒股配资网站开发济南建设网中标公告

广东炒股配资网站开发,济南建设网中标公告,wordpress多站点 缺点,已经有网站怎么做淘宝客一、相关的地址 https://github.com/tesseract-ocr/tessdata Releases - OpenCV opencv要装好,我装的是4.5.3的,最新版的没试过。 tessdata就下载了需要用的。好像还有best和fast的版本,我试了一下报错,不知道是不是版本不支持…

一、相关的地址

https://github.com/tesseract-ocr/tessdata

Releases - OpenCV

opencv要装好,我装的是4.5.3的,最新版的没试过。

tessdata就下载了需要用的。好像还有best和fast的版本,我试了一下报错,不知道是不是版本不支持的问题。

二、主要的思路

识别的代码到没什么特别的,就是在每一行的识别上,为了提高准确度,稍微花了点心思,但也不时很完善。

发现识别的时候会出现很多干扰,所以从“姓”这一行开始算第一行,然后一行一行分析。

如果图片不清晰,不是太准,有待改进。

三、代码

pom.xml的依赖:

        <!-- OpenCV --><dependency><groupId>org.openpnp</groupId><artifactId>opencv</artifactId><version>4.5.3-4</version></dependency><!--  Tesseract --><dependency><groupId>net.sourceforge.tess4j</groupId><artifactId>tess4j</artifactId><version>5.11.0</version> <!-- 使用最新版本 --></dependency>

JAVA代码:

package com.yutiandada.idcardread.demos.test;import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.core.Size;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;import java.io.File;
import java.io.IOException;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;import net.sourceforge.tess4j.*;public class IDCardRecognition2 {static {System.setProperty("java.library.path", "D:\\opencv\\opencv\\build\\java\\x64");try {Field fieldSysPath = ClassLoader.class.getDeclaredField("sys_paths");fieldSysPath.setAccessible(true);fieldSysPath.set(null, null);} catch (Exception e) {e.printStackTrace();}System.loadLibrary(Core.NATIVE_LIBRARY_NAME);}public static Mat preprocessImage(String imagePath) {// 读取图像Mat image = Imgcodecs.imread(imagePath);// 可选:进行一些图像增强操作,例如锐化Mat enhancedImage = new Mat();Imgproc.GaussianBlur(image, enhancedImage, new Size(0, 0), 3);Core.addWeighted(image, 1.5, enhancedImage, -0.5, 0, enhancedImage);return enhancedImage;}public static List<String> recognizeText(Mat mat) throws TesseractException {try {// 将Mat转换为FileFile tempFile = File.createTempFile("temp", ".png");Imgcodecs.imwrite(tempFile.getAbsolutePath(), mat);// 初始化TesseractTesseract tesseract = new Tesseract();tesseract.setLanguage("chi_sim"); // 设置语言为简体中文tesseract.setDatapath("d:/tessdata"); // 设置Tesseract数据路径
//            tesseract.setPageSegMode(PageSegMode.PSM_AUTO); // 设置页面分割模式// 进行OCR识别String result = tesseract.doOCR(tempFile);tempFile.delete(); // 删除临时文件// 将结果按行分割List<String> lines = new ArrayList<>();String[] splitResult = result.split("\\r?\\n");for (String line : splitResult) {if (!line.trim().isEmpty()) {lines.add(line.trim());}}return lines;} catch (IOException e) {// 处理异常,例如记录日志或显示错误信息e.printStackTrace();throw new TesseractException("Error during OCR processing", e);}}public static void main(String[] args) {try {String imagePath = "D:/images/test01.png";Mat processedImage = preprocessImage(imagePath);List<String> recognizedLines = recognizeText(processedImage);System.out.println("Recognized Text:");// 找到包含“姓”字的行索引int startIndex = -1;for (int i = 0; i < recognizedLines.size(); i++) {if (recognizedLines.get(i).contains("姓") || recognizedLines.get(i).contains("名") ) {startIndex = i;break;}}if (startIndex != -1) {// 从包含“姓”字的行开始重新编号List<String> filteredLines = recognizedLines.subList(startIndex, recognizedLines.size());// 第一行:“姓名”之后的字符串String name = filteredLines.get(0).replaceAll(".*姓名", "").trim();System.out.println("Name: " + name);// 第二行:性别String gender = "";String ethnicity = "";String secondLine = filteredLines.get(1);if (secondLine.contains("男")) {gender = "男";} else if (secondLine.contains("女")) {gender = "女";}int minIndex = secondLine.indexOf("民") + 2;if (minIndex > 0 && minIndex < secondLine.length()) {ethnicity = secondLine.substring(minIndex).trim();}System.out.println("Gender: " + gender);System.out.println("Ethnicity: " + ethnicity);// 第三行:出生日期,只显示数字String thirdLine = filteredLines.get(2).replaceAll("[^0-9]", "").trim();if (thirdLine.length() == 8) {String birthYear = thirdLine.substring(0, 4);String birthMonth = thirdLine.substring(4, 6);String birthDay = thirdLine.substring(6, 8);System.out.println("Birth Year: " + birthYear);System.out.println("Birth Month: " + birthMonth);System.out.println("Birth Day: " + birthDay);} else {System.out.println("Invalid date format in the third line.");}// 第四行:地址String addressPart1 = filteredLines.get(3).replaceAll("\\s+", "").substring(2).trim();String addressPart2 = filteredLines.get(4).replaceAll("\\s+", "").trim();String address = addressPart1 + addressPart2;System.out.println("Address: " + address);// 第六行:身份证号,只显示数字和字母String idNumber = filteredLines.get(5).replaceAll("[^a-zA-Z0-9]", "").trim();System.out.println("ID Number: " + idNumber);} else {System.out.println("No line containing '姓' found.");}} catch (Exception e) {e.printStackTrace();}}
}

IDEA里面要配置一下

把安装好的OPENCV装一下

四、效果

网上随便找的图

识别的效果

http://www.yayakq.cn/news/88533/

相关文章:

  • 免费建站的手机apppython 编辑wordpress
  • 网站建设 福田网站ftp地址是什么
  • 信用网站建设工作简报丹阳市住房和城乡建设局网站
  • 天津的网站建设公司工程信息网哪个好
  • 响应式网站怎么做pc端的推广引流渠道平台
  • 我想做一个网站怎么办百度关键词推广公司哪家好
  • 厦门外贸网站找谁网站推广和网站优化
  • 企业门户网站源码北京病例最新消息今天
  • 新泰网站开发制作北京建站管理系统开发
  • 唐山免费自助建站模板深圳网站设计兴田德润i简介
  • 网站监测怎么做网页设计与制作简答题
  • 分类网站怎么做项目四川建筑人员信息查询
  • 网站右下角代码wordpress 侧栏加flash
  • 做网站的业务员如何开微信小程序店铺
  • 网站建设文化流程wordpress外链图床插件
  • 建英文网站有用吗临沂做网站找哪家好
  • 网站建设解决方案ppt模板wordpress超cpu
  • 柳州网站建设柳州wordpress屏蔽右键菜单并提示
  • 女的男的做那个视频网站discuz做的网站
  • sns网站设计旅行社门店做网站嘛
  • 网站做seo网站建设目的与作用
  • 福建手机版建站系统开发网站页面设计报价
  • 返利系统网站开发不要域名做网站
  • 北京网站制作计划网站建设站长
  • 网站建设与熊掌号未来的关系工程做网站
  • 仪陇网站建设wordpress筛选最新文章
  • 北京好的网站开发为什么网站要改版
  • 网站建设需要用到那些语言电子商务网站首页设计
  • 网站建设经营服务合同美食网站页面设计源代码
  • 360免费做网站电话租赁公司租赁业务