fix: typing annotations for cv2.Mat, see #5

This commit is contained in:
283375 2023-07-07 13:32:44 +08:00
parent e01f6cd6bc
commit 922fed8efe
7 changed files with 16 additions and 8 deletions

View File

@ -1,8 +1,7 @@
from typing import Tuple from typing import Any, Tuple
from cv2 import Mat
from .device import Device from .device import Device
from .types import Mat
__all__ = [ __all__ = [
"crop_img", "crop_img",

View File

@ -1,6 +1,8 @@
from cv2 import BORDER_CONSTANT, BORDER_ISOLATED, Mat, bitwise_or, dilate, inRange from cv2 import BORDER_CONSTANT, BORDER_ISOLATED, bitwise_or, dilate, inRange
from numpy import array, uint8 from numpy import array, uint8
from .types import Mat
__all__ = [ __all__ = [
"GRAY_MIN_HSV", "GRAY_MIN_HSV",
"GRAY_MAX_HSV", "GRAY_MAX_HSV",

View File

@ -5,7 +5,6 @@ from cv2 import (
CHAIN_APPROX_SIMPLE, CHAIN_APPROX_SIMPLE,
RETR_EXTERNAL, RETR_EXTERNAL,
TM_CCOEFF_NORMED, TM_CCOEFF_NORMED,
Mat,
boundingRect, boundingRect,
findContours, findContours,
imshow, imshow,
@ -25,6 +24,7 @@ from .template import (
load_builtin_digit_template, load_builtin_digit_template,
matchTemplateMultiple, matchTemplateMultiple,
) )
from .types import Mat
__all__ = [ __all__ = [
"group_numbers", "group_numbers",

View File

@ -1,12 +1,13 @@
from dataclasses import dataclass from dataclasses import dataclass
from typing import Callable, Optional from typing import Callable, Optional
from cv2 import COLOR_BGR2HSV, GaussianBlur, Mat, cvtColor, imread from cv2 import COLOR_BGR2HSV, GaussianBlur, cvtColor, imread
from .crop import * from .crop import *
from .device import Device from .device import Device
from .mask import * from .mask import *
from .ocr import * from .ocr import *
from .types import Mat
from .utils import imread_unicode from .utils import imread_unicode
__all__ = [ __all__ = [

View File

@ -11,7 +11,6 @@ from cv2 import (
RETR_EXTERNAL, RETR_EXTERNAL,
THRESH_BINARY_INV, THRESH_BINARY_INV,
TM_CCOEFF_NORMED, TM_CCOEFF_NORMED,
Mat,
boundingRect, boundingRect,
cvtColor, cvtColor,
destroyAllWindows, destroyAllWindows,
@ -34,6 +33,7 @@ from ._builtin_templates import (
DEFAULT_REGULAR, DEFAULT_REGULAR,
DEFAULT_REGULAR_ERODED, DEFAULT_REGULAR_ERODED,
) )
from .types import Mat
__all__ = [ __all__ = [
"TemplateItem", "TemplateItem",

View File

@ -0,0 +1,4 @@
import numpy as np
# from pylance
Mat = np.ndarray[int, np.dtype[np.generic]]

View File

@ -1,7 +1,9 @@
from cv2 import IMREAD_UNCHANGED, Mat, imdecode from cv2 import IMREAD_UNCHANGED, imdecode
from numpy import fromfile as np_fromfile from numpy import fromfile as np_fromfile
from numpy import uint8 from numpy import uint8
from .types import Mat
def imread_unicode(filepath: str) -> Mat: def imread_unicode(filepath: str) -> Mat:
# https://stackoverflow.com/a/57872297/16484891 # https://stackoverflow.com/a/57872297/16484891