找回密码
 加入
搜索
查看: 1111|回复: 4

ddddocr

[复制链接]
发表于 2022-12-10 23:29:14 | 显示全部楼层 |阅读模式
本帖最后由 繁星 于 2026-4-4 12:54 编辑
#AutoIt3Wrapper_UseX64 = y
; auddddocr.dll - 已静态编译onnxruntime
; 初始化 OCR:
;   _DDDDOCR_Init($sModelPath, $sCharsetPath) -> 返回句柄,失败返回 0
;   _DDDDOCR_Close($hOcr)
; 识别:
;   _DDDDOCR_Recognize($hOcr, $sImagePath) -> 返回文本,失败时 @error 为错误码 (-1~-4)
;
; 目标检测:
;   _DDDDOCR_Detect_Init($sModelPath) -> 返回句柄
;   _DDDDOCR_Detect_Close($hDet)
;   _DDDDOCR_Detect($hDet, $sImagePath) -> 返回 JSON 字符串,失败时 @error 为错误码
;
; 滑块匹配:
;   _DDDDOCR_SlideMatch($sTargetPath, $sBgPath, $bSimple, ByRef $x, ByRef $y, ByRef $w, ByRef $h) -> 成功返回 True
;   _DDDDOCR_SlideComparison($sTargetPath, $sBgPath, ByRef $x, ByRef $y) -> 成功返回 True
;
; =================================================================================================

Global $__g_hDDDDOCR_DLL = -1

Func __DDDDOCR_LoadDLL()
    If $__g_hDDDDOCR_DLL <> -1 Then Return $__g_hDDDDOCR_DLL
    $__g_hDDDDOCR_DLL = DllOpen("auddddocr.dll")
    Return $__g_hDDDDOCR_DLL
EndFunc

Func _DDDDOCR_UnloadDLL()
    If $__g_hDDDDOCR_DLL <> -1 Then
        DllClose($__g_hDDDDOCR_DLL)
        $__g_hDDDDOCR_DLL = -1
    EndIf
EndFunc

Func _DDDDOCR_Init($sModelPath, $sCharsetPath)
    Local $hDLL = __DDDDOCR_LoadDLL()
    If $hDLL = -1 Then Return 0
    Local $aRet = DllCall($hDLL, "int", "init_ocr", "wstr", $sModelPath, "wstr", $sCharsetPath)
    If @error Then Return 0
    Return $aRet[0]
EndFunc

Func _DDDDOCR_Close($hOcr)
    Local $hDLL = __DDDDOCR_LoadDLL()
    If $hDLL = -1 Then Return
    DllCall($hDLL, "none", "close_ocr", "int", $hOcr)
EndFunc

Func _DDDDOCR_Recognize($hOcr, $sImagePath)
    Local $hDLL = __DDDDOCR_LoadDLL()
    If $hDLL = -1 Then Return SetError(-5, 0, "")
    Local $aNeed = DllCall($hDLL, "int", "ocr_file", "int", $hOcr, "wstr", $sImagePath, "ptr", 0, "int", 0)
    If @error Then Return SetError(-5, 0, "")
    Local $iNeed = $aNeed[0]
    If $iNeed <= 0 Then Return SetError($iNeed, 0, "")
    Local $tBuffer = DllStructCreate("wchar[" & $iNeed & "]")
    Local $aRet = DllCall($hDLL, "int", "ocr_file", "int", $hOcr, "wstr", $sImagePath, "ptr", DllStructGetPtr($tBuffer), "int", $iNeed)
    If @error Then Return SetError(-5, 0, "")
    If $aRet[0] <= 0 Then Return SetError($aRet[0], 0, "")
    Return DllStructGetData($tBuffer, 1)
EndFunc

Func _DDDDOCR_Detect_Init($sModelPath)
    Local $hDLL = __DDDDOCR_LoadDLL()
    If $hDLL = -1 Then Return 0
    Local $aRet = DllCall($hDLL, "int", "init_detection", "wstr", $sModelPath)
    If @error Then Return 0
    Return $aRet[0]
EndFunc

Func _DDDDOCR_Detect_Close($hDet)
    Local $hDLL = __DDDDOCR_LoadDLL()
    If $hDLL = -1 Then Return
    DllCall($hDLL, "none", "close_detection", "int", $hDet)
EndFunc

Func _DDDDOCR_Detect($hDet, $sImagePath)
    Local $hDLL = __DDDDOCR_LoadDLL()
    If $hDLL = -1 Then Return SetError(-5, 0, "")
    Local $aNeed = DllCall($hDLL, "int", "detection_file", "int", $hDet, "wstr", $sImagePath, "ptr", 0, "int", 0)
    If @error Then Return SetError(-5, 0, "")
    Local $iNeed = $aNeed[0]
    If $iNeed <= 0 Then Return SetError($iNeed, 0, "")
    Local $tBuffer = DllStructCreate("wchar[" & $iNeed & "]")
    Local $aRet = DllCall($hDLL, "int", "detection_file", "int", $hDet, "wstr", $sImagePath, "ptr", DllStructGetPtr($tBuffer), "int", $iNeed)
    If @error Then Return SetError(-5, 0, "")
    If $aRet[0] <= 0 Then Return SetError($aRet[0], 0, "")
    Return DllStructGetData($tBuffer, 1)
EndFunc

Func _DDDDOCR_SlideMatch($sTargetPath, $sBgPath, $bSimple, ByRef $x, ByRef $y, ByRef $w, ByRef $h)
    Local $hDLL = __DDDDOCR_LoadDLL()
    If $hDLL = -1 Then Return False
    Local $tX = DllStructCreate("int")
    Local $tY = DllStructCreate("int")
    Local $tW = DllStructCreate("int")
    Local $tH = DllStructCreate("int")
    Local $aRet = DllCall($hDLL, "int", "slide_match_file", _
        "wstr", $sTargetPath, _
        "wstr", $sBgPath, _
        "int", Number($bSimple), _
        "ptr", DllStructGetPtr($tX), _
        "ptr", DllStructGetPtr($tY), _
        "ptr", DllStructGetPtr($tW), _
        "ptr", DllStructGetPtr($tH))
    If @error Or $aRet[0] = 0 Then Return False
    $x = DllStructGetData($tX, 1)
    $y = DllStructGetData($tY, 1)
    $w = DllStructGetData($tW, 1)
    $h = DllStructGetData($tH, 1)
    Return True
EndFunc

Func _DDDDOCR_SlideComparison($sTargetPath, $sBgPath, ByRef $x, ByRef $y)
    Local $hDLL = __DDDDOCR_LoadDLL()
    If $hDLL = -1 Then Return False
    Local $tX = DllStructCreate("int")
    Local $tY = DllStructCreate("int")
    Local $aRet = DllCall($hDLL, "int", "slide_comparison_file", _
        "wstr", $sTargetPath, _
        "wstr", $sBgPath, _
        "ptr", DllStructGetPtr($tX), _
        "ptr", DllStructGetPtr($tY))
    If @error Or $aRet[0] = 0 Then Return False
    $x = DllStructGetData($tX, 1)
    $y = DllStructGetData($tY, 1)
    Return True
EndFunc
https://subtlelonging.lanzoue.com/ic5313mdz74f


评分

参与人数 3金钱 +239 贡献 +25 收起 理由
gapkiller + 60 很给力!
haijie1223 + 99 + 5 很给力!
rikthhpgf2005 + 80 + 20

查看全部评分

发表于 2022-12-11 17:04:21 | 显示全部楼层
很厉害!
经测试,离线版准确率稍低一些
发表于 2022-12-11 20:16:13 | 显示全部楼层
我搭的有在线版
发表于 2022-12-12 09:22:24 | 显示全部楼层
经过留名ing
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2026-7-14 10:20 , Processed in 0.086521 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表