From cb33b673297c11b8368e81be8058b79fc80c061d Mon Sep 17 00:00:00 2001 From: tfarcraw <123211521@163.com> Date: Sun, 8 Nov 2026 21:41:04 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=87=E7=BA=A7=EF=BC=9A=E5=B0=86=E8=B7=A8?= =?UTF-8?q?=E5=B9=B3=E5=8F=B0=E5=9B=BE=E5=83=8F=E4=BE=9D=E8=B5=96=E8=BF=81?= =?UTF-8?q?=E7=A7=BB=E5=88=B0=20OpenCvSharp=205?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 ++ .../SopHelper.CrossPlatform.Engine.csproj | 6 +-- tests/OpenCv.Smoke/OpenCv.Smoke.csproj | 4 ++ tests/OpenCv.Smoke/Program.cs | 42 +++++++++++++++++++ 4 files changed, 53 insertions(+), 3 deletions(-) create mode 100644 tests/OpenCv.Smoke/OpenCv.Smoke.csproj create mode 100644 tests/OpenCv.Smoke/Program.cs diff --git a/README.md b/README.md index 7b48737..9f29e54 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,9 @@ pwsh -File tools/Publish-Avalonia.ps1 `artifacts/avalonia/linux-x64/SopHelper.Avalonia`。 两个平台使用同一套视图、ViewModel 和业务代码,仅供应商 SDK 绑定及原生运行库不同。 +图像依赖统一使用 OpenCvSharp5 `5.0.0.20261107`,Windows 和 Linux 配套原生包使用相同版本, +实际加载 OpenCV 5.0.0。项目保持 .NET 8,现有相机、预览和检测调用通过迁移验证。 + Windows Python 环境使用 `tools/Setup-Python.ps1 -Sam2`;Linux 环境和部署见 [LINUX.md](LINUX.md)。 发布脚本会携带 Windows 的仓库 Python 运行时,Linux 需建立对应平台环境。 @@ -51,6 +54,7 @@ Windows Python 环境使用 `tools/Setup-Python.ps1 -Sam2`;Linux 环境和部 ```powershell dotnet run --project tests/Avalonia.Smoke -c Release +dotnet run --project tests/OpenCv.Smoke -c Release dotnet run --project tests/HandednessSmoke -c Release dotnet run --project tests/Training.Smoke -c Release -- python/python.exe dotnet run --project tests/YoloModelSmoke -c Release -- models/yolo11n.onnx diff --git a/src/SopHelper.CrossPlatform.Engine/SopHelper.CrossPlatform.Engine.csproj b/src/SopHelper.CrossPlatform.Engine/SopHelper.CrossPlatform.Engine.csproj index d5e0bd5..882d943 100644 --- a/src/SopHelper.CrossPlatform.Engine/SopHelper.CrossPlatform.Engine.csproj +++ b/src/SopHelper.CrossPlatform.Engine/SopHelper.CrossPlatform.Engine.csproj @@ -13,9 +13,9 @@ $(MvsManagedSdk)true - - - + + + diff --git a/tests/OpenCv.Smoke/OpenCv.Smoke.csproj b/tests/OpenCv.Smoke/OpenCv.Smoke.csproj new file mode 100644 index 0000000..5716f4b --- /dev/null +++ b/tests/OpenCv.Smoke/OpenCv.Smoke.csproj @@ -0,0 +1,4 @@ + + Exenet8.0enableenable + + diff --git a/tests/OpenCv.Smoke/Program.cs b/tests/OpenCv.Smoke/Program.cs new file mode 100644 index 0000000..a11f611 --- /dev/null +++ b/tests/OpenCv.Smoke/Program.cs @@ -0,0 +1,42 @@ +using OpenCvSharp; +using SopHelper.Engine.Camera; + +var version = Cv2.GetVersionString() ?? throw new Exception("OpenCV did not report its native version"); +if (!version.StartsWith("5.", StringComparison.Ordinal)) throw new Exception("Loaded an unexpected OpenCV runtime: " + version); +Console.WriteLine("PASS: OpenCV " + version + " native runtime loaded"); + +var directory = Path.GetFullPath("artifacts/opencv-smoke"); +using var recorder = new VideoRecorder(); +using var frame = new Mat(240, 320, MatType.CV_8UC3, new Scalar(10, 30, 220)); +var path = recorder.Start(directory, frame, 30); +await Task.Delay(80); +frame.SetTo(new Scalar(20, 180, 40)); +recorder.Write(frame); +await Task.Delay(80); +var result = recorder.Stop() ?? throw new Exception("Recording did not finalize"); +if (result.Frames < 2 || recorder.IsRecording) throw new Exception("Recording frame pacing or stop failed"); + +using var video = new VideoCapture(path); +if (!video.IsOpened()) throw new Exception("OpenCV could not reopen the recorded MJPEG video"); +using var decoded = new Mat(); +var frames = 0; +Scalar first = default, last = default; +while (video.Read(decoded)) +{ + if (decoded.Width != 320 || decoded.Height != 240 || decoded.Type() != MatType.CV_8UC3) + throw new Exception("Video dimensions or pixel type changed"); + last = Cv2.Mean(decoded); + if (frames++ == 0) first = last; +} +if (frames != result.Frames) throw new Exception($"Recorded {result.Frames} frames but decoded {frames}"); +CheckColor(first, new Scalar(10, 30, 220)); +CheckColor(last, new Scalar(20, 180, 40)); +Console.WriteLine($"PASS: VideoRecorder MJPEG round trip, {frames} frames, 320x240, BGR colors preserved"); +Console.WriteLine("Video: " + path); + +static void CheckColor(Scalar actual, Scalar expected) +{ + // MJPEG is lossy; verify channel order and retained frames with a small codec tolerance. + if (Math.Abs(actual.Val0 - expected.Val0) > 8 || Math.Abs(actual.Val1 - expected.Val1) > 8 || Math.Abs(actual.Val2 - expected.Val2) > 8) + throw new Exception($"Unexpected decoded color: {actual}; expected approximately {expected}"); +}