Skip to content

Commit a9a9617

Browse files
committed
Support passing in base64 encoded images
1 parent 2ce6bf2 commit a9a9617

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

HISTORY.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
# 版本历史
2+
1.0.2 (2026-01-28)
3+
* 支持传入base64编码的图片 (Support passing in base64 encoded images)
24

35
1.0.1 (2025-09-29)
46
* 提高默认的置信度阈值 (Improve default confidence threshold)

captcha_recognizer/slider.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import base64
12
import os
23
import random
34
import time
@@ -234,7 +235,13 @@ def draw_segments(image, boxes, masks,
234235

235236
@staticmethod
236237
def image_to_array(source: Union[str, Path, bytes, np.ndarray] = None):
237-
if isinstance(source, (str, Path)):
238+
if isinstance(source, str) and source.startswith('data:image'):
239+
# 从Base64字符串读取
240+
header, encoded = source.split(',', 1)
241+
data = base64.b64decode(encoded)
242+
np_arr = np.frombuffer(data, np.uint8)
243+
return cv2.imdecode(np_arr, cv2.IMREAD_COLOR)
244+
elif isinstance(source, (str, Path)):
238245
# 从文件路径读取
239246
return cv2.imread(str(source))
240247
elif isinstance(source, bytes):
@@ -795,5 +802,8 @@ def non_max_suppression(
795802
单缺口
796803
"""
797804
model = Slider()
805+
# base64 图片测试
806+
# base64_image = 'xxx'
807+
# res = model.identify(source=base64_image, show=True)
798808
res = model.identify(source='img_example.png', show=True)
799809
print('results', res)

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def read_requirements(filename):
1616

1717
setup(
1818
name='captcha-recognizer',
19-
version='1.0.1',
19+
version='1.0.2',
2020
description='滑块验证码识别',
2121
long_description=read_file("README.md") + "\n\n" + read_file("HISTORY.md"),
2222
long_description_content_type="text/markdown",

0 commit comments

Comments
 (0)