fix: 修复 test_subtitle_frame 切片比例(10%->1%) 和 test_ratio_ok_but_max_brightness_too_low 断言(适配阈值240)

This commit is contained in:
simonkoson
2026-06-15 12:13:58 +08:00
parent 7470dbb0ed
commit 487877fa08
+6 -5
View File
@@ -163,7 +163,7 @@ class TestIsBlankFrame:
img_path = tmp_path / "subtitle.png"
arr = np.zeros((100, 100), dtype=np.uint8)
# 1% 白像素(亮度255),其余黑(亮度0)
arr[:100, :10] = 255
arr[:10, :10] = 255 # 10×10=100/10000=1%
img = Image.fromarray(arr, mode="L")
img.save(img_path)
@@ -189,17 +189,18 @@ class TestIsBlankFrame:
assert white_ratio < 0.005
def test_ratio_ok_but_max_brightness_too_low(self, tmp_path):
"""white_ratio>=0.005 但 max_brightness<240 → is_blank=True"""
"""max_brightness<240 → 白像素计数全为0 → is_blank=True"""
from PIL import Image
import numpy as np
img_path = tmp_path / "dim_pixels.png"
arr = np.zeros((100, 100), dtype=np.uint8)
# 1% 像素亮度=220(不240阈值),其余黑
arr[:100, :10] = 220
# 1% 像素亮度=220(不满足阈值240),其余黑
# is_blank_frame 用 arr > 240 统计白像素,220 全不满足 → white_ratio=0
arr[:10, :10] = 220
img = Image.fromarray(arr, mode="L")
img.save(img_path)
is_blank, white_ratio, max_brightness = is_blank_frame(img_path)
assert is_blank is True
assert max_brightness == 220
assert white_ratio >= 0.005
assert white_ratio == 0.0