关键帧去冗余保留同亮度的瞬态颜色变化

This commit is contained in:
tfarcraw 2026-11-19 02:34:44 +08:00
parent d4650323c3
commit 54af738dc1
2 changed files with 17 additions and 2 deletions

View File

@ -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;
}

View File

@ -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)