下载地址:
需要用大模型也可自行更好模型使用
整合包的主脚本代码片段:
#Requires AutoHotkey v2.0 #include <RapidOcr> #include <wincapture> #include <CGdip> ; #include <Gdip_All> rpd_orc := RapidOcr() dxcp := wincapture.DXGI() CGdip.Startup() ; 从图片识别 rtn := rpd_orc.ocr_from_file(A_ScriptDir '\test.png') MsgBox(rtn) ; 从屏幕识别 CGdip.Startup() bitmap := CGdip.Bitmap.FromScreen() bb := BitmapBuffer.loadGpBitmap(bitmap) rtn := rpd_orc.ocr_from_bitmapdata(bb.info) MsgBox(rtn) CGdip.Shutdown() ; 从内存图片识别 fo := FileOpen(A_ScriptDir '/test.png', "r") raw_data := Buffer(1024000) fo.RawRead(raw_data) rtn := rpd_orc.ocr_from_binary(raw_data, raw_data.Size) MsgBox(rtn) fo.Close() ; 从屏幕指定位置识别 GetRange(&x, &y, &w, &h) MsgBox(x " " y " " w " " h) bitmap := CGdip.Bitmap.FromScreen() bb := BitmapBuffer.loadGpBitmap(bitmap) bb := bb.range(x, y, x + w, y + h, true) rtn := rpd_orc.ocr_from_bitmapdata(bb.info) MsgBox(rtn) ; 清理 CGdip.Shutdown() ; 依赖函数 ; 左键拖动选择范围 GetRange(&x, &y, &w, &h) { CoordMode "Mouse", "Screen" GetRange_begin := true loop { ToolTip("请按下鼠标左键") sleep(50) if(GetKeyState("Esc")) { ToolTip return false } }until (GetKeyState("LButton")) while GetKeyState("LButton") { if(GetRange_begin) { GetRange_begin := !GetRange_begin MouseGetPos( &begin_x, &begin_y) } MouseGetPos &now_x, &now_y ToolTip begin_x ", " begin_y "`n" Abs(begin_x-now_x) " x " Abs(begin_y-now_y) HighlightOutline(begin_x, begin_y, now_x, now_y,,,,50) Sleep 10 } x := begin_x, y := begin_y, w := Abs(begin_x-now_x), h := Abs(begin_y-now_y) ToolTip return true } class HighlightOutline { gui := [] __New(x1, y1, x2, y2, b := 3,color := "red", Transparent := 255, time_out := unset) { this.gui.Length := 4 Loop 4 { this.gui[A_index] := Gui("-Caption +AlwaysOnTop +ToolWindow -DPIScale +E0x20 +E0x00080000") this.gui[A_index].BackColor := color DllCall("SetLayeredWindowAttributes", "Ptr", this.gui[A_index].hwnd, "Uint", 0, "Uchar", Transparent, "int", 2) } if(IsSet(time_out)) { this.timer := ObjBindMethod(this, "Destroy") this.Show(x1, y1, x2, y2) SetTimer(this.timer, -time_out) } } Show(x1, y1, x2, y2, b := 3) { Try { this.gui[1].Show("NA x" x1-b " y" y1-b " w" x2-x1+b*2 " h" b) this.gui[2].show("NA x" x2 " y" y1 " w" b " h" y2-y1) this.gui[3].Show("NA x" x1-b " y" y2 " w" x2-x1+2*b " h" b) this.gui[4].Show("NA x" x1-b " y" y1 " w" b " h" y2-y1) } } Hide() { Loop(4) { try { this.gui[A_Index].Hide() } } } Destroy() { this.timer := 0 Loop(4) { try { this.gui[A_Index].Destroy() } } } }
声明:站内资源为整理优化好的代码上传分享与学习研究,如果是开源代码基本都会标明出处,方便大家扩展学习路径。请不要恶意搬运,破坏站长辛苦整理维护的劳动成果。本站为爱好者分享站点,所有内容不作为商业行为。如若本站上传内容侵犯了原著者的合法权益,请联系我们进行删除下架。
评论(0)