-
Notifications
You must be signed in to change notification settings - Fork 139
/
Copy pathdemo.ps1
59 lines (57 loc) · 2.19 KB
/
demo.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
Import-Module -Force ".\PPOCR_api.ps1" #修改对应路径
# 初始化识别器对象,传入 PaddleOCR_json.exe 的路径
$exePath = Convert-Path ".\PaddleOCR-json_v.1.3.0_alpha.2\PaddleOCR-json.exe" #修改对应exe路径
$arg = "" #参数其实在API内没处理
$ocr = [PPOCR]::new($exePath,$arg)
while (1) {
$prompt_str = "1:图片路径`n2:图片Base64`n3:图片Byte`n"
if ( $ocr.isClipboardEnabled() ) {
$prompt_str += "4:剪贴板`n"
}
$prompt_str += "其他则退出"
$选择 = Read-Host $prompt_str
switch($选择){
1{
# 识别图片
$imgPath = read-host "请输入图片路径"
if ($imgPath) {
$getObj = $ocr.run($imgPath)
Write-Host "图片识别完毕,状态码:$($getObj.'code') 结果:`n$($getObj.'data'|Out-String)`n"
}
}
2{
$path = read-host "请输入图片路径,自动转换BASE64"
$imgBase64 = [convert]::ToBase64String([System.IO.FIle]::ReadAllBytes($path))
if ($imgBase64) {
$getObj = $ocr.runBase64($imgBase64)
Write-Host "图片识别完毕,状态码:$($getObj.'code') 结果:`n$($getObj.'data'|Out-String)`n"
}
}
3{
$path = read-host "请输入图片路径,自动转换Byte"
$imgByte = [System.IO.FIle]::ReadAllBytes($path)
if ($imgByte) {
$getObj = $ocr.runByte($imgByte)
Write-Host "图片识别完毕,状态码:$($getObj.'code') 结果:`n$($getObj.'data'|Out-String)`n"
}
}
# 以下示例默认禁用
4{
if ( $ocr.isClipboardEnabled() ) {
$getObj = $ocr.runClipboard()
Write-Host "图片识别完毕,状态码:$($getObj.'code') 结果:`n$($getObj.'data'|Out-String)`n"
}
else {
$ocr.stop() # 结束子进程。
Write-Host "程序结束。"
Exit
}
}
Default
{
$ocr.stop() # 结束子进程。
Write-Host "程序结束。"
Exit
}
}
}