码迷,mamicode.com
首页 > 其他好文 > 详细

利用AForge+Tesseract制作视频OCR程序

时间:2017-05-12 01:33:03      阅读:295      评论:0      收藏:0      [点我收藏+]

标签:nts   sem   rect   技术   sof   制作   地址   选区   legacy   

先上界面:

技术分享


实现功能及流程:

1:从摄像头获取图像,框选要识别的区域

2:对选区进行图像处理,方便识别

3:识别文字

4:获取芯片上的内容(使用客户提供的芯片解码程序)

5:比较两个内容是否一致

6:写入数据库(带图片)

7:对历史数据进行查阅、导出Word(导出时带图片)


此版本将4~7功能去除了

获取图像:

使用AForge组件(参考项目:http://download.csdn.net/detail/jrlxsy/6927833),为了绘选区,将图像通过PictureBox显示出来,事件:videoSource.NewFrame += VideoSource_NewFrame;

        /// <summary>
        /// 视频产生新祯时的事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="eventArgs"></param>
        private void VideoSource_NewFrame(object sender, NewFrameEventArgs eventArgs)
        {
            try
            {
                srcBitmap = (Bitmap)eventArgs.Frame.Clone();
                pictureBoxIn.Image = drawRectangle(new Bitmap(srcBitmap));
                GC.Collect();
            }
            catch (Exception) { }
        }

图片框事件:

        #region 视频预览框事件
        private void pictureBoxIn_MouseDown(object sender, MouseEventArgs e)
        {
            sx = e.X;//记录当前鼠标坐标信息
            sy = e.Y;
            isDrawRect = true;//鼠标点下是绘制矩形
            w = h = 0;
            pictureBoxIn.Refresh();
        }

        private void pictureBoxIn_MouseMove(object sender, MouseEventArgs e)
        {
            if (!isDrawRect)
            {//如果不允许绘制 直接返回
                return;
            }
            w = e.X - sx;
            h = e.Y - sy;
            //pictureBoxIn.Refresh();//刷新窗体(主要是在move事件里面在不停绘制绘制一次刷新一次(上次绘制的就被清除了))
            pictureBoxIn.Image = drawRectangle(pictureBoxIn.Image);
        }

        private void pictureBoxIn_MouseUp(object sender, MouseEventArgs e)
        {
            isDrawRect = false;// 鼠标抬起禁止绘制矩形 并且把矩形区域的图像绘制出来
        }
        #endregion

然后就是图像的预处理和识别了,预处理用的是ZPhotoEngine库,地址:http://download.csdn.net/detail/trent1985/9591030,主要就是进行前景与背景分离,得到黑白的图像(右下图片框的图片)。

使用了中值滤波、高斯模糊、高反差保留、阈值几个方法。


识别就使用Tesseract3.0.2.0,不过这家伙的语言库有点大,一个eng的居然快50M,2.0.4.0的才1.6M。


另外,ZPhotoEngine库需要设置允许不安全代码,SQLite需要设置2.0环境,App.config设置如下(重点是startup段的配置):

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
    <supportedRuntime version="v2.0.50727"/>
  </startup>
  <system.diagnostics>
    <sources>
      <source name="Tesseract" switchValue="Verbose">
        <listeners>
          <clear />
          <add name="console" />
          <!-- Uncomment to log to file
                <add name="file" />
                -->
        </listeners>
      </source>
    </sources>
    <sharedListeners>
      <add name="console" type="System.Diagnostics.ConsoleTraceListener" />
    </sharedListeners>
  </system.diagnostics>
</configuration>



利用AForge+Tesseract制作视频OCR程序

标签:nts   sem   rect   技术   sof   制作   地址   选区   legacy   

原文地址:http://blog.csdn.net/apollokk/article/details/71642803

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!