【C#】身份证识别(一):身份证号定位
来源:互联网 发布:12345网络举报平台 编辑:程序博客网 时间:2024/06/18 15:54
完整项目地址:https://gitee.com/xgpxg/ICRS
一、图像预处理
- 灰度化图像。
- 二值化图像。 利用
AdaptiveThresholdType
全局化阈值,blockSize = 55时,效果最好。
public static Image<Gray,byte> BinImg(Image <Bgr ,byte> img) { return img.Convert<Gray, byte>().ThresholdAdaptive(new Gray(255), AdaptiveThresholdType.GaussianC, ThresholdType.Binary, 55, new Gray(55)).Erode(9); }
二、身份证号区域提取
- 扩选图像黑色像素区域,形成连通区域。
img.Erode(9)
- 提取轮廓。
/// <summary> /// 获取轮廓 /// </summary> /// <param name="pic"></param> /// <returns></returns> private static VectorOfVectorOfPoint GetContours(Image<Gray, byte> pic) { Image<Gray, byte> p1 = new Image<Gray, byte>(pic.Size); Image<Gray, byte> p2 = pic.Canny(60, 255); VectorOfVectorOfPoint contours = contours = new VectorOfVectorOfPoint(); CvInvoke.FindContours(p2, contours, p1, RetrType.Ccomp, ChainApproxMethod.ChainApproxSimple); return contours; }
- 轮廓筛选,提取身份证矩形区域。身份证号的宽高比约为8,将比值为7~9的轮廓保留,并绘制矩形
//筛选矩形 public static RotatedRect RotatedRect( Image<Bgr, byte> img) { Image<Bgr, byte> a = new Image<Bgr, byte>(img.Size); VectorOfVectorOfPoint con = GetContours(BinImg(img)); Point[][] con1 = con.ToArrayOfArray(); PointF[][] con2 = Array.ConvertAll<Point[], PointF[]>(con1, new Converter<Point[], PointF[]>(PointToPointF)); for (int i = 0; i < con.Size; i++) { RotatedRect rrec = CvInvoke.MinAreaRect(con2[i]); float w = rrec.Size.Width; float h = rrec.Size.Height; if (w / h > 6 && w / h < 10 && h > 20) { PointF[] pointfs = rrec.GetVertices(); for (int j = 0; j < pointfs.Length; j++) CvInvoke.Line(a, new Point((int)pointfs[j].X, (int)pointfs[j].Y), new Point((int)pointfs[(j + 1) % 4].X, (int)pointfs[(j + 1) % 4].Y), new MCvScalar(0, 0, 255, 255), 4); return rrec; } } return new RotatedRect(); }//绘制矩形 public static void DrawRotatedRect(RotatedRect rrec, Image<Bgr,byte> img) { PointF[] pointfs = rrec.GetVertices(); for (int j = 0; j < pointfs.Length; j++) CvInvoke.Line(img, new Point((int)pointfs[j].X, (int)pointfs[j].Y), new Point((int)pointfs[(j + 1) % 4].X, (int)pointfs[(j + 1) % 4].Y), new MCvScalar(0, 0, 255, 255), 4); }
三、定位结果
阅读全文
0 0
- 【C#】身份证识别(一):身份证号定位
- tf21: 身份证识别——识别身份证号
- 【C#】身份证识别(三):身份证信息识别
- Opencv+C++之身份证识别(一)
- Opencv+C++之身份证识别(一)
- 身份证识别——生成身份证号和汉字
- 阿里云 OCR身份证识别Api 使用(一)
- 【C#】身份证识别(二):提取目标区域图像
- 车牌识别之车牌定位(一)
- 身份证识别SDK-身份证识别api(移动端-服务器端)
- 身份证识别SDK-身份证识别api(移动端-服务器端)
- 【C#】基于Opencv/Emgucv的身份证识别
- 身份证识别
- 身份证校验(//身份证号合法性验证 //支持15位和18位身份证号//支持地址编码、出生日期、校验位验证)
- iOS身份证识别(OCR源码)
- 字符识别练习(验证码、车牌号、身份证号等)
- 图像识别练习(字符验证码、车牌号、身份证号)
- 图像识别练习(字符验证码、车牌号、身份证号)
- react native Navigator使用踩的坑
- 集合扩容问题(ArrList为例,常用集合扩容机制) -- JAVA 基础
- 【LeetCode】2. Add Two Numbers
- jsp的常用的标签
- 37条强大的常用linux shell命令组合
- 【C#】身份证识别(一):身份证号定位
- 遍历
- 编程范式20 函数式编程
- JVM调优总结(三)-基本垃圾回收算法
- Killers in Kaggle Competition
- 字符数组总结
- Redis Cluster原理和应用
- python的浅拷贝和深拷贝
- python多条件排序