C# 中 ID 卡或 Pan 卡的 EmguCV 偏差检测

EmguCV skew detection for ID card or Pan Card in C#

我想使用 emgucv 检测图像的方向,例如 Id 卡或 Pan 卡,以便我可以校正图像并将其传递给 tesseract OCR。我已经搜索 google 无法在 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 年的一些不起眼的博客 post,并且必须修改代码才能与最新版本的 Emgucv 正常工作。为了弥补这一点,我经常会查看 opencv 的 c++ 代码,并只修改其中的一部分以与 c# 一起工作。我发现它的工作相对较好,因为从 opencv c++ 到 emgucv c# 的语法与 opencv python 到 emgucv c# 的语法相对相同。要回答有关检测身份证和更正方向的问题,请在此处查看 link。

https://www.learnopencv.com/image-alignment-feature-based-using-opencv-c-python/

基本思路是创建一个特征检测器来检测图像的相关部分,然后使用匹配器和扭曲透视来固定方向。如前所述,代码是用 c++ 编写的,但我应该很容易转换,大多数函数都包含在命名空间 CvInvoke.