当前位置:网站首页>【WinForm】关于截图识别数字并计算的桌面程序实现方案
【WinForm】关于截图识别数字并计算的桌面程序实现方案
2022-07-23 08:40:00 【TA远方】
在计算机办公场景中,处理非电子表的统计表文件时,通常需要手动输入数字,用计算器计算,这种操作无需自己效劳,可以拍照上图,或者截图下来,用现有OCR功能识别图中的数字,最后自动完成计算,这些是可以交给计算机自动完成的,不知道网上有没有这样的程序,有条件的就自己动手来实现吧
- 接下来,软件开发用C#语言编写程序,打开Visual Studio开发工具,建一个WinForm项目,建桌面程序,要实现一下三个功能
- 桌面截图
- 数字识别
- 计算器
关于桌面截图的实现,请参考这个文章【截屏工具窗口简单实现原理,附详细代码】,截图工具的运行效果

关于数字识别,有很多现成的OCR插件,这里用的插件是NuGet程序包中的 Spire.OCR,但只能用在64位机系统环境上

安装Spire.OCR注意事项
点安装后,还需要将其中packages\Spire.OCR.1.8.0\runtimes\win-x64\native文件夹下所有文件复制到运行文件夹中(通常是Debug)
- 下面是调用图文识别方法的相关代码
/// <summary>
/// Spire.OCR
/// </summary>
/// <param name="imgFileName"></param>
/// <param name="result"></param>
/// <returns></returns>
private bool UseSpireOCR(String imgFileName, out string result)
{
//创建一个OcrScanner类的实例
OcrScanner scanner = new OcrScanner();
//调用OcrScanner.Scan(string fileName)方法扫描图片上的文字
scanner.Scan(imgFileName);
//识别结果
string text = scanner.Text.ToString();
//测试,保存识别文字到txt文件
//File.WriteAllText("output.txt", text);
//System.Diagnostics.Process.Start("output.txt");
if (!String.IsNullOrEmpty(text))
{
//使用这个 会多出提示 仅用于评估目的
int lastIndex = text.LastIndexOf("Evaluation Warning : The version can be used only for evaluation purpose...");
if (lastIndex == 0) text = "";
else if (lastIndex > 0) text = text.Substring(0, lastIndex);//去掉提示
result = text;
return true;
}
result = "";
return false;
}
- 关于计算器,这里实现就简单,基本是由用户选择如何计算,默认是将识别到所有数字相加,求其和,或者求其平均数,求和实现代码如下
//传入图片文件 fileName, 识别结果赋值到 result
if (UseSpireOCR(fileName, out result))
{
var reg = new Regex(@"\d+(.\d+)\s*");
MatchCollection mes = reg.Matches(result);
if (mes.Count>0)
{
var text = new StringBuilder();
foreach(Match m in mes)
{
if (text.Length > 0) text.Append("+" + m.Value.Trim());
else text.Append(m.Value.Trim());
}
textBox1.Text = text.ToString();
text.Clear();
return;
}
textBox1.Text = "";
result = "识别非数字\n" + result;
MessageBox.Show(result, "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
- 计算器的实现代码这里就不列举了,很简单的,请自己实现,界面布局大致如下图

小提示
上面思路是将识别结果输出到文本编辑框中,用于计算器上显示的,其中的计算逻辑就是将用户输入框中的数字和运算符提取出来处理,然后参与运算,最后得出结果显示
边栏推荐
- Canvas eraser function
- 太平洋大西洋水流问题
- FFmpeg 2 - ffplay、ffprobe、ffmpeg 命令使用
- 强化學習——策略梯度理解點
- How many processors is Tianji 1100 equivalent to snapdragon? How about Tianji 1100 equivalent to snapdragon
- 鸡与蛋,产品与策略
- JS calendar style pie chart statistics plug-in
- js纹理样式饼图插件
- STM32输出正弦波+cubeMX配置+HAL库
- VK36N5D抗电源干扰/手机干扰 5键5通道触摸检测芯片防呆功能触摸区域积水仍可操作
猜你喜欢

js日历样式饼图统计插件

How about the nuclear display performance of Ruilong R7 Pro 6850h? What level is it equivalent to

回文相关题目

152. 乘积最大子数组

Surrounded Regions

Spotlight light box JS plug-in full screen enlarged picture

What level of rtx3070ti graphics card? What level of rtx3070ti graphics card? How about rtx3070ti graphics card
![[review of analog electricity - diode]](/img/dc/7b3c3187000be24053f0e69733444d.jpg)
[review of analog electricity - diode]

npm warn config global `--global`, `--local` are deprecated. use `--location=global` instead.

Day108. Shang Yitong: interface docking of hospital simulation system - query of hospital | Department | shift scheduling, addition, deletion, modification and paging conditions
随机推荐
優化華為雲服務器采用Key登陸
Stream stream is used for classification display.
Changing the historical length of chart during LabVIEW operation
CPU,内存,磁盘速度比较
Antd form - reset method does not work - Basic accumulation - importance of prop
JS calendar style pie chart statistics plug-in
How many processors is Tianji 820 equivalent to Xiaolong? How about Tianji 1100 equivalent to Xiaolong? How about Tianji 820
太平洋大西洋水流问题
炫酷代码雨动态背景注册页面
子序列 --- 编辑距离
Reinforcement learning -- understanding point of strategy gradient
激励发生器、监测器
ValidationError: Invalid options object. Dev Server has been initialized using an options object th
VK36N5D抗电源干扰/手机干扰 5键5通道触摸检测芯片防呆功能触摸区域积水仍可操作
STM32 outputs SPWM wave, Hal library, cubemx configuration, and outputs 1kHz sine wave after filtering
多重背包!
Drag and drop----
Renforcement de l'apprentissage - points de compréhension du gradient stratégique
第4章 集合运算
pageHepler丢失原sql order by条件的坑