c#.net

c# ocr

우유빛 2009. 8. 21. 14:34


참조 -> 추가 -> COM -> Microsoft Office Document Imaging 12.0 Type Library

private void Convert2OCR(String file)
        {
            MODI.Document md = new MODI.Document();
            md.Create(file);
            try
            {

                if (langSelect == 1)
                    md.OCR(MODI.MiLANGUAGES.miLANG_KOREAN, false, true); //한글은 회전하면 인식율 떨어짐
                else if (langSelect == 2)
                    md.OCR(MODI.MiLANGUAGES.miLANG_ENGLISH, true, true);
                else return;

                string strText = String.Empty;

                MODI.Image image = (MODI.Image)md.Images[0];
                MODI.Layout layout = image.Layout;

                for (int i = 0; i < layout.Words.Count; i++)
                {
                    MODI.Word word = (MODI.Word)layout.Words[i];
                    if (strText.Length > 0)
                    {
                        strText += " ";
                    }
                    strText += word.Text;

                }
                textBox1.Text = strText;
            }
            catch
            {
                textBox1.Text = "문자추출 실패";
                md.Close(false);

            }
            finally
            {
                md.Close(false);
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (filename == null) return;
            Convert2OCR(filename);
        }

http://blog.naver.com/PostView.nhn?blogId=tramper2&logNo=100085768695