从图像中读取的文本 [英] Text reading from image

查看:110
本文介绍了从图像中读取的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从Image中读取一个文本,因为我编写了以下代码。我使用了MODI和OCR方法。这段代码只读取了具有Times New Roman和Arial Font的文本。但实际上我使用的Monotype Carsiva字体的图像无法被代码识别。如何从图像中读取文字,其中包含Monotype Carsiva字体的文字



代码

 使用系统; 
使用 System.Collections.Generic;
使用 System.Linq;
使用 System.Text;
使用 System.Threading.Tasks;
使用 System.IO;
使用 MODI;
使用 System.Threading;

命名空间 ImageProcessingConsoleApplication
{
class Program
{
静态 void Main( string [] args)
{

// 设置示例图像路径
字符串 ImagePath = AppDomain.CurrentDomain.BaseDirectory + dev.jpg;

ReadTextFromImage(ImagePath);

// 设置商店图片内容文本文件路径
< span class =code-sdkkeyword> String StoreTextFilePath = AppDomain.CurrentDomain.BaseDirectory + SampleText.txt ;

ReadTextFromImage(ImagePath,StoreTextFilePath);

Console.ReadLine();

}
public static void ReadTextFromImage( String ImagePath)
{
try
{
// 从图像中抓取文本
MODI。文档ModiObj = new MODI.Document();

ModiObj.Create(ImagePath);
ModiObj.OCR(MODI.MiLANGUAGES.miLANG_ENGLISH, true true );



// 检索从图像中收集的文本
MODI.Image ModiImageObj =(MODI.Image)ModiObj.Images [ 0 ];

System.Console.WriteLine(ModiImageObj.Layout.Text);
ModiObj.Close();
}
catch (例外情况)
{
throw new 例外(ex.Message);

}
} 私有 静态 void ReadTextFromImage( String ImagePath, String StoreTextFilePath)
{
尝试
{
MODI.Document ModiObj = MODI。文献();

ModiObj.Create(ImagePath);
ModiObj.OCR(MODI.MiLANGUAGES.miLANG_ENGLISH, true true );


// 检索从图像收集的文本
MODI.Image ModiImageObj =(MODI.Image)ModiObj.Images [ 0 ];



// 将图像内容存储在文本文件中
FileStream CreateFileObj = new FileStream(StoreTextFilePath,FileMode.Create);

// 将图像文本保存在文本文件中
StreamWriter WriteFileObj = new StreamWriter(CreateFileObj);
WriteFileObj.Write(ModiImageObj.Layout.Text);
WriteFileObj.Close();

ModiObj.Close();
}
catch (例外情况)
{
throw new 例外(ex.Message);
}

}
}
}

解决方案

hi。你可以点击这些显示OCR技术的链接...

 http://code.google.com/p/tesseract-ocr/ 
http://networkprogramming.wordpress.com/2012/03/14/convert-an-image-to-text-in-c/
http://ns-developers.com/c-net-read-文本从图像-OCR组分和 - C-NET /


I want to read a text from Image for that i write following code..I Used MODI and OCR methods.This code is only read the text having "Times New Roman" and "Arial Font". but actually image which i used having "Monotype Carsiva" font which can't be recognized by code.How to read text from Image in which text having "Monotype Carsiva" Font

Code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using MODI;
using System.Threading;
 
namespace ImageProcessingConsoleApplication
{
    class Program
    {
        static void Main(string[] args)
        {

            // Set Sample Image Path
            String ImagePath = AppDomain.CurrentDomain.BaseDirectory + "dev.jpg";

            ReadTextFromImage(ImagePath);

            // Set Store Image Content text file Path
            String StoreTextFilePath = AppDomain.CurrentDomain.BaseDirectory + "SampleText.txt";

            ReadTextFromImage(ImagePath, StoreTextFilePath);

            Console.ReadLine();

        }
public static void ReadTextFromImage(String ImagePath)
        {
            try
            {
                // Grab Text From Image 
                MODI.Document ModiObj = new MODI.Document();
              
                ModiObj.Create(ImagePath);
                ModiObj.OCR(MODI.MiLANGUAGES.miLANG_ENGLISH, true, true);
              
             

                //Retrieve the text gathered from the image  
                MODI.Image ModiImageObj = (MODI.Image)ModiObj.Images[0];
                
                System.Console.WriteLine(ModiImageObj.Layout.Text);
                ModiObj.Close();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);

            }
        }  private static void ReadTextFromImage(String ImagePath, String StoreTextFilePath)
        {
            try
            {
                MODI.Document ModiObj = new MODI.Document();
               
                ModiObj.Create(ImagePath);
                ModiObj.OCR(MODI.MiLANGUAGES.miLANG_ENGLISH, true, true);
               

                //Retrieve the text gathered from the image  
                MODI.Image ModiImageObj = (MODI.Image)ModiObj.Images[0];
                


                // Store Image Content in Text File  
                FileStream CreateFileObj = new FileStream(StoreTextFilePath, FileMode.Create);

                //save the image text in the text file   
                StreamWriter WriteFileObj = new StreamWriter(CreateFileObj);
                WriteFileObj.Write(ModiImageObj.Layout.Text);
                WriteFileObj.Close();

                ModiObj.Close();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }

        }
}
}

解决方案

hi.. you can follow these links which shows about OCR techniques...

http://code.google.com/p/tesseract-ocr/
http://networkprogramming.wordpress.com/2012/03/14/convert-an-image-to-text-in-c/
http://ns-developers.com/c-net-read-text-from-image-ocr-component-and-c-net/


这篇关于从图像中读取的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆