2024-04-02 15:36:52 +08:00
|
|
|
|
from ctypes import (
|
|
|
|
|
c_uint,
|
|
|
|
|
c_bool,
|
|
|
|
|
c_wchar_p,
|
|
|
|
|
CDLL,
|
2024-05-16 19:55:36 +08:00
|
|
|
|
c_size_t,
|
2024-07-14 15:09:37 +08:00
|
|
|
|
CFUNCTYPE,
|
2024-04-02 15:36:52 +08:00
|
|
|
|
c_void_p,
|
2024-10-01 22:58:41 +08:00
|
|
|
|
cast,
|
|
|
|
|
POINTER,
|
|
|
|
|
c_char,
|
2024-04-02 15:36:52 +08:00
|
|
|
|
)
|
2024-10-20 00:37:51 +08:00
|
|
|
|
import platform, gobject, threading
|
2024-01-08 23:37:00 +08:00
|
|
|
|
|
2024-04-02 15:36:52 +08:00
|
|
|
|
try:
|
2024-11-05 15:46:45 +08:00
|
|
|
|
if platform.system() != "Windows" or int(platform.version().split(".")[0]) <= 6:
|
2024-01-08 23:37:00 +08:00
|
|
|
|
raise Exception()
|
2024-04-02 15:36:52 +08:00
|
|
|
|
winrtutilsdll = CDLL(gobject.GetDllpath(("winrtutils32.dll", "winrtutils64.dll")))
|
2024-01-08 23:37:00 +08:00
|
|
|
|
except:
|
2024-04-02 15:36:52 +08:00
|
|
|
|
winrtutilsdll = 0
|
|
|
|
|
|
2024-01-08 23:37:00 +08:00
|
|
|
|
if winrtutilsdll:
|
2024-04-02 15:36:52 +08:00
|
|
|
|
|
|
|
|
|
_OCR_f = winrtutilsdll.OCR
|
2024-07-14 15:09:37 +08:00
|
|
|
|
_OCR_f.argtypes = c_void_p, c_size_t, c_wchar_p, c_wchar_p, c_void_p
|
2024-04-02 15:36:52 +08:00
|
|
|
|
|
|
|
|
|
_check_language_valid = winrtutilsdll.check_language_valid
|
|
|
|
|
_check_language_valid.argtypes = (c_wchar_p,)
|
|
|
|
|
_check_language_valid.restype = c_bool
|
|
|
|
|
|
|
|
|
|
_getlanguagelist = winrtutilsdll.getlanguagelist
|
2024-07-14 15:09:37 +08:00
|
|
|
|
_getlanguagelist.argtypes = (c_void_p,)
|
2024-04-02 15:36:52 +08:00
|
|
|
|
|
2024-05-16 19:55:36 +08:00
|
|
|
|
def OCR_f(data, lang, space):
|
2024-07-14 15:09:37 +08:00
|
|
|
|
ret = []
|
|
|
|
|
|
|
|
|
|
def cb(x1, y1, x2, y2, text):
|
|
|
|
|
ret.append((text, x1, y1, x2, y2))
|
|
|
|
|
|
2024-10-20 00:37:51 +08:00
|
|
|
|
t = threading.Thread(
|
|
|
|
|
target=_OCR_f,
|
|
|
|
|
args=(
|
|
|
|
|
data,
|
|
|
|
|
len(data),
|
|
|
|
|
lang,
|
|
|
|
|
space,
|
|
|
|
|
CFUNCTYPE(None, c_uint, c_uint, c_uint, c_uint, c_wchar_p)(cb),
|
|
|
|
|
),
|
2024-07-14 15:09:37 +08:00
|
|
|
|
)
|
2024-10-20 00:37:51 +08:00
|
|
|
|
t.start()
|
|
|
|
|
t.join()
|
|
|
|
|
# 如果不这样,就会在在ui线程执行时,BitmapDecoder::CreateAsync(memoryStream).get()等Async函数会导致阻塞卡住。
|
2024-07-14 15:09:37 +08:00
|
|
|
|
return ret
|
2024-04-02 15:36:52 +08:00
|
|
|
|
|
|
|
|
|
_winrt_capture_window = winrtutilsdll.winrt_capture_window
|
2024-10-01 22:58:41 +08:00
|
|
|
|
_winrt_capture_window.argtypes = c_void_p, c_void_p
|
|
|
|
|
|
|
|
|
|
|
2024-12-24 15:22:04 +08:00
|
|
|
|
def getlanguagelist():
|
|
|
|
|
if not winrtutilsdll:
|
|
|
|
|
return []
|
|
|
|
|
ret = []
|
|
|
|
|
_getlanguagelist(CFUNCTYPE(None, c_wchar_p)(ret.append))
|
|
|
|
|
return ret
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def winrt_capture_window(hwnd):
|
|
|
|
|
if not winrtutilsdll:
|
|
|
|
|
return
|
|
|
|
|
ret = []
|
|
|
|
|
|
|
|
|
|
def cb(ptr, size):
|
|
|
|
|
ret.append(cast(ptr, POINTER(c_char))[:size])
|
2024-10-01 22:58:41 +08:00
|
|
|
|
|
2024-12-24 15:22:04 +08:00
|
|
|
|
_winrt_capture_window(hwnd, CFUNCTYPE(None, c_void_p, c_size_t)(cb))
|
|
|
|
|
if len(ret):
|
|
|
|
|
return ret[0]
|
|
|
|
|
return None
|