From 54af738dc170762e9c93156e54d71f181e6576c4 Mon Sep 17 00:00:00 2001 From: tfarcraw <123211521@163.com> Date: Thu, 19 Nov 2026 02:34:44 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=B3=E9=94=AE=E5=B8=A7=E5=8E=BB=E5=86=97?= =?UTF-8?q?=E4=BD=99=E4=BF=9D=E7=95=99=E5=90=8C=E4=BA=AE=E5=BA=A6=E7=9A=84?= =?UTF-8?q?=E7=9E=AC=E6=80=81=E9=A2=9C=E8=89=B2=E5=8F=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Sop/VisualEvidenceSampler.cs | 4 ++-- tests/VisionDecision.Smoke/VisualEvidenceTests.cs | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/SopHelper.CrossPlatform.Engine/Sop/VisualEvidenceSampler.cs b/src/SopHelper.CrossPlatform.Engine/Sop/VisualEvidenceSampler.cs index 6e37499..0e8f195 100644 --- a/src/SopHelper.CrossPlatform.Engine/Sop/VisualEvidenceSampler.cs +++ b/src/SopHelper.CrossPlatform.Engine/Sop/VisualEvidenceSampler.cs @@ -34,11 +34,11 @@ public static class VisualEvidenceSampler if (jpeg.Length < 16) return null; try { - using var image = Cv2.ImDecode(jpeg, ImreadModes.Grayscale); + using var image = Cv2.ImDecode(jpeg, ImreadModes.Color); if (image.Empty()) return null; using var small = new Mat(); Cv2.Resize(image, small, new Size(32, 32), 0, 0, InterpolationFlags.Area); - var signature = new byte[1024]; + var signature = new byte[32 * 32 * 3]; System.Runtime.InteropServices.Marshal.Copy(small.Data, signature, 0, signature.Length); return signature; } diff --git a/tests/VisionDecision.Smoke/VisualEvidenceTests.cs b/tests/VisionDecision.Smoke/VisualEvidenceTests.cs index 8e0ed3e..7985a77 100644 --- a/tests/VisionDecision.Smoke/VisualEvidenceTests.cs +++ b/tests/VisionDecision.Smoke/VisualEvidenceTests.cs @@ -18,6 +18,21 @@ internal static class VisualEvidenceTests foreach (var frame in frames) window.Add(frame); if (!window.Frames.Select(f => f.FrameId).SequenceEqual(new long[] { 0, 1, 3 })) throw new Exception("缓存压缩与请求采样均须保护瞬态关键画面"); + using var blue = new Mat(32, 32, MatType.CV_8UC3, new Scalar(255, 0, 0)); + var baseline = VisionDecisionImage.Encode(blue, null); + using var baselineGray = Cv2.ImDecode(baseline, ImreadModes.Grayscale); + byte[]? colorChange = null; + for (var value = 30; value < 100 && colorChange is null; value++) + { + using var green = new Mat(32, 32, MatType.CV_8UC3, new Scalar(0, value, 0)); + var jpeg = VisionDecisionImage.Encode(green, null); + using var gray = Cv2.ImDecode(jpeg, ImreadModes.Grayscale); + if (Cv2.Mean(gray).Val0 == Cv2.Mean(baselineGray).Val0) colorChange = jpeg; + } + if (colorChange is null) throw new Exception("无法构造同亮度异色回归样本"); + var colors = frames.Select(f => f with { Jpeg = f.FrameId == 1 ? colorChange : baseline }).ToArray(); + if (!VisualEvidenceSampler.Select(colors, 3).Any(f => f.FrameId == 1)) + throw new Exception("同亮度的短暂颜色变化也必须保留,不能只依赖灰度变化"); var many = Enumerable.Range(0, 12).Select(i => new VisionEvidenceFrame(i, DateTime.UnixEpoch.AddSeconds(i), normal, i)).ToArray(); var snapshot = VisualEvidenceSampler.Select(many, 4); if (snapshot.Length != 4 || snapshot[0].FrameId != 0 || snapshot[^1].FrameId != 11 || many.Length != 12)