标题: [问题求助] powershell调用ddddocr [打印本页]
作者: 小白龙 时间: 2024-11-3 05:37 标题: powershell调用ddddocr
本帖最后由 小白龙 于 2024-11-3 05:39 编辑
刚刚发现一个专门识别验证码的免费开源项目 ddddocr, 开源项目地址如下:
https://github.com/86maid/ddddocr
下载地址如下:
https://github.com/86maid/ddddoc ... pc-windows-msvc.zip
我用命令行把服务启动起来后,然后用powershell调用,但总是识别输出为空,求路过大佬支招, 多谢
下面代码是GPT帮写的,不报错,但是输出为空,截图如下:
- #先手动下面的命令启动服务
- #ddddocr.exe -a 127.0.0.1 -p 9898 --ocr
-
- # 设置服务器地址和图片路径
- $hostUrl = "http://127.0.0.1:9898/ocr/file/text"
- $imagePath = "$PSScriptRoot\test1.png"
-
- # 检查图片文件是否存在
- if (-Not (Test-Path -Path $imagePath)) {
- Write-Output "图片文件未找到: $imagePath"
- return
- }
-
- # 读取图片文件内容
- $fileBytes = [System.IO.File]::ReadAllBytes($imagePath)
-
- # 准备 multipart/form-data 请求
- $boundary = [System.Guid]::NewGuid().ToString()
- $formData = @"
- --$boundary
- Content-Disposition: form-data; name="image"; filename="test.png"
- Content-Type: image/png
-
- $fileBytes
- --$boundary--
- "@
-
- try {
- # 发送 POST 请求
- $response = Invoke-RestMethod -Uri $hostUrl -Method Post -ContentType "multipart/form-data; boundary=$boundary" -Body ([System.Text.Encoding]::UTF8.GetBytes($formData))
- Write-Output "识别结果: $response"
- } catch {
- Write-Output "请求失败,错误信息: $_"
- }
复制代码
作者: 小白龙 时间: 2024-11-4 20:37
试了几乎所有的ai, 都没有搞定, 看来哪里描述不清楚
作者: flashercs 时间: 2024-11-10 13:51
- # 测试 ocr classification
- # ddddocr.exe -a 127.0.0.1 -p 9898 --ocr
- # [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12
- $webclient = New-Object System.Net.WebClient
- $webclient.Encoding = New-Object System.Text.UTF8Encoding -ArgumentList $false
- $dddd_url = 'http://127.0.0.1:9898/ocr/b64/text'
- # $dddd_url = 'http://127.0.0.1:9898/ocr_probability/b64/text'
- Get-ChildItem -Filter captcha*.* -File | ForEach-Object {
- $sjson = ConvertTo-Json @{image = [Convert]::ToBase64String([IO.File]::ReadAllBytes($_.FullName)) } -Compress
- $webclient.Headers.Add('Content-Type', 'application/json')
- $result = $webclient.UploadString($dddd_url, 'Post', $sjson)
- #$webclient.Encoding.GetString($result_bytes)
- $_ | Add-Member -MemberType NoteProperty -Name Captcha -Value $result -PassThru
- } | Format-List -Property Name, Captcha
-
- $webclient.Dispose()
复制代码
欢迎光临 批处理之家 (http://www.bathome.net/) |
Powered by Discuz! 7.2 |