Skip to content

Commit

Permalink
feat: 升级.net8和相关依赖
Browse files Browse the repository at this point in the history
  • Loading branch information
sangyuxiaowu committed Jan 23, 2024
1 parent 54e3664 commit 57a9122
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 61 deletions.
41 changes: 17 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,38 +1,31 @@
# Snipping_OCR

A simple desktop screenshot OCR tool for Windows platform, use the system's own screenshot tool to take screenshots, use PaddleOCRSharp for OCR recognition, and support Chinese and English OCR character recognition.
Snipping_OCR is a straightforward desktop screenshot OCR tool designed for the Windows platform. It utilizes the system's built-in screenshot tool for capturing images and PaddleOCRSharp for OCR recognition. The software supports OCR character recognition in both Chinese and English.

一个适用于 Windows 平台的简单桌面截图 OCR 工具,使用系统自带截图工具截图,使用 PaddleOCRSharp 来进行 OCR 识别,支持中英文的 OCR 字符识别。
English | [简体中文](./README_zh.md)

已经测试过 Win10 和 Win11,不支持 Win7。
The tool has been tested on Windows 10 and Windows 11. Please note that it does not support Windows 7.

<p align="center">
<img src="./doc/6.png">
</p>

# Features
## Features

- Software supports offline use
- Chinese and English support
- Clipboard image recognition
- Drag and drop
- Supports offline usage
- Recognizes Chinese and English characters
- Recognizes clipboard images
- Allows drag and drop

<hr>
## Installation

- 离线使用
- 中英文字符识别
- 剪切板识别
- 支持拖拽
You can download and unzip the software from the repository's Releases. No installation is required. We provide standalone versions for windows and versions dependent on the .NET6 framework. For the framework-dependent version, you need to install the [.NET8 runtime](https://dotnet.microsoft.com/zh-cn/download/dotnet/8.0).

# Installation
## Usage

在仓库的 Releases 下载解压使用即可,无需安装。提供有 windows 的对立版本和 .NET6 框架依赖版本。框架依赖版本需要安装 [.NET6 运行时](https://dotnet.microsoft.com/zh-cn/download/dotnet/6.0)

# Usage

1. 双击 `Snipping_OCR.exe`启动软件。
2. 最小化将最小化到托盘,关闭为退出软件。
3. 使用快捷键 `Ctrl + Alt + A`启动截图。
4. 若快捷无法正常使用,可以使用其他软件或者系统自带的截图工具 “Win + Shift + S”截图后,在托盘使用右键菜单 “识别剪贴板”来进行 OCR 识别
5. 可以将图片拖放到左边空白区域来识别
6. 复制图片文件后也可以在托盘使用右键菜单 “识别剪贴板”来进行 OCR 识别
1. Double-click `Snipping_OCR.exe` to launch the software.
2. Minimizing the software will minimize it to the tray, while closing it will exit the software.
3. Use the `Ctrl + Tab` shortcut to initiate a screenshot.
4. If the shortcut cannot be used normally, you can use other software or the system's built-in screenshot tool “Win + Shift + S” to take a screenshot. Then, use the right-click menu "Recognize Clipboard" in the tray to perform OCR recognition.
5. You can drag and drop images into the left blank area for recognition.
6. After copying an image file, you can also use the right-click menu "Recognize Clipboard" in the tray to perform OCR recognition.
31 changes: 31 additions & 0 deletions README_zh.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Snipping_OCR

Snipping_OCR 是一个简单的桌面截图 OCR 工具,专为 Windows 平台设计。它使用系统自带的截图工具进行截图,并使用 PaddleOCRSharp 进行 OCR 识别。软件支持中英文的 OCR 字符识别。

[English](./README.md) | 简体中文

该工具已在 Windows 10 和 Windows 11 上进行过测试。请注意,它不支持 Windows 7。

<p align="center">
<img src="./doc/6.png">
</p>

## 功能

- 支持离线使用
- 中英文字符识别
- 剪切板图片识别
- 支持拖拽

## 安装

你可以在仓库的 Releases 下载并解压软件,无需安装。我们提供了 Windows 的独立版本和依赖 .NET8 框架的版本。对于依赖框架的版本,你需要安装 [.NET8 运行时](https://dotnet.microsoft.com/zh-cn/download/dotnet/8.0)

## 使用

1. 双击 `Snipping_OCR.exe` 启动软件。
2. 最小化将软件最小化到托盘,关闭则为退出软件。
3. 使用快捷键 `Ctrl + Tab` 启动截图。
4. 如果快捷键无法正常使用,你可以使用其他软件或者系统自带的截图工具 “Win + Shift + S” 截图,然后在托盘使用右键菜单 “识别剪贴板” 来进行 OCR 识别。
5. 你可以将图片拖放到左边空白区域来识别。
6. 复制图片文件后,也可以在托盘使用右键菜单 “识别剪贴板” 来进行 OCR 识别。
66 changes: 32 additions & 34 deletions Snipping_OCR/Main.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using PaddleOCRSharp;
using Snipping_OCR;
using System.Diagnostics;
using System.Security.Policy;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
using System.Drawing.Imaging;

namespace Snipping_OCR
{
Expand All @@ -14,6 +12,9 @@ public Main()
InitializeComponent();
}

private PaddleOCREngine engine;


/// <summary>
/// 覆写窗体消息
/// </summary>
Expand All @@ -31,16 +32,21 @@ protected override void WndProc(ref Message m)
/// <param name="e"></param>
private void Main_Load(object sender, EventArgs e)
{
//注册热键 Ctrl+ALT+A 截图
//注册热键 Ctrl+TAB 截图
try
{
Hotkey.Regist(base.Handle, HotkeyModifiers.MOD_CONTROL_ALT, Keys.A, new Hotkey.HotKeyCallBackHanlder(StartCapture));
Hotkey.Regist(base.Handle, HotkeyModifiers.MOD_CONTROL, Keys.Tab, new Hotkey.HotKeyCallBackHanlder(StartCapture));
}
catch
{
notifyIcon.ShowBalloonTip(2, "屏幕 OCR", "热键注册失败,您仍可以使用其他方式执行 OCR。",ToolTipIcon.Info);
}


OCRParameter oCRParameter = new()
{
use_gpu = true,
};
engine = new(null, oCRParameter);
}

/// <summary>
Expand Down Expand Up @@ -82,15 +88,6 @@ private void StartCapture()
snippingToolProcess.EnableRaisingEvents = true;
snippingToolProcess.Exited += SnippingToolProcess_Exited;

/*
Process snippingToolProcess = new Process()
{
StartInfo = new ProcessStartInfo("C:\\Windows\\system32\\SnippingTool.exe", "/clip"),
EnableRaisingEvents = true,
};
snippingToolProcess.Exited += SnippingToolProcess_Exited;
snippingToolProcess.Start();
*/
}

/// <summary>
Expand All @@ -100,7 +97,6 @@ private void StartCapture()
/// <param name="e"></param>
private void SnippingToolProcess_Exited(object? sender, EventArgs e)
{
Debug.WriteLine("触发了已经");
this.BeginInvoke(new Action(() =>
{
ClipboardOCR();
Expand Down Expand Up @@ -176,27 +172,29 @@ private void sqPhoto_DragEnter(object sender, DragEventArgs e)
/// <param name="imgfile"></param>
private void showFileOcr(Image imgfile)
{
new Task(() =>
//识别结果对象
var ocrResult = new OCRResult();
ocrResult = engine.DetectText(ImageToBytes(imgfile));
var txt = "";
if (ocrResult.TextBlocks.Count > 0)
{
//识别结果对象
var ocrResult = new OCRResult();
using PaddleOCREngine engine = new PaddleOCREngine(null, new OCRParameter());
ocrResult = engine.DetectText(imgfile);
var txt = "";
if (ocrResult.TextBlocks.Count > 0)
foreach (var item in ocrResult.TextBlocks)
{
foreach (var item in ocrResult.TextBlocks)
{
txt += item.Text + "\r\n";
}
txt += item.Text + "\r\n";
}
this.BeginInvoke(new Action(() =>
{
if (!string.IsNullOrEmpty(txt) && txt != textOCR.Text) textOCR.Text = txt;
textOCR.Cursor = Cursors.IBeam;
}));

}).Start();
}
this.BeginInvoke(new Action(() =>
{
if (!string.IsNullOrEmpty(txt) && txt != textOCR.Text) textOCR.Text = txt;
textOCR.Cursor = Cursors.IBeam;
}));
}

private byte[] ImageToBytes(Image img)
{
MemoryStream ms = new MemoryStream();
img.Save(ms, ImageFormat.Jpeg);
return ms.ToArray();
}

/// <summary>
Expand Down
7 changes: 4 additions & 3 deletions Snipping_OCR/Snipping_OCR.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFrameworks>net6.0-windows;net7.0-windows</TargetFrameworks>
<TargetFrameworks>net8.0-windows10.0.17763.0</TargetFrameworks>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
<Platforms>AnyCPU;x64</Platforms>
<ApplicationIcon>favicon.ico</ApplicationIcon>
<Version>1.0.1</Version>
<Version>1.1.2</Version>
<Authors>SangSQ(桑世强)</Authors>
</PropertyGroup>

Expand All @@ -17,13 +17,14 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="PaddleOCRSharp" Version="2.2.0" />
<PackageReference Include="PaddleOCRSharp" Version="4.1.0" />
<PackageReference Include="SQPhoto" Version="1.0.2" />
</ItemGroup>

<ItemGroup>
<Folder Include="..\doc\" />
<None Include="..\README.md" Link="doc\README.md" />
<None Include="..\README_zh.md" Link="doc\README_zh.md" />
<None Include="..\LICENSE.txt" Link="doc\LICENSE.txt" />
</ItemGroup>

Expand Down

0 comments on commit 57a9122

Please sign in to comment.