From c1bf835e2fd60fecde9f73a6d10c25dc4bbc6b8d Mon Sep 17 00:00:00 2001 From: Victor Kuznetsov Date: Sat, 5 Sep 2026 13:43:00 -0700 Subject: [PATCH] Fix Kling video detection across decoders --- src/remove_ai_watermarks/video_visible.py | 2 +- tests/test_video.py | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/remove_ai_watermarks/video_visible.py b/src/remove_ai_watermarks/video_visible.py index 1ee8c98..a96c01f 100644 --- a/src/remove_ai_watermarks/video_visible.py +++ b/src/remove_ai_watermarks/video_visible.py @@ -803,7 +803,7 @@ def detect_kling_frame( and logo_x is not None ): font_x, _, font_width, _ = font_candidate.region - if logo_x <= font_x + round(font_width * 0.50): + if font_x - round(font_width * 0.08) <= logo_x <= font_x + round(font_width * 0.50): best = logo_candidate if best is None or best.region is None: return FrameLocalization(frame_index, 0.0, None) diff --git a/tests/test_video.py b/tests/test_video.py index e51125c..0a7d409 100644 --- a/tests/test_video.py +++ b/tests/test_video.py @@ -1745,6 +1745,27 @@ class TestAdditionalProviderFrameLocalization: assert detection.confidence == 0.0 assert detection.region is None + def test_ignores_a_logo_candidate_left_of_the_wordmark(self, monkeypatch: pytest.MonkeyPatch): + from remove_ai_watermarks import video_visible + from remove_ai_watermarks.video_visible import FrameLocalization, detect_kling_frame + + frame = np.zeros((720, 1280, 3), dtype=np.uint8) + frame[670:706, 1120:1280] = 255 + + def fixed_mark(_frame, template_key, *, frame_index, **_kwargs): + if template_key == "kling-3": + return FrameLocalization(frame_index, 0.63, (1156, 678, 60, 20)) + if template_key == "kling-logo": + return FrameLocalization(frame_index, 0.55, (900, 680, 20, 20)) + return FrameLocalization(frame_index, 0.0, None) + + monkeypatch.setattr(video_visible, "_detect_fixed_mark", fixed_mark) + + detection = detect_kling_frame(frame) + + assert detection.region == (1120, 670, 160, 36) + assert detection.confidence == 0.63 + class TestSoraTemporalArbiter: _BOX = (40, 60, 150, 54)