; creates a click-and-drag selection box to specify an area
getSelectionCoords(ByRef x_start, ByRef x_end, ByRef y_start, ByRef y_end) {
;Mask Screen
Gui, Color, FFFFFF
Gui +LastFound
WinSet, Transparent, 75
Gui, -Caption
Gui, +AlwaysOnTop
Gui, Show, x0 y0 h%A_ScreenHeight% w%A_ScreenWidth%,"AutoHotkeySnapshotApp"
;Drag Mouse
CoordMode, Mouse, Screen
CoordMode, Tooltip, Screen
WinGet, hw_frame_m,ID,"AutoHotkeySnapshotApp"
hdc_frame_m := DllCall( "GetDC", "uint", hw_frame_m)
KeyWait, LButton, D
MouseGetPos, scan_x_start, scan_y_start
Loop
{
Sleep, 10
KeyIsDown := GetKeyState("LButton")
if (KeyIsDown = 1)
{
MouseGetPos, scan_x, scan_y
DllCall( "gdi32.dll\Rectangle", "uint", hdc_frame_m, "int", 0,"int",0,"int", A_ScreenWidth,"int",A_ScreenWidth)
DllCall( "gdi32.dll\Rectangle", "uint", hdc_frame_m, "int", scan_x_start,"int",scan_y_start,"int", scan_x,"int",scan_y)
} else {
break
}
}
;KeyWait, LButton, U
MouseGetPos, scan_x_end, scan_y_end
Gui Destroy
if(scan_x_start!=scan_x_end || scan_y_start!=scan_y_end) {
if (scan_x_start < scan_x_end)
{
x_start := scan_x_start
x_end := scan_x_end
} else {
x_start := scan_x_end
x_end := scan_x_start
}
if (scan_y_start < scan_y_end)
{
y_start := scan_y_start
y_end := scan_y_end
} else {
y_start := scan_y_end
y_end := scan_y_start
}
}
}
#Include D:\Code\FigureOut\chrome\extesions\AutoHotKey\PaddleOCR\PaddleOCR.ahk
RunOCR(){
getSelectionCoords(x_start, x_end, y_start, y_end)
; RunWait, D:\software\Capture2Text_v4.6.3_64bit\Capture2Text.exe --screen-rect "%x_start% %y_start% %x_end% %y_end%" --clipboard
; MsgBox, In area :: --screen-rect "%x_start% %y_start% %x_end% %y_end%" `n`nFound Text:`n`n%clipboard%
global MyText
MyText := PaddleOCR([x_start, y_start, x_end-x_start, y_end-y_start])
;tmp := "In area :: --screen-rect """ . x_start . " " . y_start . " " . x_end . " " . y_end . """`n`nFound Text:`n`n" . clipboard
tmp := "In area :: --screen-rect """ . x_start . " " . y_start . " " . x_end . " " . y_end . """`n`nFound Text:`n`n" . MyText
; MsgBox, %vMyText%
Try {
Gui, MyGui:Font, s24
Gui, MyGui:Add, Edit, vMyText, %tmp%
}
GuiControl,MyGui:,MyText,%tmp%
Gui, MyGui:Show
}
首先要下载 PaddleOCR-Autohotkey,在github,最近更新时间是2022年。PaddleOCR 比 capture2text 更精准,但是截取的框不能过大,否则耗时比较多。识别八个汉字秒出。
很好的引擎。但是字一多就变慢了,和手机上的 tesseract 差不多。。。下次再更换个 tesseract 引擎试试,应该更小更快!