c#调用ocr识别数字

公司最近安排我做一个收银系统的插件,我要根据照片去识别别人系统的金额,老板太抠,又不想出钱调取百度的api,让我们自己摸索,经过一条的捣鼓还真让我给捣鼓出来了,现在把项目分享给大家

我们先看一下具体的演示的过程
运行软件:
在这里插入图片描述
选取我们要获取的区域:红色框即为我们要获取的区域
在这里插入图片描述
点击开始获取就可以识别我们的数字了:
在这里插入图片描述
项目的主要动态库为项目下面的三个动态库文件
在这里插入图片描述
具体调用函数如下:

using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;

namespace OcrAcquireDemo
{
    public class OcrHelpher
    {
        [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);

        public static string ImageToString(string imagePath, int width, int height)
        {
            try
            {
                return Marshal.PtrToStringAnsi(OCRpart(imagePath, -1, 0, 0, width, height));
            }
            catch (Exception ex)
            {
                Console.WriteLine("ocr图像识别出现异常:" + ex.Message.ToString());
                return "";
            }

        }      
}

为了便于大家理解我们项目demo分享给大家,欢迎感兴趣的朋友可以看一看

链接:https://pan.baidu.com/s/1-VLMauOV_ES72mv6rKoZdQ 
提取码:hhk7 
--来自百度网盘超级会员V3的分享
var foo = 'bar';
  • 5
    点赞
  • 25
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 15
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 15
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

搬砖大师兄.

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值