70 lines
2.0 KiB
Python
Raw Normal View History

2024-04-02 15:36:52 +08:00
from ctypes import (
c_uint,
c_bool,
POINTER,
c_wchar_p,
pointer,
CDLL,
2024-05-16 19:55:36 +08:00
c_size_t,
2024-04-02 15:36:52 +08:00
Structure,
c_void_p,
)
import platform, gobject
2024-01-08 23:37:00 +08:00
2024-04-02 15:36:52 +08:00
try:
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
2024-01-08 23:37:00 +08:00
class ocrres(Structure):
2024-04-02 15:36:52 +08:00
_fields_ = [
("lines", POINTER(c_wchar_p)),
("xs", POINTER(c_uint)),
("ys", POINTER(c_uint)),
("xs2", POINTER(c_uint)),
("ys2", POINTER(c_uint)),
2024-01-08 23:37:00 +08:00
]
2024-04-02 15:36:52 +08:00
_OCR_f = winrtutilsdll.OCR
2024-05-16 19:55:36 +08:00
_OCR_f.argtypes = c_void_p, c_size_t, c_wchar_p, c_wchar_p, POINTER(c_uint)
2024-04-02 15:36:52 +08:00
_OCR_f.restype = ocrres
_freeocrres = winrtutilsdll.freeocrres
_freeocrres.argtypes = ocrres, c_uint
_freewstringlist = winrtutilsdll.freewstringlist
_freewstringlist.argtypes = POINTER(c_wchar_p), c_uint
_check_language_valid = winrtutilsdll.check_language_valid
_check_language_valid.argtypes = (c_wchar_p,)
_check_language_valid.restype = c_bool
_getlanguagelist = winrtutilsdll.getlanguagelist
_getlanguagelist.argtypes = (POINTER(c_uint),)
_getlanguagelist.restype = POINTER(c_wchar_p)
2024-01-08 23:37:00 +08:00
def getlanguagelist():
2024-04-02 15:36:52 +08:00
num = c_uint()
ret = _getlanguagelist(pointer(num))
_allsupport = []
2024-01-08 23:37:00 +08:00
for i in range(num.value):
_allsupport.append(ret[i])
2024-04-02 15:36:52 +08:00
_freewstringlist(ret, num.value)
2024-01-08 23:37:00 +08:00
return _allsupport
2024-05-16 19:55:36 +08:00
def OCR_f(data, lang, space):
2024-04-02 15:36:52 +08:00
num = c_uint()
2024-05-16 19:55:36 +08:00
ret = _OCR_f(data, len(data), lang, space, pointer(num))
2024-04-02 15:36:52 +08:00
res = []
for i in range(num.value):
2024-01-08 23:37:00 +08:00
res.append((ret.lines[i], ret.xs[i], ret.ys[i], ret.xs2[i], ret.ys2[i]))
2024-04-02 15:36:52 +08:00
_freeocrres(ret, num.value)
2024-01-08 23:37:00 +08:00
return res
2024-04-02 15:36:52 +08:00
_winrt_capture_window = winrtutilsdll.winrt_capture_window
_winrt_capture_window.argtypes = c_wchar_p, c_void_p