找回密码
 立即注册

QQ登录

只需一步,快速开始

druidAAAA

注册会员

11

主题

36

帖子

95

积分

注册会员

积分
95
druidAAAA
注册会员   /  发表于:2017-1-11 15:32  /   查看:3396  /  回复:3
本帖最后由 druidAAAA 于 2017-1-11 15:48 编辑

背景:        我做一个识别游戏的程序


思路:
         通过不断的截图, 识别出牌的类别  (当然, 也要识别玩家的名字)

问题:
        复杂的玩家名字很容易的识别出来 (附图1: 识别出 adeptRock272)
        但是
       简单的一个4, 无法识别, 根本认不出这是个字.  是我哪里做得不对吗  ??

///////////////////////////////////////////////////////////////////////////////////////////////////////////
1) 附件为 pnp 文件, 因为论坛禁止上传 pnp,  我只能改成扩展名为 jpg,  其实格式还是 pnp
版主请见谅,  我用 pnp 是因为 pnp 比 jpg 对这些色块的兼容性更好

2) 代码如下,
通过MemoryStrem传递截图:
public string Read(System.IO.MemoryStream img)
        {
            using (IOcrDocument ocrDocument = ocrEngine.DocumentManager.CreateDocument())
            {
                img.Position = 0;
                IOcrPage ocrPage = ocrDocument.Pages.AddPage(img, null);

                ocrPage.Recognize(null);

                System.IO.MemoryStream stream = new System.IO.MemoryStream();
                ocrDocument.Save(stream, DocumentFormat.Text, null);

                byte[] buff = stream.ToArray();
                string rsl = System.Text.Encoding.Default.GetString(buff);

                return rsl;
            }
        }


本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x

3 个回复

倒序浏览
Richard.Ma讲师达人认证 悬赏达人认证 SpreadJS 开发认证
超级版主   /  发表于:2017-1-11 17:09:22
沙发
这种字体看着比较简单,但是因为有黑色的边框和红色的北京,软件识别时可能会将边框识别为其他内容
对图片进行二值化处理转换为黑白图片即可识别,可参考
\LEADTOOLS 19\Examples\DotNet\CS\OcrMultiEngineDemo中

功能及代码,处理后在进行识别即可

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
回复 使用道具 举报
druidAAAA
注册会员   /  发表于:2017-1-11 20:32:45
板凳
本帖最后由 druidAAAA 于 2017-1-11 20:34 编辑
Richard.Ma 发表于 2017-1-11 17:09
这种字体看着比较简单,但是因为有黑色的边框和红色的北京,软件识别时可能会将边框识别为其他内容
对图片 ...

多谢万能的版主大大.
1) 你给我的这个例子, 我跑不起来(我现在还在试), 不知这个例子是否有官方的文档说明?  
   (另: 我在中文LeadTools网站上  
    http://leadtools.gcpowertools.com.cn/products/imaging/image-processing/
   的 LEADTOOLS Image Processing SDK技术综述 里面
   找到了这个 32位和64位图像处理二进制文件
   但似乎他没有如 MSDN 一样指向具体的文档,  不知我应该如何查阅? )

2) 在上面这条路还没走通的时候, 我写了3个函数来做二值化.  出来的图形似乎可以接受, 但是仍然无法用 Advantage 引擎识别;
     你觉得解决的思路会不会在识别引擎的使用上?  (如果需要我也可以贴我写的OCR引擎调用代码, 但是这里贴出来就太长啦)
    这里附上我转化后的图形.
    (我会在下面贴上我的3个转化函数给您参考, 如果需要的话.)
-----------------------------------------------------------------------------------------------------------------------------------------------------------

Bitmap Binarization(Bitmap bmp) // 此函数调用了3个我写的粗糙的图像转化功能,  见笑了.
        {
            bmp = ToGray((Bitmap)bmp);
            bmp = GrayReverse((Bitmap)bmp);
            bmp = ConvertTo1Bpp2((Bitmap)bmp);
            return bmp;
        }

------------------------------------------------------------------------------------------------------------------------------------------------------------
Bitmap ToGray(Bitmap bmp)
        {
            for (int i = 0; i < bmp.Width; i++)
            {
                for (int j = 0; j < bmp.Height; j++)
                {
                    //获取该点的像素的RGB的颜色
                    Color color = bmp.GetPixel(i, j);
                    //利用公式计算灰度值
                    int gray = (int)(color.R * 0.3 + color.G * 0.59 + color.B * 0.11);
                    Color newColor = Color.FromArgb(gray, gray, gray);
                    bmp.SetPixel(i, j, newColor);
                }
            }
            return bmp;
        }
-----------------------------------------------------------------------------------------------------------------------------------------------------------
Bitmap GrayReverse(Bitmap bmp)
        {
            for (int i = 0; i < bmp.Width; i++)
            {
                for (int j = 0; j < bmp.Height; j++)
                {
                    //获取该点的像素的RGB的颜色
                    Color color = bmp.GetPixel(i, j);
                    Color newColor = Color.FromArgb(255 - color.R, 255 - color.G, 255 - color.B);
                    bmp.SetPixel(i, j, newColor);
                }
            }
            return bmp;
        }

-----------------------------------------------------------------------------------------------------------------------------------------------------------
Bitmap ConvertTo1Bpp2(Bitmap img)
        {
            int w = img.Width;
            int h = img.Height;
            Bitmap bmp = new Bitmap(w, h, PixelFormat.Format1bppIndexed);
            BitmapData data = bmp.LockBits(new Rectangle(0, 0, w, h), ImageLockMode.ReadWrite, PixelFormat.Format1bppIndexed);
            for (int y = 0; y < h; y++)
            {
                byte[] scan = new byte[(w + 7) / 8];
                for (int x = 0; x < w; x++)
                {
                    Color c = img.GetPixel(x, y);
                    if (c.GetBrightness() >= 0.5) scan[x / 8] |= (byte)(0x80 >> (x % 8));
                }
                Marshal.Copy(scan, 0, (IntPtr)((int)data.Scan0 + data.Stride * y), scan.Length);
            }
            return bmp;
        }



本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
回复 使用道具 举报
Richard.Ma讲师达人认证 悬赏达人认证 SpreadJS 开发认证
超级版主   /  发表于:2017-1-12 10:36:17
地板
这里有示例的可执行程序可以参考,看看运行会有什么问题
\LEADTOOLS 19\Shortcuts\OCR - MICR - ICR - OMR\.NET Class Libraries\Main OCR Demo
跑不起来是编译还是运行报错么
引擎的调用方式没有区别,Professional引擎确实识别率较高,昨天的4这个数字二值化以后用之可以识别
建议你换用Professional引擎来验证

文档方面,官方的支持最全,https://www.leadtools.com/support
如果英语可以的话,建议在上面查询问题
https://www.leadtools.com/help/l ... ols.topics.ocr.html
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部