MCPcopy Create free account
hub / github.com/Vinyzu/recognizer / handle_single_image

Function handle_single_image

recognizer/components/image_processor.py:115–140  ·  view source on GitHub ↗
(single_image: Union[Path, bytes], area_captcha: bool)

Source from the content-addressed store, hash-verified

113
114
115def handle_single_image(single_image: Union[Path, bytes], area_captcha: bool) -> Tuple[List[bytes], List[Tuple[int, int]]]:
116 if isinstance(single_image, bytes):
117 with suppress(binascii.Error):
118 single_image = base64.b64decode(single_image, validate=True)
119
120 # Image Bytes to Cv2
121 rgba_img = imread(single_image)
122 img = cv2.cvtColor(rgba_img, cv2.COLOR_BGR2RGB)
123
124 # Image Splitting Presuming has white barriers
125 images, coords = get_captcha_fields(img)
126
127 if len(images) == 1:
128 # Turning bytes from get_captcha_fields back to Cv2
129 rgba_img = imread(images[0])
130 img = cv2.cvtColor(rgba_img, cv2.COLOR_BGR2RGB)
131
132 # Either it is just a single image or no white barriers
133 height, width, _ = img.shape
134
135 if height > 200 and width > 200:
136 tiles_amount = 4 if area_captcha else 3
137 images = split_image_into_tiles(img, tiles_amount)
138 coords = calculate_approximated_coords(height // tiles_amount, width // tiles_amount, tiles_amount)
139
140 return images, coords
141
142
143def handle_multiple_images(images: List[bytes]) -> List[cv2.typing.MatLike]:

Callers 1

detectMethod · 0.85

Calls 3

get_captcha_fieldsFunction · 0.85
split_image_into_tilesFunction · 0.85

Tested by

no test coverage detected