c# - EmguCV 在 C# 中对 ID 卡或 Pan Card 进行歪斜检测
问题描述
我想使用 emgucv 检测身份证或 Pan 卡等图像的方向,以便我可以校正图像并将其传递给 tesseract OCR。我搜索了谷歌在 C# 中找不到示例。
任何人都可以在这里指导我或提出一些例子吗?任何帮助将不胜感激。
imgInput = new Image<Bgr, byte>(impath);
Image<Gray, Byte> imggray = imgInput.Convert<Gray, Byte>();
VectorOfVectorOfPoint contour = new VectorOfVectorOfPoint();
Emgu.CV.Mat hiers = new Emgu.CV.Mat();
CvInvoke.FindContours(imggray, contour, hiers, Emgu.CV.CvEnum.RetrType.External, Emgu.CV.CvEnum.ChainApproxMethod.ChainApproxSimple);
Bitmap imgsss;
if (contour.Size >= 1)
{
for (int i = 0; i <= 1; i++)
{
Rectangle rect = CvInvoke.BoundingRectangle(contour[i]);
Emgu.CV.Structure.RotatedRect box = CvInvoke.MinAreaRect(contour[i]);
imggray.ROI = rect;
imggray = imggray.Rotate(box.Angle, new Gray(255));
imggray.Save(impath);
imgsss = imggray.Copy().Bitmap;
break;
}
}
解决方案
不幸的是,我一直在努力寻找 Emgucv 的文档。很多时候,我会查看 2013 年的一些晦涩的博客文章,并且必须修改代码才能与最新版本的 Emgucv 正常工作。为了弥补这一点,我经常会查看 opencv 的 c++ 代码,并只是修改其中的一部分以与 c# 一起使用。我发现这比较好用,因为从 opencv c++ 到 emgucv c# 的语法相对相同,而从 opencv python 到 emgucv c#。要回答有关检测身份证和更正方向的问题,请在此处查看此链接。
https://www.learnopencv.com/image-alignment-feature-based-using-opencv-c-python/
基本思想是创建一个特征检测器来检测图像的相关部分,然后使用匹配器和扭曲透视来确定方向。如前所述,代码是用 c++ 编写的,但我应该很容易转换,大多数函数都包含在 namespaceCvInvoke
中。
推荐阅读
- select - CodeMirror:选择活动(聚焦)编辑器
- google-cloud-platform - 如何从 Google Cloud Functions 中删除文件
- netlogo - 错误:这不是您可以在 netlogo 上使用的设置
- java - 使用 Visual Studio Code 远程扩展运行 JavaFX
- image - 使用 ResNet-50 进行图像分类
- java - android中listview中的重复值
- angular - 使用产品 ID-Anguler 8 和 Firebase 读取和显示单个产品数据
- python - 如何将多个熊猫数据帧转换为内存约束中的数组?
- javascript - 流式传输 html/内容,但可以控制在已解析内容中插入哪个部分(不是以附加方式)
- .net - 调用 Google API 得到“调用者没有权限 [403]”