【OCR】AspriseOCR C# 英文、数字识别(中文不行)

4 篇文章 0 订阅

原图

一、AspriseOCR  4.0 破解版

识别效果

x86

 

C#源码

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace ToText
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        #region DllImport
        [DllImport("AspriseOCR.dll", EntryPoint = "OCR", CallingConvention = CallingConvention.Cdecl)]
        public static extern IntPtr OCR(string file, int type);

        [DllImport("AspriseOCR.dll", EntryPoint = "OCRpart", CallingConvention = CallingConvention.Cdecl)]
        static extern IntPtr OCRpart(string file, int type, int startX, int startY, int width, int height);

        [DllImport("AspriseOCR.dll", EntryPoint = "OCRBarCodes", CallingConvention = CallingConvention.Cdecl)]
        static extern IntPtr OCRBarCodes(string file, int type);

        [DllImport("AspriseOCR.dll", EntryPoint = "OCRpartBarCodes", CallingConvention = CallingConvention.Cdecl)]
        static extern IntPtr OCRpartBarCodes(string file, int type, int startX, int startY, int width, int height);
        #endregion

        #region 转换按钮事件
        // 转换按钮事件
        private void button2_Click(object sender, EventArgs e)
        {
            int startX = 0;
            int startY = 0;
            int width = -1;
            int height = -1;

            string img_path = txt_imgpath.Text; // 图片路径
            if (String.IsNullOrEmpty(img_path)) // 图片非空验证
            {
                MessageBox.Show("请先选择图片!");
                return;
            }
            try
            {
                Image img = Image.FromFile(img_path);
                width = img.Width;
                height = img.Height;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.StackTrace);
            }
            txt_result.Text = Marshal.PtrToStringAnsi(OCRpart(img_path, -1, startX, startY, width, height));
        }
        #endregion

        #region 浏览事件
        // 浏览事件
        private void btn_imgpath_Click(object sender, EventArgs e)
        {
            openFileDialog1.ShowDialog();
            txt_imgpath.Text = openFileDialog1.FileName;
        }
        // 浏览图片
        private void txt_imgpath_Click(object sender, EventArgs e)
        {
            openFileDialog1.ShowDialog();
            txt_imgpath.Text = openFileDialog1.FileName;
        }
        #endregion
      

    }
}

二、AspriseOCR  15.3 

 

 

识别效果(x64) 

源码:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using asprise_ocr_api;
namespace ToText
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        #region DllImport
        [DllImport("AspriseOCR.dll", EntryPoint = "OCR", CallingConvention = CallingConvention.Cdecl)]
        public static extern IntPtr OCR(string file, int type);

        [DllImport("AspriseOCR.dll", EntryPoint = "OCRpart", CallingConvention = CallingConvention.Cdecl)]
        static extern IntPtr OCRpart(string file, int type, int startX, int startY, int width, int height);

        [DllImport("AspriseOCR.dll", EntryPoint = "OCRBarCodes", CallingConvention = CallingConvention.Cdecl)]
        static extern IntPtr OCRBarCodes(string file, int type);

        [DllImport("AspriseOCR.dll", EntryPoint = "OCRpartBarCodes", CallingConvention = CallingConvention.Cdecl)]
        static extern IntPtr OCRpartBarCodes(string file, int type, int startX, int startY, int width, int height);
        #endregion

        #region 转换按钮事件
        // 转换按钮事件
        private void button2_Click(object sender, EventArgs e)
        {
            int startX = 0;
            int startY = 0;
            int width = -1;
            int height = -1;

            string img_path = txt_imgpath.Text; // 图片路径
            if (String.IsNullOrEmpty(img_path)) // 图片非空验证
            {
                MessageBox.Show("请先选择图片!");
                return;
            }
            try
            {
                Image img = Image.FromFile(img_path);
                width = img.Width;
                height = img.Height;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.StackTrace);
            }
            // txt_result.Text = Marshal.PtrToStringAnsi(OCRpart(img_path, -1, startX, startY, width, height));
            AspriseOCR.SetUp();
            AspriseOCR ocr = new AspriseOCR();
            ocr.StartEngine("eng", AspriseOCR.SPEED_FASTEST);
            string s = ocr.Recognize(img_path, -1, -1, -1, -1, -1, AspriseOCR.RECOGNIZE_TYPE_ALL, AspriseOCR.OUTPUT_FORMAT_PLAINTEXT);

            ocr.StopEngine();
            txt_result.Text = s;
        }
        #endregion

        #region 浏览事件
        // 浏览事件
        private void btn_imgpath_Click(object sender, EventArgs e)
        {
            openFileDialog1.ShowDialog();
            txt_imgpath.Text = openFileDialog1.FileName;
        }
        // 浏览图片
        private void txt_imgpath_Click(object sender, EventArgs e)
        {
            openFileDialog1.ShowDialog();
            txt_imgpath.Text = openFileDialog1.FileName;
        }
        #endregion


    }
}

 参考:

LanTenggit/orc: orc图片识别(MODI) (github.com)icon-default.png?t=M4ADhttps://github.com/LanTenggit/orc

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值