问题搜索:根据定位截图OCR历遍题库返回

#NoEnv
#NoTrayIcon
SetBatchLines, -1
Process , Priority, , High
;以下的库自己微调
#Include,Class_bdocr.ahk
#Include,JSON.ahk
#Include,Gdip_all.ahk
#Include,FindText - 8.5.ahk
; --------------------------   Run as Administrator   --------------------------
full_command_line := DllCall("GetCommandLine", "str")

If not (A_IsAdmin or RegExMatch(full_command_line, " /restart(?!\S)"))
{
    Try
    {
        If A_IsCompiled
            Run *RunAs "%A_ScriptFullPath%" /restart
        Else
            Run *RunAs "%A_AhkPath%" /restart "%A_ScriptFullPath%"
    }
    ExitApp
}
; ------------------------------------------------------------------------------
;判定是否有题库,如果没有,则下载题库
if !FileExist("c:\****.json")
{
    UrlDownloadToFile, https://****.json, c:\****.json
}
;判断是否有配置文件
if !FileExist("DIR.ini")
{
    Text:="[DIR]`nAPI_KEY=`nSECRET_KEY=`n茶话会问题高度=40`n茶话会问题宽度=531"
    FileAppend , %Text%, DIR.ini, UTF-8
    MsgBox, 申请百度OCR【高精度接口】`n如有需要,请微调配置文件的【问题识别宽度】和【问题识别高度】
    run,https://www.bilibili.com/video/av53888416/
}

查询(question)
Return


;================================================================================
F1::Reload
F8::ExitApp
F12::
    ToolTip
    MsgBox, 申请百度OCR【高精度接口】`n如有需要,请微调配置文件的【问题识别宽度】和【问题识别高度】
    run,https://www.bilibili.com/video/av53888416/
Return



;================================================================================
查询(关键字)
{
    ;=====指定区域截图识别出问题question=====
    WinGetPos, X, Y, Width, Height, *****
    IniRead, API_KEY,DIR.ini, DIR, API_KEY
    IniRead, SECRET_KEY,DIR.ini, DIR, SECRET_KEY
    IniRead, 茶话会问题宽度,DIR.ini, DIR, 茶话会问题宽度
    IniRead, 茶话会问题高度,DIR.ini, DIR, 茶话会问题高度
    ocr:=new bdocr(API_KEY, SECRET_KEY)
    loop,
    {
        ;用findtext找到定位点
        Text:="|<>*126$9.zbkyDlq4MVk70810sSb7lyDly7sU"
        if(ok:=FindText(X, Y, X + Width, Y + Height, 0.2, 0.2, Text))
        {
            dX:= ok.1.x,dY:= ok.1.y
            X:= dX - 205,Y:= dY + 13
        ;通过定位点确定截图区域
            Area:= X "|" Y "|" 茶话会问题宽度 "|" 茶话会问题高度
            question:=
            pToken := Gdip_Startup()
            pBitmap := Gdip_BitmapFromScreen(Area)
            ;通过上述截图OCR得出问题
            ret:=ocr.GetOcr(pBitmap,"accurate_basic")	; 高精度识别
            for k,v in JSON.Load(ret).words_result
            {
                question.=v.words "`r`n"
            }

            ;=====指定区域截图识别出问题question=====
            FileEncoding UTF-8
            FileRead, json, c:\fhl.json
            ;====================================
            ;分出十五人题库和五人题库
            ov:= StrSplit(json, "]`,""a5"":[")
            a10:=ov[1]
            a5:=ov[2]
            ;处理十五人题库,格式化json
            a10:=StrReplace(a10, """a"":[1,2,3,4,5,6,7,8,9,10]`,")
            a10:=StrReplace(a10, """a10""`:[{")
            ;处理五人题库,格式化json
            a5:=StrReplace(a5, """a""`:[1,2,3,4,5],")

            question:= StrReplace(question, ",")
            ;question:= StrReplace(关键字, ",")
            question:= StrReplace(question, "`,")
            question:= StrReplace(question, "?")
            question:= StrReplace(question, "?")
            question:= StrReplace(question, "“")
            question:= StrReplace(question, "”")
            question:= StrReplace(question, "`r`n")
            关键字:=question
            loop,% StrLen(关键字)
            {
                lalala.="[" SubStr(关键字, A_Index, 1) "]" ; "*" 
            }

            ;=====根据关键字,历遍出15人茶话会答案
            a10:=StrSplit(StrReplace(StrReplace(StrReplace(StrReplace(StrReplace(a10, """"), "c"), "q"), "["), "]"),",","{}:}")
            i:=1
            loop,61
            {
                i:= i + 9
                loop,10
                {
                    StringLeft, answerbf, % a10[i], 3
                    answer:= answerbf "、" answer
                    i-=1
                } 
                StringTrimRight, answer, % answer, 1
                ;answer:= % a10[i + 15] "`n" answer
                question:=a10[i + 15]
                question:= StrReplace(question, ",")
                question:= StrReplace(question, "`,")
                question:= StrReplace(question, "?")
                question:= StrReplace(question, "?")
                question:= StrReplace(question, "“")
                question:= StrReplace(question, "”")
                If (RegExMatch(question, lalala)<>0)
                {
                    LV_Add("",answer,question)
                    answera:=answer
                    questiona:=question
                }
                i:=i+16
                answer:=""
                ;举例:a10.15为问题,a10.1-a10.10均为答案
            }
            text:= questiona "`n" answera "`n下一题:F1`n告诉队友:团队频道按Ctrl+V`n退出:F8`n帮助:F12"
            ;在客户端问题下方显示答案
            CoordMode, ToolTip, Screen
            tooltip,%text%,dX-160,dY+60
            ;将答案copy到剪贴板
            Clipboard:= answera
            ;Break
        }
    }
    Gdip_DisposeImage(pBitmap)
    Gdip_Shutdown(pToken)
    ;return,answera
}
;================================================================================
;拓展性思考,继续通过定位截图OCR的方法,确定每个答案精确坐标,然后完成后续操作,或点击,或_____________

给TA捐赠
共{{data.count}}人
人已捐赠
其他

微博发博数提取

2021-12-2 16:12:37

其他

无需按快捷键自动置顶窗口

2021-12-2 16:16:08

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索