From e98b669a7c83400bd1e1cb188bb01129e0d4b6b8 Mon Sep 17 00:00:00 2001
From: sophelper <123211521@163.com>
Date: Thu, 5 Nov 2026 22:18:09 +0800
Subject: [PATCH] =?UTF-8?q?fix:=20=E5=B0=86=E6=89=8B=E9=83=A8=E6=A3=80?=
=?UTF-8?q?=E6=B5=8B=E7=BD=AE=E4=BF=A1=E5=BA=A6=E9=97=A8=E6=A7=9B=E9=99=8D?=
=?UTF-8?q?=E8=87=B340%?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
README.md | 1 +
src/SopHelper.Engine/Inference/MediaPipeHandDetector.cs | 7 +++++--
src/SopHelper.Engine/Pipeline/DetectionPipeline.cs | 3 ++-
tests/HandDetectionSmoke/Program.cs | 4 ++--
4 files changed, 10 insertions(+), 5 deletions(-)
diff --git a/README.md b/README.md
index 602236d..11b85a5 100644
--- a/README.md
+++ b/README.md
@@ -44,6 +44,7 @@ dotnet build SopHelper.slnx
运行时,检测到的手会直接标在视频画面上:21 个关键点与骨架连线,不显示手部外框或文字标签。
标记与 ROI 共用原图坐标,随预览一起缩放;未检测到手或停止采集时清除。
需要 `models/` 中的 palm 与 landmark 两份模型,缺失时日志会提示。
+手掌检测与手部关键点确认的默认置信度门槛均为 40%(界面上的置信度滑块用于 YOLO 目标检测)。
默认支持同帧显示两只手。针对 palm 导出中内置的单手 NMS 限制,加载时仅在内存中
适配候选输出数量,原始模型文件不变;相邻手部去重使用原始手掌框。
diff --git a/src/SopHelper.Engine/Inference/MediaPipeHandDetector.cs b/src/SopHelper.Engine/Inference/MediaPipeHandDetector.cs
index 178bdb9..c95a73c 100644
--- a/src/SopHelper.Engine/Inference/MediaPipeHandDetector.cs
+++ b/src/SopHelper.Engine/Inference/MediaPipeHandDetector.cs
@@ -25,8 +25,11 @@ public class MediaPipeHandDetector : IDisposable
private InferenceSession? _palm;
private InferenceSession? _landmark;
- private float _palmThreshold = 0.5f;
- private float _keypointThreshold = 0.5f;
+ public const float DefaultPalmThreshold = 0.4f;
+ public const float DefaultKeypointThreshold = 0.4f;
+
+ private float _palmThreshold = DefaultPalmThreshold;
+ private float _keypointThreshold = DefaultKeypointThreshold;
private int _maxHands = 2;
/// 模型是否就绪(缺文件时上层跳过手部判定,不报错)
diff --git a/src/SopHelper.Engine/Pipeline/DetectionPipeline.cs b/src/SopHelper.Engine/Pipeline/DetectionPipeline.cs
index 8e9db7d..4f83c99 100644
--- a/src/SopHelper.Engine/Pipeline/DetectionPipeline.cs
+++ b/src/SopHelper.Engine/Pipeline/DetectionPipeline.cs
@@ -105,7 +105,8 @@ public class DetectionPipeline : IDisposable
}
}
- _hand.SetThresholds(0.5f, 0.5f, Math.Max(1, options.MaxHands));
+ _hand.SetThresholds(MediaPipeHandDetector.DefaultPalmThreshold,
+ MediaPipeHandDetector.DefaultKeypointThreshold, Math.Max(1, options.MaxHands));
}
///
diff --git a/tests/HandDetectionSmoke/Program.cs b/tests/HandDetectionSmoke/Program.cs
index 5bdc5a1..7fd4754 100644
--- a/tests/HandDetectionSmoke/Program.cs
+++ b/tests/HandDetectionSmoke/Program.cs
@@ -24,9 +24,9 @@ for (var index = 0; index < 300 && video.Read(frame); index++)
if (!hands.Any(h => h.HandType == HandType.Left) || !hands.Any(h => h.HandType == HandType.Right))
continue;
Console.WriteLine($"PASS: 帧 {index} 同时检出左手和右手,均有 21 个关键点");
- detector.SetThresholds(0.5f, 0.5f, 1);
+ detector.SetThresholds(MediaPipeHandDetector.DefaultPalmThreshold, MediaPipeHandDetector.DefaultKeypointThreshold, 1);
if (detector.Detect(frame).Count != 1) throw new Exception("MaxHands=1 未生效");
- detector.SetThresholds(0.5f, 0.5f, 2);
+ detector.SetThresholds(MediaPipeHandDetector.DefaultPalmThreshold, MediaPipeHandDetector.DefaultKeypointThreshold, 2);
if (detector.Detect(frame).Count != 2) throw new Exception("MaxHands=2 未生效");
Console.WriteLine("PASS: MaxHands=1/2 均生效");
found = true;