|
41 | 41 | MixinDataclassIterable,
|
42 | 42 | Structure,
|
43 | 43 | as_float_array,
|
44 |
| - as_int_array, |
45 | 44 | as_int,
|
| 45 | + as_int_array, |
| 46 | + as_int_scalar, |
46 | 47 | orient,
|
47 | 48 | usage_warning,
|
48 | 49 | )
|
@@ -210,7 +211,7 @@ def swatch_masks(
|
210 | 211 | return tuple(masks)
|
211 | 212 |
|
212 | 213 |
|
213 |
| -def as_8_bit_BGR_image(image: ArrayLike) -> NDArrayFloat: |
| 214 | +def as_8_bit_BGR_image(image: ArrayLike) -> NDArrayInt: |
214 | 215 | """
|
215 | 216 | Convert and encodes given linear float *RGB* image to 8-bit *BGR* with
|
216 | 217 | *sRGB* reverse OETF.
|
@@ -280,7 +281,7 @@ def as_8_bit_BGR_image(image: ArrayLike) -> NDArrayFloat:
|
280 | 281 | if image.dtype == np.uint8:
|
281 | 282 | return image
|
282 | 283 |
|
283 |
| - return cv2.cvtColor( |
| 284 | + return cv2.cvtColor( # pyright: ignore |
284 | 285 | cast(NDArrayFloat, cctf_encoding(image) * 255).astype(np.uint8),
|
285 | 286 | cv2.COLOR_RGB2BGR,
|
286 | 287 | )
|
@@ -346,11 +347,11 @@ def adjust_image(
|
346 | 347 | ratio = width / target_width
|
347 | 348 |
|
348 | 349 | if np.allclose(ratio, 1):
|
349 |
| - return cast(NDArrayFloat, image) |
| 350 | + return image |
350 | 351 | else:
|
351 |
| - return cv2.resize( |
| 352 | + return cv2.resize( # pyright: ignore |
352 | 353 | image,
|
353 |
| - (as_int(target_width), as_int(height / ratio)), |
| 354 | + (as_int_scalar(target_width), as_int_scalar(height / ratio)), |
354 | 355 | interpolation=interpolation_method,
|
355 | 356 | )
|
356 | 357 |
|
@@ -383,7 +384,7 @@ def is_square(contour: ArrayLike, tolerance: float = 0.015) -> bool:
|
383 | 384 |
|
384 | 385 | return (
|
385 | 386 | cv2.matchShapes(
|
386 |
| - contour, |
| 387 | + contour, # pyright: ignore |
387 | 388 | np.array([[0, 0], [1, 0], [1, 1], [0, 1]]),
|
388 | 389 | cv2.CONTOURS_MATCH_I2,
|
389 | 390 | 0.0,
|
@@ -418,7 +419,7 @@ def contour_centroid(contour: ArrayLike) -> Tuple[float, float]:
|
418 | 419 | (0.5, 0.5)
|
419 | 420 | """
|
420 | 421 |
|
421 |
| - moments = cv2.moments(contour) |
| 422 | + moments = cv2.moments(contour) # pyright: ignore |
422 | 423 | centroid = (
|
423 | 424 | moments["m10"] / moments["m00"],
|
424 | 425 | moments["m01"] / moments["m00"],
|
@@ -535,7 +536,7 @@ def crop_and_level_image_with_rectangle(
|
535 | 536 | if image_c.shape[0] > image_c.shape[1]:
|
536 | 537 | image_c = orient(image_c, "90 CW")
|
537 | 538 |
|
538 |
| - return image_c |
| 539 | + return image_c # pyright: ignore |
539 | 540 |
|
540 | 541 |
|
541 | 542 | @dataclass
|
@@ -786,7 +787,10 @@ def colour_checkers_coordinates_segmentation(
|
786 | 787 |
|
787 | 788 | if additional_data:
|
788 | 789 | return DataColourCheckersCoordinatesSegmentation(
|
789 |
| - tuple(colour_checkers), tuple(clusters), tuple(swatches), image_c |
| 790 | + tuple(colour_checkers), |
| 791 | + tuple(clusters), |
| 792 | + tuple(swatches), |
| 793 | + image_c, # pyright: ignore |
790 | 794 | )
|
791 | 795 | else:
|
792 | 796 | return colour_checkers
|
@@ -934,7 +938,9 @@ def extract_colour_checkers_segmentation(
|
934 | 938 | colour_checkers_coordinates_segmentation(image, **settings),
|
935 | 939 | ):
|
936 | 940 | colour_checker = crop_and_level_image_with_rectangle(
|
937 |
| - image, cv2.minAreaRect(rectangle), settings.interpolation_method |
| 941 | + image, |
| 942 | + cv2.minAreaRect(rectangle), # pyright: ignore |
| 943 | + settings.interpolation_method, |
938 | 944 | )
|
939 | 945 | width, height = (colour_checker.shape[1], colour_checker.shape[0])
|
940 | 946 |
|
@@ -974,9 +980,9 @@ def detect_colour_checkers_segmentation(
|
974 | 980 | samples: int = 16,
|
975 | 981 | additional_data: bool = False,
|
976 | 982 | **kwargs: Any,
|
977 |
| -) -> Tuple[DataDetectColourCheckersSegmentation, ...] | Tuple[ |
978 |
| - NDArrayFloat, ... |
979 |
| -]: |
| 983 | +) -> ( |
| 984 | + Tuple[DataDetectColourCheckersSegmentation, ...] | Tuple[NDArrayFloat, ...] |
| 985 | +): |
980 | 986 | """
|
981 | 987 | Detect the colour checkers swatches in given image using segmentation.
|
982 | 988 |
|
|
0 commit comments