1
- from _typeshed import Incomplete , StrOrBytesPath , Unused
1
+ from _typeshed import Incomplete , ReadableBuffer , StrOrBytesPath , Unused
2
2
from collections .abc import Callable , Generator
3
3
from typing import NamedTuple , SupportsFloat , TypeVar , overload
4
4
from typing_extensions import Final , ParamSpec , SupportsIndex , TypeAlias
@@ -7,13 +7,9 @@ from PIL import Image
7
7
8
8
_P = ParamSpec ("_P" )
9
9
_R = TypeVar ("_R" )
10
- # TODO: cv2.Mat is not available as a type yet:
11
- # https://github.com/microsoft/python-type-stubs/issues/211
12
- # https://github.com/microsoft/python-type-stubs/tree/main/cv2
13
- # https://github.com/opencv/opencv/pull/20370
14
- # cv2.Mat is just an alias for a numpy NDArray, but can't import that either.
15
- # Because pyscreeze does not declare it as a dependency, stub_uploader won't let it.
16
- _Mat : TypeAlias = Incomplete
10
+ # cv2.typing.MatLike: is an alias for `numpy.ndarray | cv2.mat_wrapper.Mat`, Mat extends ndarray.
11
+ # But can't import either, because pyscreeze does not declare them as dependencies, stub_uploader won't let it.
12
+ _MatLike : TypeAlias = Incomplete
17
13
18
14
useOpenCV : Final [bool ]
19
15
RUNNING_PYTHON_2 : Final = False
@@ -40,21 +36,22 @@ class RGB(NamedTuple):
40
36
class PyScreezeException (Exception ): ...
41
37
class ImageNotFoundException (PyScreezeException ): ...
42
38
43
- # _locateAll_opencv
44
39
def requiresPyGetWindow (wrappedFunction : Callable [_P , _R ]) -> Callable [_P , _R ]: ...
40
+
41
+ # _locateAll_opencv
45
42
@overload
46
43
def locate (
47
- needleImage : str | Image .Image | _Mat ,
48
- haystackImage : str | Image .Image | _Mat ,
44
+ needleImage : str | Image .Image | _MatLike ,
45
+ haystackImage : str | Image .Image | _MatLike ,
49
46
* ,
50
47
grayscale : bool | None = None ,
51
48
limit : Unused = 1 ,
52
49
region : tuple [int , int , int , int ] | None = None ,
53
50
step : int = 1 ,
54
- confidence : SupportsFloat | SupportsIndex | str = 0.999 ,
51
+ confidence : SupportsFloat | SupportsIndex | str | ReadableBuffer = 0.999 ,
55
52
) -> Box | None : ...
56
53
57
- # _locateAll_python / _locateAll_pillow
54
+ # _locateAll_pillow
58
55
@overload
59
56
def locate (
60
57
needleImage : str | Image .Image ,
@@ -70,17 +67,17 @@ def locate(
70
67
# _locateAll_opencv
71
68
@overload
72
69
def locateOnScreen (
73
- image : str | Image .Image | _Mat ,
70
+ image : str | Image .Image | _MatLike ,
74
71
minSearchTime : float = 0 ,
75
72
* ,
76
73
grayscale : bool | None = None ,
77
74
limit : Unused = 1 ,
78
75
region : tuple [int , int , int , int ] | None = None ,
79
76
step : int = 1 ,
80
- confidence : SupportsFloat | SupportsIndex | str = 0.999 ,
77
+ confidence : SupportsFloat | SupportsIndex | str | ReadableBuffer = 0.999 ,
81
78
) -> Box | None : ...
82
79
83
- # _locateAll_python / _locateAll_pillow
80
+ # _locateAll_pillow
84
81
@overload
85
82
def locateOnScreen (
86
83
image : str | Image .Image ,
@@ -96,16 +93,16 @@ def locateOnScreen(
96
93
# _locateAll_opencv
97
94
@overload
98
95
def locateAllOnScreen (
99
- image : str | Image .Image | _Mat ,
96
+ image : str | Image .Image | _MatLike ,
100
97
* ,
101
98
grayscale : bool | None = None ,
102
99
limit : int = 1000 ,
103
100
region : tuple [int , int , int , int ] | None = None ,
104
101
step : int = 1 ,
105
- confidence : SupportsFloat | SupportsIndex | str = 0.999 ,
102
+ confidence : SupportsFloat | SupportsIndex | str | ReadableBuffer = 0.999 ,
106
103
) -> Generator [Box , None , None ]: ...
107
104
108
- # _locateAll_python / _locateAll_pillow
105
+ # _locateAll_pillow
109
106
@overload
110
107
def locateAllOnScreen (
111
108
image : str | Image .Image ,
@@ -120,17 +117,17 @@ def locateAllOnScreen(
120
117
# _locateAll_opencv
121
118
@overload
122
119
def locateCenterOnScreen (
123
- image : str | Image .Image | _Mat ,
120
+ image : str | Image .Image | _MatLike ,
124
121
* ,
125
122
minSearchTime : float ,
126
123
grayscale : bool | None = None ,
127
124
limit : Unused = 1 ,
128
125
region : tuple [int , int , int , int ] | None = None ,
129
126
step : int = 1 ,
130
- confidence : SupportsFloat | SupportsIndex | str = 0.999 ,
127
+ confidence : SupportsFloat | SupportsIndex | str | ReadableBuffer = 0.999 ,
131
128
) -> Point | None : ...
132
129
133
- # _locateAll_python / _locateAll_pillow
130
+ # _locateAll_pillow
134
131
@overload
135
132
def locateCenterOnScreen (
136
133
image : str | Image .Image ,
@@ -142,22 +139,22 @@ def locateCenterOnScreen(
142
139
step : int = 1 ,
143
140
confidence : None = None ,
144
141
) -> Point | None : ...
145
- def locateOnScreenNear (image : str | Image .Image | _Mat , x : int , y : int ) -> Box : ...
146
- def locateCenterOnScreenNear (image : str | Image .Image | _Mat , x : int , y : int ) -> Point | None : ...
142
+ def locateOnScreenNear (image : str | Image .Image | _MatLike , x : int , y : int ) -> Box : ...
143
+ def locateCenterOnScreenNear (image : str | Image .Image | _MatLike , x : int , y : int ) -> Point | None : ...
147
144
148
145
# _locateAll_opencv
149
146
@overload
150
147
def locateOnWindow (
151
- image : str | Image .Image | _Mat ,
148
+ image : str | Image .Image | _MatLike ,
152
149
title : str ,
153
150
* ,
154
151
grayscale : bool | None = None ,
155
152
limit : Unused = 1 ,
156
153
step : int = 1 ,
157
- confidence : SupportsFloat | SupportsIndex | str = 0.999 ,
154
+ confidence : SupportsFloat | SupportsIndex | str | ReadableBuffer = 0.999 ,
158
155
) -> Box | None : ...
159
156
160
- # _locateAll_python / _locateAll_pillow
157
+ # _locateAll_pillow
161
158
@overload
162
159
def locateOnWindow (
163
160
image : str | Image .Image ,
@@ -181,16 +178,16 @@ def screenshot(imageFilename: StrOrBytesPath | None = None, region: tuple[int, i
181
178
# _locateAll_opencv
182
179
@overload
183
180
def locateAll (
184
- needleImage : str | Image .Image | _Mat ,
185
- haystackImage : str | Image .Image | _Mat ,
181
+ needleImage : str | Image .Image | _MatLike ,
182
+ haystackImage : str | Image .Image | _MatLike ,
186
183
grayscale : bool | None = None ,
187
184
limit : int = 1000 ,
188
185
region : tuple [int , int , int , int ] | None = None ,
189
186
step : int = 1 ,
190
- confidence : SupportsFloat | SupportsIndex | str = 0.999 ,
187
+ confidence : SupportsFloat | SupportsIndex | str | ReadableBuffer = 0.999 ,
191
188
) -> Generator [Box , None , None ]: ...
192
189
193
- # _locateAll_python / _locateAll_pillow
190
+ # _locateAll_pillow
194
191
@overload
195
192
def locateAll (
196
193
needleImage : str | Image .Image ,
0 commit comments