Migrate selected camera, branding, handedness and YOLO safeguards to main
This commit is contained in:
parent
6a5bc1a6b4
commit
f3418cd1a8
@ -135,6 +135,12 @@ SOP 页配方行的「编辑 / 新建」。表单式,四个 tab:步骤 / 区
|
||||
"照抄别人的 YAML 拼错一个字母"这种事发生(下拉候选就是 `ConditionMethod` 那几项)。
|
||||
区域改键名会同步更新所有引用它的步骤;删区域会清掉引用。
|
||||
|
||||
“检测模型”页选择普通 YOLO 的 ONNX 文件和对应类别表;类别表留空时可从模型的 `names` 元数据读取。
|
||||
加载时会检查类别数量和输出格式,加载失败会在 SOP 日志提示,切换到缺失模型也会释放旧模型。
|
||||
该页的“相机曝光(μs)”随配方保存到 `sop.settings.exposure_time_us`,例如 10000 表示 10 毫秒。
|
||||
海康相机在区域取图与 SOP 启动前关闭自动曝光并应用该值;留空保留设备设置。UVC 暂不支持微秒曝光设置,请留空。
|
||||
程序启动时自动扫描相机并恢复上次成功使用的设备,主窗口默认最大化。
|
||||
|
||||
区域页支持图像画框标定:
|
||||
|
||||
1. 停止运行,在 SOP 页选好相机,打开「编辑 / 新建」→「区域」。
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
<prism:PrismApplication x:Class="SopHelper.App"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:prism="http://prismlibrary.com/">
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:prism="http://prismlibrary.com/">
|
||||
<prism:PrismApplication.Resources>
|
||||
<ResourceDictionary>
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
|
||||
167
src/SopHelper.App/Assets/BellwetherLogo.xaml
Normal file
167
src/SopHelper.App/Assets/BellwetherLogo.xaml
Normal file
@ -0,0 +1,167 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!-- Vector drawing generated from bws.svg; preserve the SVG as the source asset. -->
|
||||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
||||
<DrawingImage x:Key="BellwetherLogo">
|
||||
<DrawingImage.Drawing>
|
||||
<DrawingGroup>
|
||||
<GeometryDrawing Brush="Transparent" Geometry="M0,0 H380 V120 H0 Z" />
|
||||
<DrawingGroup>
|
||||
<DrawingGroup.Transform>
|
||||
<MatrixTransform Matrix="1.08,0,0,1.08,-40.6,-75.6892" />
|
||||
</DrawingGroup.Transform>
|
||||
<GeometryDrawing Brush="#2B387C" Geometry="F0 M58.0 108.0C63.12 107.93 68.25 107.87 73.37 107.84C75.11 107.82 76.85 107.8 78.59 107.77C81.1 107.74 83.61 107.72 86.12 107.71C86.51 107.7 86.51 107.7 88.45 107.66C93.94 107.66 97.99000000000001 108.74 103.0 111.0C105.0 113.0 105.0 113.0 105.44 116.81C105.35 120.28 105.03999999999999 120.95 102.81 123.88C100.22 125.84 98.09 127.03 95.0 128.0C95.83 128.52 96.65 129.03 97.5 129.56C100.0 132.0 100.0 132.0 100.62 135.44C99.82 140.01 98.69 141.21 95.0 144.0C87.73 147.84 81.72 149.15 73.52 149.1C72.7 149.1 71.88 149.09 71.03999999999999 149.09C68.45 149.09 65.85 149.07999999999998 63.25 149.06C61.49 149.06 59.72 149.05 57.96 149.05C53.64 149.04 49.32 149.02 45.0 149.0C47.31 139.96 50.21 131.15 53.19 122.31C53.66 120.92 54.12 119.52 54.59 118.13C55.72 114.75 56.86 111.37 58.0 108.0ZM63.0 130.0C65.75 129.92 68.5 129.86 71.25 129.81C72.03 129.79 72.8 129.76 73.61 129.74C79.43 129.66 79.43 129.66 82.55 131.51C83.03 132.0 83.51 132.49 84.0 133.0C83.83 137.35 83.5 139.45 80.53 142.72C76.49 145.88 72.55 145.57 67.62 145.31C66.79 145.29 65.96 145.27 65.11 145.24C63.07 145.19 61.03 145.1 59.0 145.0C59.48 143.06 59.96 141.12 60.44 139.19C60.7 138.11 60.97 137.03 61.25 135.92C61.76 133.93 62.35 131.95 63.0 130.0ZM69.0 111.0C71.4 110.92 73.79 110.86 76.19 110.81C76.86 110.79 77.53 110.76 78.23 110.74C82.71000000000001 110.67 85.4 111.31 89.0 114.0C90.0 115.0 90.0 115.0 90.38 117.25C89.84 121.16 87.96000000000001 122.52 85.0 125.0C82.28999999999999 125.9 80.76 126.12 77.99 126.1C77.61 126.1 77.61 126.1 75.69 126.09C74.91 126.08 74.12 126.07 73.31 126.06C72.52 126.06 71.72 126.05 70.9 126.05C68.93 126.03999999999999 66.97 126.02 65.0 126.0C65.56 122.23 66.31 118.73 67.56 115.12C67.83 114.34 68.1 113.56 68.38 112.76C68.58 112.18 68.79 111.6 69.0 111.0Z" />
|
||||
<DrawingGroup>
|
||||
<DrawingGroup.Transform>
|
||||
<MatrixTransform Matrix="1.0,0,0,1.0,108.0,108.0" />
|
||||
</DrawingGroup.Transform>
|
||||
<GeometryDrawing Brush="#253278" Geometry="F1 M0 0 C4.29 0 8.58 0 13 0 C12.67 6.6 12.34 13.2 12 20 C13.4 17.53 14.81 15.05 16.25 12.5 C20.61 5.42 20.61 5.42 25.34 4 C28.62 4.06 28.62 4.06 34 5 C34.16 7.64 34.16 7.64 35 21 C35.27 20.45 35.27 20.45 36.64 17.68 C37.37 16.22 38.09 14.77 38.81 13.31 C39.17 12.59 39.53 11.87 39.89 11.13 C40.59 9.72 41.31 8.31 42.03 6.91 C42.85 5.29 43.62 3.65 44.38 2 C46 0 46 0 48.92 -0.49 C50 -0.43 51.08 -0.37 52.19 -0.31 C53.27 -0.27 54.36 -0.22 55.48 -0.18 C56.31 -0.12 57.14 -0.06 58 0 C53.27 10.09 48.48 20.15 43.5 30.12 C43.07 31 42.63 31.87 42.19 32.76 C41.79 33.57 41.38 34.37 40.97 35.2 C40.61 35.91 40.26 36.62 39.89 37.35 C39 39 39 39 38 40 C35.98 40.07 33.96 40.08 31.94 40.06 C31.39 40.06 31.39 40.06 28.59 40.04 C27.74 40.02 26.88 40.01 26 40 C25.94 39.4 25.89 38.8 25.83 38.18 C25.58 35.47 25.32 32.77 25.06 30.06 C24.98 29.12 24.89 28.17 24.8 27.2 C24.71 26.3 24.62 25.4 24.54 24.47 C24.46 23.64 24.38 22.81 24.3 21.95 C24 20 24 20 23 19 C20.85 22.29 18.71 25.58 16.56 28.88 C16.26 29.34 16.26 29.34 14.71 31.71 C14.13 32.61 13.54 33.51 12.94 34.43 C12.4 35.26 11.86 36.08 11.31 36.94 C10 39 10 39 9 41 C4.71 41 0.42 41 -4 41 C-3.37 30.27 -2.32 19.67 -1 9 C-0.66 6 -0.33 3 0 0 Z " />
|
||||
</DrawingGroup>
|
||||
<DrawingGroup>
|
||||
<DrawingGroup.Transform>
|
||||
<MatrixTransform Matrix="1.0,0,0,1.0,175.75,77.5625" />
|
||||
</DrawingGroup.Transform>
|
||||
<GeometryDrawing Brush="#D13A2E" Geometry="F1 M0 0 C0.48 -0.01 0.48 -0.01 2.9 -0.07 C10.94 -0.04 17.42 1.99 24.19 6.31 C28.61 10.87 29.42 14.58 29.44 20.81 C29.39 22.69 29.33 24.56 29.25 26.44 C25.62 26.44 21.99 26.44 18.25 26.44 C17.86 25.36 17.47 24.29 17.06 23.19 C15.45 19.49 13.78 17.56 10.25 15.44 C-8.16 8.49 -29.61 16.24 -46.75 23.44 C-47.19 23.71 -47.19 23.71 -49.43 25.11 C-54.58 27.17 -59.64 26.75 -65.12 26.62 C-65.68 26.62 -65.68 26.62 -68.51 26.58 C-71.26 26.55 -74 26.5 -76.75 26.44 C-73.33 22.84 -69.82 20.7 -65.38 18.56 C-64.67 18.22 -63.96 17.87 -63.22 17.51 C-61.07 16.48 -58.91 15.45 -56.75 14.44 C-55.57 13.88 -54.4 13.33 -53.18 12.76 C-44.91 9.05 -36.51 6.3 -27.75 3.97 C-25.95 3.49 -24.16 2.98 -22.37 2.46 C-14.9 0.54 -7.69 0.11 0 0 Z " />
|
||||
</DrawingGroup>
|
||||
<DrawingGroup>
|
||||
<DrawingGroup.Transform>
|
||||
<MatrixTransform Matrix="1.0,0,0,1.0,185.390625,107.90234375" />
|
||||
</DrawingGroup.Transform>
|
||||
<GeometryDrawing Brush="#263378" Geometry="F1 M0 0 C0.35 0 0.35 0 2.14 0 C4.38 0.01 6.62 0.02 8.86 0.04 C10.38 0.04 11.91 0.04 13.43 0.05 C17.16 0.06 20.88 0.08 24.61 0.1 C23.62 3.07 22.63 6.04 21.61 9.1 C20.77 9.12 19.93 9.14 19.07 9.16 C15.97 9.24 12.86 9.32 9.76 9.42 C7.75 9.47 5.74 9.52 3.74 9.57 C3.11 9.59 3.11 9.59 -0.07 9.68 C-1.23 9.72 -2.4 9.75 -3.59 9.78 C-6.39 10.1 -6.39 10.1 -8.39 12.1 C-8.39 13.09 -8.39 14.08 -8.39 15.1 C-7.16 15.14 -5.93 15.17 -4.66 15.21 C-3.03 15.28 -1.4 15.34 0.23 15.41 C1.04 15.43 1.85 15.46 2.68 15.48 C7.67 15.7 11.29 16.34 15.61 19.1 C17.22 22.32 17.07 25.6 16.61 29.1 C14.1 34.21 10.45 37.28 5.61 40.1 C1.91 41.33 -1.49 41.22 -5.34 41.2 C-6.11 41.19 -6.89 41.19 -7.68 41.19 C-10.15 41.19 -12.61 41.17 -15.08 41.16 C-16.75 41.16 -18.42 41.15 -20.1 41.15 C-24.19 41.14 -28.29 41.12 -32.39 41.1 C-31.4 38.13 -30.41 35.16 -29.39 32.1 C-28.46 32.08 -27.53 32.06 -26.58 32.04 C-23.14 31.96 -19.7 31.87 -16.26 31.78 C-14.77 31.74 -13.28 31.71 -11.79 31.68 C-9.65 31.63 -7.51 31.57 -5.37 31.51 C-4.08 31.48 -2.79 31.45 -1.46 31.42 C1.61 31.1 1.61 31.1 3.61 29.1 C3.61 28.11 3.61 27.12 3.61 26.1 C3.29 26.09 3.29 26.09 1.67 26.07 C-1.25 26.02 -4.16 25.93 -7.08 25.85 C-8.09 25.83 -9.09 25.82 -10.13 25.8 C-14.59 25.66 -17.62 25.53 -21.56 23.32 C-24.16 20.16 -24.05 18.29 -23.8 14.34 C-23 9.97 -20.99 7.31 -17.48 4.66 C-11.48 0.72 -7.23 -0.03 0 0 Z " />
|
||||
</DrawingGroup>
|
||||
<DrawingGroup>
|
||||
<DrawingGroup.Transform>
|
||||
<MatrixTransform Matrix="1.0,0,0,1.0,55.0,153.0" />
|
||||
</DrawingGroup.Transform>
|
||||
<GeometryDrawing Brush="#D13A2D" Geometry="F1 M0 0 C2.42 -0.16 4.83 -0.28 7.25 -0.38 C7.93 -0.43 8.61 -0.48 9.32 -0.53 C11.33 -0.59 11.33 -0.59 15 0 C17.24 2.84 17.24 2.84 19 6 C26.15 12.65 36.47 11.67 45.56 11.36 C52.28 11 58.53 9.85 65 8 C65.87 7.77 66.75 7.54 67.65 7.31 C72.34 6.01 76.68 4.29 81.12 2.31 C86.1 0.17 89.63 -0.52 95 0 C92.77 2.5 90.79 3.71 87.68 4.94 C86.84 5.28 85.99 5.61 85.12 5.96 C84.23 6.3 83.35 6.65 82.44 7 C81.58 7.34 80.72 7.69 79.84 8.04 C59.97 15.87 34.34 23.1 13.27 16.04 C7.96 13.6 4.12 10.78 1 5.81 C0 3 0 3 0 0 Z " />
|
||||
</DrawingGroup>
|
||||
<DrawingGroup>
|
||||
<DrawingGroup.Transform>
|
||||
<MatrixTransform Matrix="1.0,0,0,1.0,150.0,153.0" />
|
||||
</DrawingGroup.Transform>
|
||||
<GeometryDrawing Brush="#D34338" Geometry="F1 M0 0 C-3.24 3.54 -6.88 4.94 -11.25 6.75 C-11.99 7.08 -12.73 7.41 -13.49 7.75 C-18.5 9.84 -21.69 10.26 -27 9 C-23.59 6.13 -19.84 4.47 -15.75 2.81 C-15.43 2.68 -15.43 2.68 -13.84 1.99 C-9.04 0.04 -5.17 -0.26 0 0 Z " />
|
||||
</DrawingGroup>
|
||||
<DrawingGroup>
|
||||
<DrawingGroup.Transform>
|
||||
<MatrixTransform Matrix="1.0,0,0,1.0,88.0,165.0" />
|
||||
</DrawingGroup.Transform>
|
||||
<GeometryDrawing Brush="#D86359" Geometry="F1 M0 0 C2.75 -0.11 5.5 -0.19 8.25 -0.25 C9.03 -0.28 9.8 -0.32 10.61 -0.35 C16.43 -0.45 16.43 -0.45 19.55 2.02 C20.03 2.67 20.51 3.33 21 4 C20.17 3.84 20.17 3.84 16 3 C16 2.34 16 1.68 16 1 C10.72 1 5.44 1 0 1 C0 0.67 0 0.34 0 0 Z " />
|
||||
</DrawingGroup>
|
||||
<DrawingGroup>
|
||||
<DrawingGroup.Transform>
|
||||
<MatrixTransform Matrix="1.0,0,0,1.0,131.0,159.0" />
|
||||
</DrawingGroup.Transform>
|
||||
<GeometryDrawing Brush="#D0392D" Geometry="F1 M0 0 C-0.33 1.32 -0.66 2.64 -1 4 C-3.31 3.67 -5.62 3.34 -8 3 C-4.94 0.38 -4.27 0 0 0 Z " />
|
||||
</DrawingGroup>
|
||||
<DrawingGroup>
|
||||
<DrawingGroup.Transform>
|
||||
<MatrixTransform Matrix="1.0,0,0,1.0,150.0,153.0" />
|
||||
</DrawingGroup.Transform>
|
||||
<GeometryDrawing Brush="#D04337" Geometry="F1 M0 0 C-2.23 2.5 -4.21 3.71 -7.32 4.94 C-7.74 5.11 -7.74 5.11 -9.88 5.96 C-10.77 6.3 -11.65 6.65 -12.56 7 C-13.42 7.34 -14.28 7.69 -15.16 8.04 C-21.02 10.35 -26.94 12.28 -33 14 C-33.73 14.22 -34.46 14.44 -35.21 14.66 C-39.15 15.77 -42.06 16.23 -46 15 C-46 14.34 -46 13.68 -46 13 C-51.28 13 -56.56 13 -62 13 C-62 12.67 -62 12.34 -62 12 C-61.43 11.98 -61.43 11.98 -58.55 11.89 C-48.71 11.49 -39.56 10.51 -30 8 C-29.12 7.77 -28.24 7.55 -27.34 7.31 C-22.65 6 -18.32 4.28 -13.88 2.31 C-8.9 0.17 -5.37 -0.52 0 0 Z " />
|
||||
</DrawingGroup>
|
||||
</DrawingGroup>
|
||||
<DrawingGroup>
|
||||
<DrawingGroup>
|
||||
<DrawingGroup.Transform>
|
||||
<MatrixTransform Matrix="0.2226833,0,0,-0.2070485,195.76487,60.23789" />
|
||||
</DrawingGroup.Transform>
|
||||
<DrawingGroup>
|
||||
<DrawingGroup.Transform>
|
||||
<MatrixTransform Matrix="1.0,0,0,1.0,0.0,0.0" />
|
||||
</DrawingGroup.Transform>
|
||||
<GeometryDrawing Brush="#FFFFFF" Geometry="F1 M201 178Q201 83 202 55L187 48V184H78V48L63 42Q64 80 64.0 119.5Q64 159 63 198L79 190H186L196 200L211 185ZM28 -19Q88 6 102.5 28.5Q117 51 120.0 83.5Q123 116 122 164L147 152L138 145Q138 70 121.5 35.0Q105 0 29 -23ZM147 43Q190 27 208.0 14.0Q226 1 223.0 -9.5Q220 -20 216 -20Q214 -20 210 -15Q201 -3 187.0 10.0Q173 23 146 39Z">
|
||||
<GeometryDrawing.Pen>
|
||||
<Pen Brush="#FFFFFF" LineJoin="Round" Thickness="5" />
|
||||
</GeometryDrawing.Pen>
|
||||
</GeometryDrawing>
|
||||
</DrawingGroup>
|
||||
<DrawingGroup>
|
||||
<DrawingGroup.Transform>
|
||||
<MatrixTransform Matrix="1.0,0,0,1.0,256.0,0.0" />
|
||||
</DrawingGroup.Transform>
|
||||
<GeometryDrawing Brush="#FFFFFF" Geometry="F1 M244 -4V-8Q227 -8 219 -19Q176 27 165 109H158Q153 53 130.0 23.5Q107 -6 63 -23L62 -20Q101 3 120.0 31.0Q139 59 144 109H115Q102 109 91 106L82 115H144Q146 146 146 176Q115 174 91 172V176Q114 179 133.0 182.0Q152 185 173.5 190.5Q195 196 207 203L224 186Q205 185 160 178Q160 147 158 115H208L224 130L243 109H170Q195 12 244 -4ZM86 161Q57 56 54.5 43.5Q52 31 52 13Q52 -5 51.5 -10.5Q51 -16 48 -16Q45 -16 38.5 -12.5Q32 -9 32 -2Q32 5 34 11Q37 20 37 26Q37 32 33.0 36.0Q29 40 14 45V49Q29 47 34.5 47.0Q40 47 46.0 58.0Q52 69 82 162ZM14 138Q45 123 44.5 113.5Q44 104 41.0 100.5Q38 97 36 97Q33 97 30 106Q26 118 12 136ZM36 200Q58 190 61.5 185.5Q65 181 65 177Q65 172 62.0 166.5Q59 161 57 161Q54 161 52 169Q47 182 34 198Z">
|
||||
<GeometryDrawing.Pen>
|
||||
<Pen Brush="#FFFFFF" LineJoin="Round" Thickness="5" />
|
||||
</GeometryDrawing.Pen>
|
||||
</GeometryDrawing>
|
||||
</DrawingGroup>
|
||||
<DrawingGroup>
|
||||
<DrawingGroup.Transform>
|
||||
<MatrixTransform Matrix="1.0,0,0,1.0,512.0,0.0" />
|
||||
</DrawingGroup.Transform>
|
||||
<GeometryDrawing Brush="#FFFFFF" Geometry="F1 M76 66 99 56 91 49V13Q90 -3 103 -1H169Q181 0 182.5 13.0Q184 26 185 45H190Q191 23 193.5 13.5Q196 4 204 2Q196 -16 167 -14H98Q76 -16 77 6Q77 49 76 66ZM106 76 108 79Q126 72 135.0 66.0Q144 60 145.0 53.5Q146 47 142.5 41.5Q139 36 137 36Q134 36 131 44Q126 56 106 76ZM197 54 199 57Q219 47 229.0 39.0Q239 31 239.0 23.0Q239 15 235.0 10.5Q231 6 230 6Q226 6 222 18Q216 34 197 54ZM46 59H50Q50 34 48.0 22.0Q46 10 40.5 6.5Q35 3 30 3Q26 3 22.5 4.5Q19 6 19 7Q19 11 27 19Q39 31 46 59ZM67 188V143H122V188ZM136 188V143H190V188ZM67 137V93H122V137ZM136 137V93H190V137ZM204 185V118Q204 98 205 80L190 74V87H67V77L52 71Q53 101 53.0 142.5Q53 184 52 203L67 194H188L195 204L212 192Z">
|
||||
<GeometryDrawing.Pen>
|
||||
<Pen Brush="#FFFFFF" LineJoin="Round" Thickness="5" />
|
||||
</GeometryDrawing.Pen>
|
||||
</GeometryDrawing>
|
||||
</DrawingGroup>
|
||||
</DrawingGroup>
|
||||
<DrawingGroup>
|
||||
<DrawingGroup.Transform>
|
||||
<MatrixTransform Matrix="0.0123755,0,0,-0.0129604,196.14367,101.0" />
|
||||
</DrawingGroup.Transform>
|
||||
<DrawingGroup>
|
||||
<DrawingGroup.Transform>
|
||||
<MatrixTransform Matrix="1.0,0,0,1.0,0.0,0.0" />
|
||||
</DrawingGroup.Transform>
|
||||
<GeometryDrawing Brush="#FFFFFF" Geometry="F1 M150 1466H736Q910 1466 995.5 1451.5Q1081 1437 1148.5 1391.0Q1216 1345 1261.0 1268.5Q1306 1192 1306 1097Q1306 994 1250.5 908.0Q1195 822 1100 779Q1234 740 1306.0 646.0Q1378 552 1378 425Q1378 325 1331.5 230.5Q1285 136 1204.5 79.5Q1124 23 1006 10Q932 2 649 0H150ZM446 1222V883H640Q813 883 855 888Q931 897 974.5 940.5Q1018 984 1018 1055Q1018 1123 980.5 1165.5Q943 1208 869 1217Q825 1222 616 1222ZM446 639V247H720Q880 247 923 256Q989 268 1030.5 314.5Q1072 361 1072 439Q1072 505 1040.0 551.0Q1008 597 947.5 618.0Q887 639 685 639Z" />
|
||||
</DrawingGroup>
|
||||
<DrawingGroup>
|
||||
<DrawingGroup.Transform>
|
||||
<MatrixTransform Matrix="1.0,0,0,1.0,1479.0,0.0" />
|
||||
</DrawingGroup.Transform>
|
||||
<GeometryDrawing Brush="#FFFFFF" Geometry="F1 M149 0V1466H1236V1218H445V893H1181V646H445V247H1264V0Z" />
|
||||
</DrawingGroup>
|
||||
<DrawingGroup>
|
||||
<DrawingGroup.Transform>
|
||||
<MatrixTransform Matrix="1.0,0,0,1.0,2845.0,0.0" />
|
||||
</DrawingGroup.Transform>
|
||||
<GeometryDrawing Brush="#FFFFFF" Geometry="F1 M157 0V1454H453V247H1189V0Z" />
|
||||
</DrawingGroup>
|
||||
<DrawingGroup>
|
||||
<DrawingGroup.Transform>
|
||||
<MatrixTransform Matrix="1.0,0,0,1.0,4096.0,0.0" />
|
||||
</DrawingGroup.Transform>
|
||||
<GeometryDrawing Brush="#FFFFFF" Geometry="F1 M157 0V1454H453V247H1189V0Z" />
|
||||
</DrawingGroup>
|
||||
<DrawingGroup>
|
||||
<DrawingGroup.Transform>
|
||||
<MatrixTransform Matrix="1.0,0,0,1.0,5347.0,0.0" />
|
||||
</DrawingGroup.Transform>
|
||||
<GeometryDrawing Brush="#FFFFFF" Geometry="F1 M357 0 7 1466H310L531 459L799 1466H1151L1408 442L1633 1466H1931L1575 0H1261L969 1096L678 0Z" />
|
||||
</DrawingGroup>
|
||||
<DrawingGroup>
|
||||
<DrawingGroup.Transform>
|
||||
<MatrixTransform Matrix="1.0,0,0,1.0,7280.0,0.0" />
|
||||
</DrawingGroup.Transform>
|
||||
<GeometryDrawing Brush="#FFFFFF" Geometry="F1 M149 0V1466H1236V1218H445V893H1181V646H445V247H1264V0Z" />
|
||||
</DrawingGroup>
|
||||
<DrawingGroup>
|
||||
<DrawingGroup.Transform>
|
||||
<MatrixTransform Matrix="1.0,0,0,1.0,8646.0,0.0" />
|
||||
</DrawingGroup.Transform>
|
||||
<GeometryDrawing Brush="#FFFFFF" Geometry="F1 M479 0V1218H44V1466H1209V1218H775V0Z" />
|
||||
</DrawingGroup>
|
||||
<DrawingGroup>
|
||||
<DrawingGroup.Transform>
|
||||
<MatrixTransform Matrix="1.0,0,0,1.0,9897.0,0.0" />
|
||||
</DrawingGroup.Transform>
|
||||
<GeometryDrawing Brush="#FFFFFF" Geometry="F1 M150 0V1466H446V889H1026V1466H1322V0H1026V641H446V0Z" />
|
||||
</DrawingGroup>
|
||||
<DrawingGroup>
|
||||
<DrawingGroup.Transform>
|
||||
<MatrixTransform Matrix="1.0,0,0,1.0,11376.0,0.0" />
|
||||
</DrawingGroup.Transform>
|
||||
<GeometryDrawing Brush="#FFFFFF" Geometry="F1 M149 0V1466H1236V1218H445V893H1181V646H445V247H1264V0Z" />
|
||||
</DrawingGroup>
|
||||
<DrawingGroup>
|
||||
<DrawingGroup.Transform>
|
||||
<MatrixTransform Matrix="1.0,0,0,1.0,12742.0,0.0" />
|
||||
</DrawingGroup.Transform>
|
||||
<GeometryDrawing Brush="#FFFFFF" Geometry="F1 M150 0V1466H773Q1008 1466 1114.5 1426.5Q1221 1387 1285.0 1286.0Q1349 1185 1349 1055Q1349 890 1252.0 782.5Q1155 675 962 647Q1058 591 1120.5 524.0Q1183 457 1289 286L1468 0H1114L900 319Q786 490 744.0 534.5Q702 579 655.0 595.5Q608 612 506 612H446V0ZM446 846H665Q878 846 931.0 864.0Q984 882 1014.0 926.0Q1044 970 1044 1036Q1044 1110 1004.5 1155.5Q965 1201 893 1213Q857 1218 677 1218H446Z" />
|
||||
</DrawingGroup>
|
||||
</DrawingGroup>
|
||||
</DrawingGroup>
|
||||
</DrawingGroup>
|
||||
</DrawingImage.Drawing>
|
||||
</DrawingImage>
|
||||
</ResourceDictionary>
|
||||
8
src/SopHelper.App/Assets/bws.svg
Normal file
8
src/SopHelper.App/Assets/bws.svg
Normal file
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 11 KiB |
@ -1,7 +1,6 @@
|
||||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
||||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
||||
|
||||
<!-- 纯 WPF 样式,不依赖任何控件库 -->
|
||||
<!-- 纯 WPF 样式,不依赖任何控件库 -->
|
||||
|
||||
<SolidColorBrush x:Key="Bg" Color="#FF101820" />
|
||||
<SolidColorBrush x:Key="Panel" Color="#FF16222E" />
|
||||
@ -19,7 +18,9 @@
|
||||
<Setter Property="VerticalAlignment" Value="Center" />
|
||||
</Style>
|
||||
|
||||
<Style x:Key="Title" TargetType="TextBlock" BasedOn="{StaticResource {x:Type TextBlock}}">
|
||||
<Style x:Key="Title"
|
||||
BasedOn="{StaticResource {x:Type TextBlock}}"
|
||||
TargetType="TextBlock">
|
||||
<Setter Property="FontSize" Value="16" />
|
||||
<Setter Property="FontWeight" Value="Bold" />
|
||||
<Setter Property="Foreground" Value="{StaticResource Accent}" />
|
||||
@ -45,11 +46,11 @@
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="Button">
|
||||
<Border Background="{TemplateBinding Background}"
|
||||
<Border Padding="{TemplateBinding Padding}"
|
||||
Background="{TemplateBinding Background}"
|
||||
BorderBrush="{TemplateBinding BorderBrush}"
|
||||
BorderThickness="{TemplateBinding BorderThickness}"
|
||||
CornerRadius="5"
|
||||
Padding="{TemplateBinding Padding}">
|
||||
CornerRadius="5">
|
||||
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" />
|
||||
</Border>
|
||||
<ControlTemplate.Triggers>
|
||||
@ -65,8 +66,10 @@
|
||||
</Setter>
|
||||
</Style>
|
||||
|
||||
<!-- ComboBox:WPF 默认模板是白底(SystemColors.WindowBrush),深色主题下
|
||||
浅色字落在白底上等于看不见——实测"选不了相机"就是这个。整体重写。 -->
|
||||
<!--
|
||||
ComboBox:WPF 默认模板是白底(SystemColors.WindowBrush),深色主题下
|
||||
浅色字落在白底上等于看不见——实测"选不了相机"就是这个。整体重写。
|
||||
-->
|
||||
<Style TargetType="ComboBox">
|
||||
<Setter Property="Foreground" Value="{StaticResource Fg}" />
|
||||
<Setter Property="Background" Value="{StaticResource Panel}" />
|
||||
@ -77,14 +80,17 @@
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="ComboBox">
|
||||
<Grid>
|
||||
<ToggleButton Focusable="False" ClickMode="Press"
|
||||
<ToggleButton ClickMode="Press" Focusable="False"
|
||||
IsChecked="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}">
|
||||
<ToggleButton.Template>
|
||||
<ControlTemplate TargetType="ToggleButton">
|
||||
<Border Background="{StaticResource Panel}" BorderBrush="{StaticResource Line}"
|
||||
BorderThickness="1" CornerRadius="4" Padding="0">
|
||||
<Path HorizontalAlignment="Right" VerticalAlignment="Center" Margin="0,0,8,0"
|
||||
Fill="{StaticResource FgDim}" Data="M 0 0 L 8 0 L 4 5 Z" />
|
||||
<Border Padding="0"
|
||||
Background="{StaticResource Panel}"
|
||||
BorderBrush="{StaticResource Line}"
|
||||
BorderThickness="1" CornerRadius="4">
|
||||
<Path Margin="0,0,8,0" HorizontalAlignment="Right"
|
||||
VerticalAlignment="Center" Data="M 0 0 L 8 0 L 4 5 Z"
|
||||
Fill="{StaticResource FgDim}" />
|
||||
</Border>
|
||||
</ControlTemplate>
|
||||
</ToggleButton.Template>
|
||||
@ -95,10 +101,13 @@
|
||||
ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}"
|
||||
IsHitTestVisible="False" />
|
||||
|
||||
<Popup AllowsTransparency="True" Placement="Bottom" Focusable="False"
|
||||
IsOpen="{TemplateBinding IsDropDownOpen}" PopupAnimation="Slide">
|
||||
<Border Background="{StaticResource Panel}" BorderBrush="{StaticResource Line}" BorderThickness="1"
|
||||
MinWidth="{Binding ActualWidth, RelativeSource={RelativeSource TemplatedParent}}">
|
||||
<Popup AllowsTransparency="True" Focusable="False"
|
||||
IsOpen="{TemplateBinding IsDropDownOpen}"
|
||||
Placement="Bottom" PopupAnimation="Slide">
|
||||
<Border MinWidth="{Binding ActualWidth, RelativeSource={RelativeSource TemplatedParent}}"
|
||||
Background="{StaticResource Panel}"
|
||||
BorderBrush="{StaticResource Line}"
|
||||
BorderThickness="1">
|
||||
<ScrollViewer MaxHeight="240">
|
||||
<StackPanel IsItemsHost="True" />
|
||||
</ScrollViewer>
|
||||
@ -116,7 +125,9 @@
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="ComboBoxItem">
|
||||
<Border x:Name="bd" Background="Transparent" Padding="{TemplateBinding Padding}">
|
||||
<Border x:Name="bd"
|
||||
Padding="{TemplateBinding Padding}"
|
||||
Background="Transparent">
|
||||
<ContentPresenter />
|
||||
</Border>
|
||||
<ControlTemplate.Triggers>
|
||||
@ -132,10 +143,12 @@
|
||||
</Setter>
|
||||
</Style>
|
||||
|
||||
<!-- TextBox:同 ComboBox,WPF 默认模板是白底。配方编辑器满屏都是输入框,
|
||||
不重写就是深底白框一片花。 -->
|
||||
<!--
|
||||
TextBox:同 ComboBox,WPF 默认模板是白底。配方编辑器满屏都是输入框,
|
||||
不重写就是深底白框一片花。
|
||||
-->
|
||||
<Style TargetType="TextBox">
|
||||
<!-- 模板内部 Border 必须显式绑定 Padding,避免继承全局面板的 10px 内边距。 -->
|
||||
<!-- 模板内部 Border 必须显式绑定 Padding,避免继承全局面板的 10px 内边距。 -->
|
||||
<Setter Property="Foreground" Value="{StaticResource Fg}" />
|
||||
<Setter Property="CaretBrush" Value="{StaticResource Accent}" />
|
||||
<Setter Property="Background" Value="{StaticResource Panel}" />
|
||||
@ -150,10 +163,11 @@
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="TextBox">
|
||||
<Border Background="{TemplateBinding Background}"
|
||||
<Border Padding="{TemplateBinding Padding}"
|
||||
Background="{TemplateBinding Background}"
|
||||
BorderBrush="{TemplateBinding BorderBrush}"
|
||||
BorderThickness="{TemplateBinding BorderThickness}"
|
||||
CornerRadius="4" Padding="{TemplateBinding Padding}">
|
||||
CornerRadius="4">
|
||||
<ScrollViewer x:Name="PART_ContentHost" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
|
||||
</Border>
|
||||
<ControlTemplate.Triggers>
|
||||
@ -169,7 +183,7 @@
|
||||
</Setter>
|
||||
</Style>
|
||||
|
||||
<!-- CheckBox:默认模板浅色主题底,同理重写 -->
|
||||
<!-- CheckBox:默认模板浅色主题底,同理重写 -->
|
||||
<Style TargetType="CheckBox">
|
||||
<Setter Property="Foreground" Value="{StaticResource Fg}" />
|
||||
<Setter Property="FontFamily" Value="Microsoft YaHei" />
|
||||
@ -179,13 +193,15 @@
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="CheckBox">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<Border x:Name="box" Width="16" Height="16" CornerRadius="3"
|
||||
<Border x:Name="box" Width="16" Height="16" Padding="0"
|
||||
VerticalAlignment="Center"
|
||||
Background="{StaticResource Panel}"
|
||||
BorderBrush="{StaticResource Line}" BorderThickness="1" Padding="0"
|
||||
VerticalAlignment="Center">
|
||||
<Path x:Name="tick" Width="10" Height="10" Stretch="Fill"
|
||||
Fill="{StaticResource Accent}" Visibility="Collapsed"
|
||||
Data="M 0 4 L 3 8 L 10 0 L 12 2 L 4 11 L 1 7 Z" />
|
||||
BorderBrush="{StaticResource Line}"
|
||||
BorderThickness="1" CornerRadius="3">
|
||||
<Path x:Name="tick" Width="10" Height="10"
|
||||
Data="M 0 4 L 3 8 L 10 0 L 12 2 L 4 11 L 1 7 Z"
|
||||
Fill="{StaticResource Accent}"
|
||||
Stretch="Fill" Visibility="Collapsed" />
|
||||
</Border>
|
||||
<ContentPresenter Margin="6,0,0,0" VerticalAlignment="Center" />
|
||||
</StackPanel>
|
||||
@ -205,7 +221,7 @@
|
||||
</Setter>
|
||||
</Style>
|
||||
|
||||
<!-- TabControl:默认模板是浅色主题底(同 ComboBox 那个坑),配方编辑器要用它分区。 -->
|
||||
<!-- TabControl:默认模板是浅色主题底(同 ComboBox 那个坑),配方编辑器要用它分区。 -->
|
||||
<Style TargetType="TabControl">
|
||||
<Setter Property="Background" Value="Transparent" />
|
||||
<Setter Property="BorderBrush" Value="{StaticResource Line}" />
|
||||
@ -219,10 +235,12 @@
|
||||
<RowDefinition Height="*" />
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<TabPanel Grid.Row="0" IsItemsHost="True" Margin="0,0,0,6" />
|
||||
<TabPanel Grid.Row="0" Margin="0,0,0,6" IsItemsHost="True" />
|
||||
|
||||
<Border Grid.Row="1" Background="{StaticResource Panel}"
|
||||
BorderBrush="{StaticResource Line}" BorderThickness="1" CornerRadius="6">
|
||||
<Border Grid.Row="1"
|
||||
Background="{StaticResource Panel}"
|
||||
BorderBrush="{StaticResource Line}"
|
||||
BorderThickness="1" CornerRadius="6">
|
||||
<ContentPresenter ContentSource="SelectedContent" />
|
||||
</Border>
|
||||
</Grid>
|
||||
@ -239,9 +257,12 @@
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="TabItem">
|
||||
<Border x:Name="bd" Background="Transparent" BorderBrush="{StaticResource Line}"
|
||||
BorderThickness="1" CornerRadius="5" Padding="{TemplateBinding Padding}" Margin="0,0,6,0">
|
||||
<ContentPresenter ContentSource="Header" VerticalAlignment="Center" />
|
||||
<Border x:Name="bd" Margin="0,0,6,0"
|
||||
Padding="{TemplateBinding Padding}"
|
||||
Background="Transparent"
|
||||
BorderBrush="{StaticResource Line}"
|
||||
BorderThickness="1" CornerRadius="5">
|
||||
<ContentPresenter VerticalAlignment="Center" ContentSource="Header" />
|
||||
</Border>
|
||||
<ControlTemplate.Triggers>
|
||||
<Trigger Property="IsSelected" Value="True">
|
||||
@ -258,13 +279,15 @@
|
||||
</Setter>
|
||||
</Style>
|
||||
|
||||
<!-- 表单里的字段标签列 -->
|
||||
<Style x:Key="Field" TargetType="TextBlock" BasedOn="{StaticResource {x:Type TextBlock}}">
|
||||
<!-- 表单里的字段标签列 -->
|
||||
<Style x:Key="Field"
|
||||
BasedOn="{StaticResource {x:Type TextBlock}}"
|
||||
TargetType="TextBlock">
|
||||
<Setter Property="Width" Value="74" />
|
||||
<Setter Property="Foreground" Value="{StaticResource FgDim}" />
|
||||
</Style>
|
||||
|
||||
<!-- 左侧导航 -->
|
||||
<!-- 左侧导航 -->
|
||||
<Style TargetType="ListBox">
|
||||
<Setter Property="Background" Value="Transparent" />
|
||||
<Setter Property="BorderThickness" Value="0" />
|
||||
@ -276,7 +299,9 @@
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="ListBoxItem">
|
||||
<Border x:Name="bd" Background="Transparent" Padding="{TemplateBinding Padding}" CornerRadius="5">
|
||||
<Border x:Name="bd"
|
||||
Padding="{TemplateBinding Padding}"
|
||||
Background="Transparent" CornerRadius="5">
|
||||
<ContentPresenter />
|
||||
</Border>
|
||||
<ControlTemplate.Triggers>
|
||||
@ -297,7 +322,7 @@
|
||||
<Setter.Value>
|
||||
<DataTemplate>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<TextBlock Text="{Binding DisplayName}" FontSize="14" />
|
||||
<TextBlock FontSize="14" Text="{Binding DisplayName}" />
|
||||
</StackPanel>
|
||||
</DataTemplate>
|
||||
</Setter.Value>
|
||||
|
||||
@ -6,9 +6,18 @@
|
||||
Title="{Binding Title}"
|
||||
Height="720" Width="1180"
|
||||
MinHeight="560" MinWidth="900"
|
||||
WindowState="Maximized"
|
||||
Background="{StaticResource Bg}"
|
||||
WindowStartupLocation="CenterScreen">
|
||||
|
||||
<Window.Resources>
|
||||
<ResourceDictionary>
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="/SopHelper;component/Assets/BellwetherLogo.xaml" />
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
</ResourceDictionary>
|
||||
</Window.Resources>
|
||||
|
||||
<Grid Margin="10">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="180" />
|
||||
@ -20,9 +29,12 @@
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<!-- 标题栏 -->
|
||||
<StackPanel Grid.ColumnSpan="2" Orientation="Horizontal" Margin="2,2,2,10">
|
||||
<TextBlock Style="{StaticResource Title}" Text="{Binding Title}" />
|
||||
</StackPanel>
|
||||
<Border Grid.ColumnSpan="2" HorizontalAlignment="Left"
|
||||
Width="202" Height="72" Margin="2,2,2,10"
|
||||
Background="Transparent" BorderThickness="0" CornerRadius="4" Padding="6">
|
||||
<Image Source="{StaticResource BellwetherLogo}" Stretch="Uniform"
|
||||
AutomationProperties.Name="贝沃思 BELLWETHER" />
|
||||
</Border>
|
||||
|
||||
<!-- 侧导航 -->
|
||||
<Border Grid.Row="1" Margin="0,0,10,0">
|
||||
|
||||
@ -518,6 +518,14 @@ public class RecipeSettingsNode : EditorNode
|
||||
private bool _autoResetOnComplete = true;
|
||||
private int _resetDelaySec = 1;
|
||||
private int _frameStride = 1;
|
||||
private double? _exposureTimeUs;
|
||||
|
||||
public double? ExposureTimeUs
|
||||
{
|
||||
get => _exposureTimeUs;
|
||||
set => SetProperty(ref _exposureTimeUs, value);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>全局置信度阈值</summary>
|
||||
public float ConfidenceThreshold
|
||||
@ -578,6 +586,7 @@ public class RecipeSettingsNode : EditorNode
|
||||
/// <summary>读入</summary>
|
||||
public void CopyFrom(SopSettings from)
|
||||
{
|
||||
ExposureTimeUs = from.ExposureTimeUs;
|
||||
ConfidenceThreshold = from.ConfidenceThreshold;
|
||||
StableFrames = from.StableFrames;
|
||||
PositionTolerance = from.PositionTolerance;
|
||||
@ -591,6 +600,7 @@ public class RecipeSettingsNode : EditorNode
|
||||
/// <summary>写出</summary>
|
||||
public void CopyTo(SopSettings to)
|
||||
{
|
||||
to.ExposureTimeUs = ExposureTimeUs;
|
||||
to.ConfidenceThreshold = ConfidenceThreshold;
|
||||
to.StableFrames = StableFrames;
|
||||
to.PositionTolerance = PositionTolerance;
|
||||
|
||||
@ -536,6 +536,13 @@
|
||||
<CheckBox Content="使用检测模型(object_* 与 hand_near_object / person_present 依赖它)"
|
||||
IsChecked="{Binding HasModel}" Margin="0,0,0,10" />
|
||||
|
||||
<StackPanel Orientation="Horizontal" Margin="0,0,0,10">
|
||||
<TextBlock Text="相机曝光(μs)" VerticalAlignment="Center" Margin="0,0,8,0" />
|
||||
<TextBox x:Name="CameraExposureInput" Width="120"
|
||||
Text="{Binding Settings.ExposureTimeUs, UpdateSourceTrigger=PropertyChanged, ValidatesOnExceptions=True}"
|
||||
ToolTip="海康相机曝光时间,10000 为 10 毫秒;留空保留相机设置。保存配方后保留,区域取图和 SOP 启动前应用。" />
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel Visibility="{Binding DataContext.HasModel, ElementName=ModelSettings, Converter={StaticResource BoolToVis}}" DataContext="{Binding Model}">
|
||||
<Grid Style="{StaticResource Row}">
|
||||
<Grid.ColumnDefinitions>
|
||||
|
||||
@ -219,6 +219,12 @@ public class RecipeEditorViewModel : BindableBase, IDialogAware
|
||||
try
|
||||
{
|
||||
if (!await camera.ConnectAsync(_cameraInfo)) throw new InvalidOperationException("连接相机失败,请查看 SOP 页日志");
|
||||
if (Recipe.Settings.ExposureTimeUs is { } exposure)
|
||||
{
|
||||
if (!double.IsFinite(exposure) || exposure <= 0)
|
||||
throw new InvalidOperationException("相机曝光必须大于 0(微秒),或留空保留相机设置");
|
||||
await camera.SetExposureTimeAsync(exposure);
|
||||
}
|
||||
camera.FrameArrived += Receive;
|
||||
if (!await camera.StartAsync()) throw new InvalidOperationException("启动采集失败");
|
||||
PreviewImage = await ready.Task.WaitAsync(TimeSpan.FromSeconds(5));
|
||||
@ -237,6 +243,11 @@ public class RecipeEditorViewModel : BindableBase, IDialogAware
|
||||
private void Save()
|
||||
{
|
||||
SaveStatus = "";
|
||||
if (Recipe.Settings.ExposureTimeUs is { } exposure && (!double.IsFinite(exposure) || exposure <= 0))
|
||||
{
|
||||
Warnings.Add("相机曝光必须大于 0(微秒),或留空保留相机设置");
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrWhiteSpace(Recipe.Name))
|
||||
{
|
||||
Warnings.Add("配方名(sop.name)不能为空");
|
||||
|
||||
@ -39,7 +39,12 @@ public sealed class HandOverlay : FrameworkElement
|
||||
var unit = Math.Max(result.Size.W, result.Size.H) / 700.0;
|
||||
foreach (var hand in result.Hands)
|
||||
{
|
||||
var brush = hand.HandType == HandType.Left ? Brushes.LimeGreen : Brushes.DeepSkyBlue;
|
||||
var brush = hand.HandType switch
|
||||
{
|
||||
HandType.Left => Brushes.LimeGreen,
|
||||
HandType.Right => Brushes.DeepSkyBlue,
|
||||
_ => Brushes.Gray,
|
||||
};
|
||||
var pen = new Pen(brush, unit * 2);
|
||||
var points = hand.Keypoints
|
||||
.Where(p => p.Index is >= 0 and <= 20 && p.Confidence > 0 &&
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text.Json;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Threading;
|
||||
@ -26,6 +27,9 @@ public class SopPageViewModel : ViewModelBase
|
||||
/// <summary>配方目录(相对程序目录)</summary>
|
||||
private static string RecipeDirectory => Path.Combine(AppContext.BaseDirectory, "configs", "sop");
|
||||
|
||||
private static string LastCameraPath => Path.Combine(
|
||||
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "SopHelper", "last-camera.json");
|
||||
|
||||
/// <summary>配方编辑器弹窗的注册名(见 App.RegisterTypes)</summary>
|
||||
private const string EditorDialogName = "RecipeEditorDialog";
|
||||
|
||||
@ -51,6 +55,7 @@ public class SopPageViewModel : ViewModelBase
|
||||
private long _lastTickCount;
|
||||
|
||||
private CameraInfo? _selectedCamera;
|
||||
private CameraInfo? _lastUsedCamera;
|
||||
private string? _selectedRecipe;
|
||||
private ImageSource? _frame;
|
||||
private string _statusText = "就绪";
|
||||
@ -114,6 +119,8 @@ public class SopPageViewModel : ViewModelBase
|
||||
NewRecipeCommand = new DelegateCommand(NewRecipe, () => !IsRunning && !_isCameraBusy);
|
||||
|
||||
StatusText = "选择相机和配方,点开始";
|
||||
LoadLastCamera();
|
||||
_ = RefreshCamerasAsync();
|
||||
}
|
||||
|
||||
/// <summary>可用相机</summary>
|
||||
@ -435,17 +442,46 @@ public class SopPageViewModel : ViewModelBase
|
||||
_dialogs.ShowDialog(EditorDialogName, parameters, _ => { });
|
||||
}
|
||||
|
||||
private void LoadLastCamera()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (File.Exists(LastCameraPath))
|
||||
_lastUsedCamera = JsonSerializer.Deserialize<CameraInfo>(File.ReadAllText(LastCameraPath));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log("warn", $"读取上次使用的相机失败:{ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
private void RememberCamera(CameraInfo camera)
|
||||
{
|
||||
_lastUsedCamera = camera;
|
||||
try
|
||||
{
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(LastCameraPath)!);
|
||||
File.WriteAllText(LastCameraPath, JsonSerializer.Serialize(camera));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log("warn", $"保存上次使用的相机失败:{ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
private async Task RefreshCamerasAsync()
|
||||
{
|
||||
if (!CanSelectCamera) return;
|
||||
if (_destroyed || !CanSelectCamera) return;
|
||||
SetCameraBusy(true);
|
||||
try
|
||||
{
|
||||
var previous = SelectedCamera;
|
||||
var previous = SelectedCamera ?? _lastUsedCamera;
|
||||
SelectedCamera = null;
|
||||
Cameras.Clear();
|
||||
|
||||
foreach (var info in await _camera.EnumerateAsync())
|
||||
var cameras = await _camera.EnumerateAsync();
|
||||
if (_destroyed) return;
|
||||
foreach (var info in cameras)
|
||||
Cameras.Add(info);
|
||||
|
||||
if (Cameras.Count == 0)
|
||||
@ -507,6 +543,23 @@ public class SopPageViewModel : ViewModelBase
|
||||
|
||||
ApplyRecipe();
|
||||
|
||||
if (_engine.Config.Sop.Settings.ExposureTimeUs is { } exposure)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!double.IsFinite(exposure) || exposure <= 0)
|
||||
throw new InvalidOperationException("相机曝光必须大于 0(微秒),或留空保留相机设置");
|
||||
await _camera.SetExposureTimeAsync(exposure);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log("error", "设置相机曝光失败:" + ex.Message);
|
||||
await Task.Run(_camera.Disconnect);
|
||||
StatusText = "设置相机曝光失败";
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// 阈值 / 抽帧从界面参数覆盖配方默认值
|
||||
_pipeline.SetThresholds((float)Confidence, 0.45f);
|
||||
_engine.Config.Sop.Settings.FrameStride = Math.Max(1, FrameStride);
|
||||
@ -520,6 +573,7 @@ public class SopPageViewModel : ViewModelBase
|
||||
|
||||
_engine.Start();
|
||||
IsRunning = true;
|
||||
RememberCamera(SelectedCamera);
|
||||
StatusText = "运行中";
|
||||
}
|
||||
|
||||
|
||||
@ -52,6 +52,18 @@ public sealed class CameraService : ICameraService
|
||||
finally { _operations.Release(); }
|
||||
}
|
||||
|
||||
public async Task SetExposureTimeAsync(double microseconds)
|
||||
{
|
||||
await _operations.WaitAsync().ConfigureAwait(false);
|
||||
try
|
||||
{
|
||||
ObjectDisposedException.ThrowIf(_disposed, this);
|
||||
if (_active is null || !_active.IsConnected) throw new InvalidOperationException("请先连接相机");
|
||||
await _active.SetExposureTimeAsync(microseconds).ConfigureAwait(false);
|
||||
}
|
||||
finally { _operations.Release(); }
|
||||
}
|
||||
|
||||
public async Task<bool> StartAsync()
|
||||
{
|
||||
await _operations.WaitAsync().ConfigureAwait(false);
|
||||
|
||||
@ -99,6 +99,19 @@ public sealed class HikvisionCameraService : ICameraService
|
||||
}
|
||||
});
|
||||
|
||||
public Task SetExposureTimeAsync(double microseconds) => Task.Run(() =>
|
||||
{
|
||||
lock (_gate)
|
||||
{
|
||||
if (!double.IsFinite(microseconds) || microseconds <= 0 || microseconds > float.MaxValue)
|
||||
throw new ArgumentOutOfRangeException(nameof(microseconds), "相机曝光必须是大于 0 的有限数值(微秒)");
|
||||
if (!_connected || _device is null || _disposed) throw new InvalidOperationException("请先连接海康相机");
|
||||
if (_grabbing) throw new InvalidOperationException("请停止采集后再设置曝光");
|
||||
Check(_device.Parameters.SetEnumValueByString("ExposureAuto", "Off"), "关闭自动曝光");
|
||||
Check(_device.Parameters.SetFloatValue("ExposureTime", (float)microseconds), "设置曝光时间,请确认数值在相机支持范围内");
|
||||
}
|
||||
});
|
||||
|
||||
public Task<bool> StartAsync() => Task.Run(() =>
|
||||
{
|
||||
lock (_gate)
|
||||
|
||||
@ -70,6 +70,10 @@ public interface ICameraService : IDisposable
|
||||
/// <summary>连接相机</summary>
|
||||
Task<bool> ConnectAsync(CameraInfo camera);
|
||||
|
||||
/// <summary>连接后、采集前设置手动曝光,单位微秒。不支持时明确报错。</summary>
|
||||
Task SetExposureTimeAsync(double microseconds) =>
|
||||
Task.FromException(new NotSupportedException("当前相机不支持以微秒设置曝光,请将配方的相机曝光留空"));
|
||||
|
||||
/// <summary>开始采集</summary>
|
||||
Task<bool> StartAsync();
|
||||
|
||||
|
||||
@ -113,6 +113,9 @@ public class Hand
|
||||
/// <summary>左右手判定</summary>
|
||||
public HandType HandType { get; set; } = HandType.Unknown;
|
||||
|
||||
/// <summary>校正输入镜像约定后的单帧右手概率(0=左,1=右);与跨帧稳定的 HandType 分开保存。</summary>
|
||||
public float? RightHandProbability { get; set; }
|
||||
|
||||
/// <summary>手部(手掌)框</summary>
|
||||
public DetRect Rect { get; set; }
|
||||
|
||||
|
||||
25
src/SopHelper.Engine/Inference/HandednessDecoder.cs
Normal file
25
src/SopHelper.Engine/Inference/HandednessDecoder.cs
Normal file
@ -0,0 +1,25 @@
|
||||
using SopHelper.Engine.Common;
|
||||
|
||||
namespace SopHelper.Engine.Inference;
|
||||
|
||||
internal static class HandednessDecoder
|
||||
{
|
||||
/// <summary>
|
||||
/// 当前 legacy MediaPipe ONNX 模型按镜像输入定义左右手;采集管线未镜像,
|
||||
/// 因此将模型输出取反,统一为操作者实际右手的概率后再做跨帧稳定。
|
||||
/// https://chuoling.github.io/mediapipe/solutions/hands.html#multi_handedness
|
||||
/// </summary>
|
||||
public static void ApplyUnmirrored(Hand hand, float modelRightProbability)
|
||||
{
|
||||
if (!float.IsFinite(modelRightProbability) || modelRightProbability is < 0 or > 1)
|
||||
{
|
||||
hand.RightHandProbability = null;
|
||||
hand.HandType = HandType.Unknown;
|
||||
return;
|
||||
}
|
||||
|
||||
var actualRightProbability = 1f - modelRightProbability;
|
||||
hand.RightHandProbability = actualRightProbability;
|
||||
hand.HandType = actualRightProbability >= 0.5f ? HandType.Right : HandType.Left;
|
||||
}
|
||||
}
|
||||
109
src/SopHelper.Engine/Inference/HandednessStabilizer.cs
Normal file
109
src/SopHelper.Engine/Inference/HandednessStabilizer.cs
Normal file
@ -0,0 +1,109 @@
|
||||
using SopHelper.Engine.Common;
|
||||
|
||||
namespace SopHelper.Engine.Inference;
|
||||
|
||||
/// <summary>按空间位置关联手部,仅稳定左右手标签,不平滑关键点或延迟位置。</summary>
|
||||
internal sealed class HandednessStabilizer
|
||||
{
|
||||
private readonly List<Track> _tracks = [];
|
||||
private (int W, int H) _size;
|
||||
private static readonly TimeSpan MaxGap = TimeSpan.FromMilliseconds(750);
|
||||
private const int SwitchFrames = 5;
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
_tracks.Clear();
|
||||
_size = default;
|
||||
}
|
||||
|
||||
public void Update(IReadOnlyList<Hand> hands, (int W, int H) size, DateTime now)
|
||||
{
|
||||
if (_size != size) Reset();
|
||||
_size = size;
|
||||
_tracks.RemoveAll(t => now - t.LastSeen > MaxGap || now < t.LastSeen || t.MissedFrames >= 5);
|
||||
|
||||
// 一对一匹配,不能使用检测列表顺序或本帧左右手标签作为身份。
|
||||
var candidates = new List<(int Hand, Track Track, double Distance)>();
|
||||
for (var i = 0; i < hands.Count; i++)
|
||||
{
|
||||
foreach (var track in _tracks)
|
||||
{
|
||||
var (x, y) = hands[i].Rect.Center;
|
||||
var (tx, ty) = track.Rect.Center;
|
||||
var scale = Math.Max(1, (Math.Max(hands[i].Rect.W, hands[i].Rect.H) +
|
||||
Math.Max(track.Rect.W, track.Rect.H)) / 2);
|
||||
var distance = Math.Sqrt((x - tx) * (x - tx) + (y - ty) * (y - ty)) / scale;
|
||||
if (distance <= 0.65) candidates.Add((i, track, distance));
|
||||
}
|
||||
}
|
||||
|
||||
var matches = new Dictionary<int, Track>();
|
||||
var used = new HashSet<Track>();
|
||||
foreach (var candidate in candidates.OrderBy(c => c.Distance))
|
||||
{
|
||||
if (matches.ContainsKey(candidate.Hand) || used.Contains(candidate.Track)) continue;
|
||||
matches.Add(candidate.Hand, candidate.Track);
|
||||
used.Add(candidate.Track);
|
||||
}
|
||||
|
||||
foreach (var track in _tracks.Where(t => !used.Contains(t)))
|
||||
{
|
||||
track.MissedFrames++;
|
||||
track.Pending = HandType.Unknown;
|
||||
track.PendingFrames = 0;
|
||||
}
|
||||
|
||||
for (var i = 0; i < hands.Count; i++)
|
||||
{
|
||||
var hand = hands[i];
|
||||
var p = hand.RightHandProbability;
|
||||
var valid = p.HasValue && float.IsFinite(p.Value) && p.Value is >= 0 and <= 1;
|
||||
var decisive = valid
|
||||
? p <= 0.35f ? HandType.Left : p >= 0.65f ? HandType.Right : HandType.Unknown
|
||||
: HandType.Unknown;
|
||||
|
||||
if (!matches.TryGetValue(i, out var track))
|
||||
{
|
||||
// 首次沿用原分类,无需等待五帧才显示骨架。
|
||||
track = new Track { Label = valid ? hand.HandType : HandType.Unknown };
|
||||
_tracks.Add(track);
|
||||
}
|
||||
else if (track.Label == HandType.Unknown && decisive != HandType.Unknown)
|
||||
{
|
||||
track.Label = decisive;
|
||||
}
|
||||
|
||||
if (decisive != HandType.Unknown && decisive != track.Label)
|
||||
{
|
||||
track.PendingFrames = track.Pending == decisive ? track.PendingFrames + 1 : 1;
|
||||
track.Pending = decisive;
|
||||
if (track.PendingFrames >= SwitchFrames)
|
||||
{
|
||||
track.Label = decisive;
|
||||
track.PendingFrames = 0;
|
||||
track.Pending = HandType.Unknown;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
track.Pending = HandType.Unknown;
|
||||
track.PendingFrames = 0;
|
||||
}
|
||||
|
||||
track.Rect = hand.Rect;
|
||||
track.LastSeen = now;
|
||||
track.MissedFrames = 0;
|
||||
hand.HandType = track.Label;
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class Track
|
||||
{
|
||||
public DetRect Rect;
|
||||
public DateTime LastSeen;
|
||||
public int MissedFrames;
|
||||
public HandType Label;
|
||||
public HandType Pending;
|
||||
public int PendingFrames;
|
||||
}
|
||||
}
|
||||
@ -31,6 +31,7 @@ public class MediaPipeHandDetector : IDisposable
|
||||
private float _palmThreshold = DefaultPalmThreshold;
|
||||
private float _keypointThreshold = DefaultKeypointThreshold;
|
||||
private int _maxHands = 2;
|
||||
private readonly HandednessStabilizer _handedness = new();
|
||||
|
||||
/// <summary>模型是否就绪(缺文件时上层跳过手部判定,不报错)</summary>
|
||||
public bool IsReady => _palm is not null && _landmark is not null;
|
||||
@ -116,6 +117,7 @@ public class MediaPipeHandDetector : IDisposable
|
||||
}
|
||||
}
|
||||
|
||||
_handedness.Update(hands, (bgr.Width, bgr.Height), DateTime.UtcNow);
|
||||
return hands;
|
||||
}
|
||||
|
||||
@ -339,7 +341,7 @@ public class MediaPipeHandDetector : IDisposable
|
||||
Confidence = 0.9f,
|
||||
};
|
||||
|
||||
// 该导出带 hand_score / lefthand_0_or_righthand_1,直接用
|
||||
// 该导出带 hand_score / lefthand_0_or_righthand_1,分别读取检测分数和左右手分类。
|
||||
var scoreTensor = Named(items, "hand_score");
|
||||
if (scoreTensor is not null)
|
||||
{
|
||||
@ -357,8 +359,8 @@ public class MediaPipeHandDetector : IDisposable
|
||||
var label = First(handedTensor);
|
||||
if (label is not null)
|
||||
{
|
||||
// 字段名 lefthand_0_or_righthand_1:0=左 1=右
|
||||
hand.HandType = label.Value >= 0.5f ? HandType.Right : HandType.Left;
|
||||
// 输出的左右手采用镜像约定;先校正到当前未镜像图像,再进入稳定器。
|
||||
HandednessDecoder.ApplyUnmirrored(hand, label.Value);
|
||||
}
|
||||
}
|
||||
|
||||
@ -488,6 +490,7 @@ public class MediaPipeHandDetector : IDisposable
|
||||
/// <inheritdoc />
|
||||
public void Dispose()
|
||||
{
|
||||
_handedness.Reset();
|
||||
_palm?.Dispose();
|
||||
_landmark?.Dispose();
|
||||
_palm = null;
|
||||
|
||||
@ -2,6 +2,7 @@ using Microsoft.ML.OnnxRuntime;
|
||||
using Microsoft.ML.OnnxRuntime.Tensors;
|
||||
using OpenCvSharp;
|
||||
using SopHelper.Engine.Common;
|
||||
using YamlDotNet.Serialization;
|
||||
|
||||
namespace SopHelper.Engine.Inference;
|
||||
|
||||
@ -18,6 +19,8 @@ public class YoloDetector : IDisposable
|
||||
private float _nmsThreshold = 0.45f;
|
||||
private int _inputSize = 640;
|
||||
|
||||
public IReadOnlyList<string> ClassNames => _classNames;
|
||||
|
||||
/// <summary>模型是否就绪</summary>
|
||||
public bool IsReady => _session is not null;
|
||||
|
||||
@ -45,7 +48,6 @@ public class YoloDetector : IDisposable
|
||||
using var options = Options(true);
|
||||
_session = new InferenceSession(modelPath, options);
|
||||
UsingGpu = true;
|
||||
return;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@ -53,9 +55,30 @@ public class YoloDetector : IDisposable
|
||||
}
|
||||
}
|
||||
|
||||
using var cpuOptions = Options(false);
|
||||
_session = new InferenceSession(modelPath, cpuOptions);
|
||||
UsingGpu = false;
|
||||
try
|
||||
{
|
||||
if (_session is null)
|
||||
{
|
||||
using var cpuOptions = Options(false);
|
||||
_session = new InferenceSession(modelPath, cpuOptions);
|
||||
UsingGpu = false;
|
||||
}
|
||||
var metadata = _session.ModelMetadata.CustomMetadataMap;
|
||||
if (metadata.TryGetValue("names", out var names))
|
||||
{
|
||||
var labels = new DeserializerBuilder().Build().Deserialize<Dictionary<int, string>>(names);
|
||||
if (labels is not null && labels.Count > 0)
|
||||
{
|
||||
if (!labels.Keys.Order().SequenceEqual(Enumerable.Range(0, labels.Count)))
|
||||
throw new InvalidDataException("模型类别索引必须从 0 连续编号");
|
||||
if (_classNames.Length == 0) _classNames = labels.OrderBy(p => p.Key).Select(p => p.Value).ToArray();
|
||||
else if (_classNames.Length != labels.Count)
|
||||
throw new InvalidDataException($"模型包含 {labels.Count} 个类别,配方却配置了 {_classNames.Length} 个,请使用与模型一致的类别表");
|
||||
}
|
||||
}
|
||||
if (_classNames.Length == 0) throw new InvalidDataException("模型没有类别名称,请填写类别表或使用含 names 元数据的 ONNX");
|
||||
}
|
||||
catch { Dispose(); throw; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -205,7 +228,7 @@ public class YoloDetector : IDisposable
|
||||
});
|
||||
}
|
||||
}
|
||||
else
|
||||
else if (t.Dimensions.Length == 3 && t.Dimensions[2] == 6)
|
||||
{
|
||||
// YOLO26 / 端到端版:[1, N, 6] = [x1, y1, x2, y2, score, class]
|
||||
var n = t.Dimensions.Length >= 2 ? t.Dimensions[1] : 0;
|
||||
@ -232,6 +255,10 @@ public class YoloDetector : IDisposable
|
||||
});
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new InvalidDataException($"不支持的检测输出 [{string.Join(",", t.Dimensions.ToArray())}],请检查类别表和 ONNX 导出设置");
|
||||
}
|
||||
|
||||
list.AddRange(Nms(candidates));
|
||||
|
||||
|
||||
@ -83,13 +83,18 @@ public class DetectionPipeline : IDisposable
|
||||
{
|
||||
_options = options;
|
||||
Warnings = [];
|
||||
_yolo.Dispose();
|
||||
|
||||
if (options.YoloModelPath is not null)
|
||||
{
|
||||
if (File.Exists(options.YoloModelPath))
|
||||
{
|
||||
_yolo.Load(options.YoloModelPath, options.YoloClasses, options.YoloInputSize, options.PreferGpu);
|
||||
if (_yolo.GpuFallbackReason is not null) Warnings.Add($"YOLO GPU 不可用,已回退 CPU:{_yolo.GpuFallbackReason}");
|
||||
try
|
||||
{
|
||||
_yolo.Load(options.YoloModelPath, options.YoloClasses, options.YoloInputSize, options.PreferGpu);
|
||||
if (_yolo.GpuFallbackReason is not null) Warnings.Add($"YOLO GPU 不可用,已回退 CPU:{_yolo.GpuFallbackReason}");
|
||||
}
|
||||
catch (Exception ex) { Warnings.Add("目标检测模型加载失败:" + ex.Message); }
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@ -47,6 +47,10 @@ public class SopBody
|
||||
/// </summary>
|
||||
public class SopSettings
|
||||
{
|
||||
/// <summary>手动相机曝光(微秒);空值保留相机当前设置。</summary>
|
||||
[YamlDotNet.Serialization.YamlMember(DefaultValuesHandling = YamlDotNet.Serialization.DefaultValuesHandling.OmitNull)]
|
||||
public double? ExposureTimeUs { get; set; }
|
||||
|
||||
/// <summary>全局置信度阈值</summary>
|
||||
public float ConfidenceThreshold { get; set; } = 0.6f;
|
||||
|
||||
|
||||
13
tests/HandednessSmoke/HandednessSmoke.csproj
Normal file
13
tests/HandednessSmoke/HandednessSmoke.csproj
Normal file
@ -0,0 +1,13 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="../../src/SopHelper.Engine/Common/Types.cs" Link="Types.cs" />
|
||||
<Compile Include="../../src/SopHelper.Engine/Inference/HandednessStabilizer.cs" Link="HandednessStabilizer.cs" />
|
||||
<Compile Include="../../src/SopHelper.Engine/Inference/HandednessDecoder.cs" Link="HandednessDecoder.cs" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
121
tests/HandednessSmoke/Program.cs
Normal file
121
tests/HandednessSmoke/Program.cs
Normal file
@ -0,0 +1,121 @@
|
||||
using SopHelper.Engine.Common;
|
||||
using SopHelper.Engine.Inference;
|
||||
|
||||
var stabilizer = new HandednessStabilizer();
|
||||
var now = new DateTime(2026, 1, 1, 0, 0, 0, DateTimeKind.Utc);
|
||||
var checks = 0;
|
||||
Hand Make(float? p, float x = 100) => new()
|
||||
{
|
||||
Rect = new DetRect(x, 100, 100, 100),
|
||||
RightHandProbability = p,
|
||||
HandType = p is null ? HandType.Unknown : p >= 0.5f ? HandType.Right : HandType.Left,
|
||||
};
|
||||
void Frame(params Hand[] hands)
|
||||
{
|
||||
now = now.AddMilliseconds(33);
|
||||
stabilizer.Update(hands, (1280, 720), now);
|
||||
}
|
||||
void Expect(Hand hand, HandType expected, string message)
|
||||
{
|
||||
if (hand.HandType != expected) throw new Exception(message);
|
||||
checks++;
|
||||
}
|
||||
|
||||
var first = Make(0.1f);
|
||||
Frame(first);
|
||||
Expect(first, HandType.Left, "首次显示不应延迟");
|
||||
foreach (var p in new[] { 0.51f, 0.49f, 0.6f, 0.4f, 0.95f, 0.1f, 0.9f, 0.1f })
|
||||
{
|
||||
var hand = Make(p);
|
||||
Frame(hand);
|
||||
Expect(hand, HandType.Left, "临界值或孤立误判不应切换");
|
||||
}
|
||||
for (var i = 1; i <= 5; i++)
|
||||
{
|
||||
var hand = Make(0.9f, 100 + i * 5);
|
||||
Frame(hand);
|
||||
Expect(hand, i < 5 ? HandType.Left : HandType.Right, "持续明确的新证据应在第五帧切换");
|
||||
}
|
||||
|
||||
stabilizer.Reset();
|
||||
Frame(Make(0.1f, 100), Make(0.9f, 400));
|
||||
for (var i = 0; i < 12; i++)
|
||||
{
|
||||
var left = Make(i % 3 == 0 ? 0.9f : 0.1f, 100 + i * 3);
|
||||
var right = Make(i % 3 == 0 ? 0.1f : 0.9f, 400 - i * 3);
|
||||
if (i % 2 == 0) Frame(right, left); else Frame(left, right);
|
||||
Expect(left, HandType.Left, "双手结果换序不应串标签");
|
||||
Expect(right, HandType.Right, "双手应各自稳定");
|
||||
}
|
||||
|
||||
stabilizer.Reset();
|
||||
Frame(Make(0.1f));
|
||||
for (var i = 0; i < 4; i++) Frame(Make(0.9f));
|
||||
Frame();
|
||||
var afterMiss = Make(0.9f);
|
||||
Frame(afterMiss);
|
||||
Expect(afterMiss, HandType.Left, "短暂漏检保留标签,但打断连续切换计数");
|
||||
for (var i = 0; i < 5; i++) Frame();
|
||||
var reenter = Make(0.9f);
|
||||
Frame(reenter);
|
||||
Expect(reenter, HandType.Right, "连续漏检后重新出现不应继承旧标签");
|
||||
|
||||
stabilizer.Reset();
|
||||
Frame(Make(0.1f));
|
||||
now = now.AddSeconds(1);
|
||||
var afterPause = Make(0.9f);
|
||||
Frame(afterPause);
|
||||
Expect(afterPause, HandType.Right, "长时间间隔应过期");
|
||||
|
||||
stabilizer.Reset();
|
||||
Frame(Make(0.1f));
|
||||
var far = Make(0.9f, 700);
|
||||
Frame(far);
|
||||
Expect(far, HandType.Right, "远处新手不应继承旧标签");
|
||||
var resized = Make(0.9f, 100);
|
||||
stabilizer.Update([resized], (640, 480), now.AddMilliseconds(33));
|
||||
Expect(resized, HandType.Right, "分辨率变化应重置");
|
||||
|
||||
stabilizer.Reset();
|
||||
var unknown = Make(null);
|
||||
Frame(unknown);
|
||||
Expect(unknown, HandType.Unknown, "缺少输出不应臆造分类");
|
||||
var known = Make(0.1f);
|
||||
Frame(known);
|
||||
Expect(known, HandType.Left, "未知标签应能恢复");
|
||||
foreach (var p in new[] { float.NaN, float.PositiveInfinity, -1f, 2f })
|
||||
{
|
||||
var invalid = Make(p);
|
||||
Frame(invalid);
|
||||
Expect(invalid, HandType.Left, "非法输出不应触发切换");
|
||||
}
|
||||
stabilizer.Reset();
|
||||
var afterReset = Make(0.9f);
|
||||
Frame(afterReset);
|
||||
Expect(afterReset, HandType.Right, "模型重载重置后不应保留标签");
|
||||
stabilizer.Reset();
|
||||
var actualLeft = Make(null, 100);
|
||||
var actualRight = Make(null, 400);
|
||||
HandednessDecoder.ApplyUnmirrored(actualLeft, 0.9f);
|
||||
HandednessDecoder.ApplyUnmirrored(actualRight, 0.1f);
|
||||
Frame(actualLeft, actualRight);
|
||||
Expect(actualLeft, HandType.Left, "未镜像输入的模型高值应映射为实际左手");
|
||||
Expect(actualRight, HandType.Right, "未镜像输入的模型低值应映射为实际右手");
|
||||
if (Math.Abs(actualLeft.RightHandProbability!.Value - 0.1f) > 0.0001f ||
|
||||
Math.Abs(actualRight.RightHandProbability!.Value - 0.9f) > 0.0001f)
|
||||
throw new Exception("稳定器必须收到校正后的概率");
|
||||
for (var i = 0; i < 3; i++)
|
||||
{
|
||||
var jitter = Make(null, 100);
|
||||
HandednessDecoder.ApplyUnmirrored(jitter, 0.05f);
|
||||
Frame(jitter);
|
||||
Expect(jitter, HandType.Left, "镜像校正不能绕过跨帧稳定");
|
||||
}
|
||||
foreach (var p in new[] { float.NaN, float.PositiveInfinity, -1f, 2f })
|
||||
{
|
||||
var invalid = Make(0.9f);
|
||||
HandednessDecoder.ApplyUnmirrored(invalid, p);
|
||||
Expect(invalid, HandType.Unknown, "非法模型输出应保持未知");
|
||||
if (invalid.RightHandProbability is not null) throw new Exception("非法概率未清除");
|
||||
}
|
||||
Console.WriteLine($"PASS: {checks} handedness stability and convention checks");
|
||||
@ -61,6 +61,7 @@ internal static class Program
|
||||
});
|
||||
saveVm.Recipe.Name = "首次保存";
|
||||
saveVm.Recipe.FileName = "repeat-save";
|
||||
saveVm.Recipe.Settings.ExposureTimeUs = 12500;
|
||||
var editedRecipe = saveVm.Recipe;
|
||||
// 未注册关闭监听器:保存如果仍尝试关闭弹窗,就不能正常完成。
|
||||
saveVm.SaveCommand.Execute();
|
||||
@ -69,11 +70,21 @@ internal static class Program
|
||||
SopConfigLoader.Load(savePath).Sop.Name != "首次保存")
|
||||
throw new Exception("首次保存后的状态或文件不正确:" + string.Join(";", saveVm.Warnings));
|
||||
saveVm.Recipe.Name = "继续修改并保存";
|
||||
var restoredSettings = new RecipeSettingsNode();
|
||||
restoredSettings.CopyFrom(SopConfigLoader.Load(savePath).Sop.Settings);
|
||||
if (restoredSettings.ExposureTimeUs != 12500) throw new Exception("曝光保存重开丢失");
|
||||
saveVm.Recipe.Settings.ExposureTimeUs = null;
|
||||
saveVm.SaveCommand.Execute();
|
||||
if (!saveVm.SaveStatus.StartsWith("已保存") || !ReferenceEquals(editedRecipe, saveVm.Recipe) ||
|
||||
notifications.Count != 2 || notifications.Any(name => name != "repeat-save.yaml") ||
|
||||
SopConfigLoader.Load(savePath).Sop.Name != "继续修改并保存" || Directory.GetFiles(saveDirectory).Length != 1)
|
||||
throw new Exception("连续保存未更新原配方文件");
|
||||
if (SopConfigLoader.Load(savePath).Sop.Settings.ExposureTimeUs is not null)
|
||||
throw new Exception("曝光留空后仍保留旧值");
|
||||
saveVm.Recipe.Settings.ExposureTimeUs = -1;
|
||||
saveVm.SaveCommand.Execute();
|
||||
if (!saveVm.Warnings.Any(w => w.Contains("相机曝光必须大于"))) throw new Exception("允许保存无效曝光值");
|
||||
saveVm.Recipe.Settings.ExposureTimeUs = null;
|
||||
Console.WriteLine("PASS: 保存不请求关闭、编辑状态保留、新建转为编辑、连续保存更新同一文件并通知主页");
|
||||
saveVm.Recipe.AddStepCommand.Execute();
|
||||
if (!saveVm.Warnings.Any(w => w.Contains("未设置完成条件")))
|
||||
@ -82,6 +93,16 @@ internal static class Program
|
||||
stepView.Measure(new Size(1020, 720));
|
||||
stepView.Arrange(new Rect(0, 0, 1020, 720));
|
||||
stepView.UpdateLayout();
|
||||
var editorTabs = Descendants(stepView).OfType<TabControl>().Single();
|
||||
editorTabs.SelectedItem = editorTabs.Items.OfType<TabItem>().Single(t => Equals(t.Header, "检测模型"));
|
||||
stepView.UpdateLayout();
|
||||
var exposureInput = (TextBox)stepView.FindName("CameraExposureInput");
|
||||
exposureInput.Text = "18000";
|
||||
exposureInput.GetBindingExpression(TextBox.TextProperty)!.UpdateSource();
|
||||
if (saveVm.Recipe.Settings.ExposureTimeUs != 18000) throw new Exception("检测模型页曝光输入未绑定配方");
|
||||
saveVm.Recipe.Settings.ExposureTimeUs = null;
|
||||
editorTabs.SelectedIndex = 0;
|
||||
stepView.UpdateLayout();
|
||||
SelectMethod(stepView, ConditionMethod.TimeElapsed);
|
||||
if (saveVm.Warnings.Any(w => w.Contains("未设置完成条件")))
|
||||
throw new Exception("选择方法后缺少判定的提示未实时更新");
|
||||
@ -173,6 +194,7 @@ internal static class Program
|
||||
|
||||
var config = new SopConfig();
|
||||
config.Sop.Name = "画框标定";
|
||||
config.Sop.Settings.ExposureTimeUs = 12000;
|
||||
config.Sop.Regions["work"] = new RegionDef { X1 = 200, Y1 = 150, X2 = 950, Y2 = 650, Name = "操作区域", Color = "#00B8D4" };
|
||||
using var fake = new CaptureCamera();
|
||||
using var real = args.Contains("--hardware") ? new CameraService() : null;
|
||||
@ -189,6 +211,17 @@ internal static class Program
|
||||
while (vm.IsCapturing && DateTime.UtcNow < deadline) await Task.Delay(20);
|
||||
if (vm.IsCapturing || vm.PreviewImage is null) throw new Exception("取图失败:" + vm.PreviewStatus);
|
||||
if (!vm.PreviewImage.IsFrozen || camera.IsConnected || camera.IsGrabbing) throw new Exception("图像未冻结或取图后未释放相机");
|
||||
if (real is null && fake.ExposureAtStart != 12000) throw new Exception("区域取图前未应用配方曝光");
|
||||
if (real is null)
|
||||
{
|
||||
var starts = fake.StartCount;
|
||||
fake.RejectExposure = true;
|
||||
vm.CaptureImageCommand.Execute();
|
||||
while (vm.IsCapturing) await Task.Delay(20);
|
||||
if (!vm.PreviewStatus.Contains("失败") || fake.StartCount != starts || fake.IsConnected)
|
||||
throw new Exception("曝光设置失败后仍采集或未释放相机");
|
||||
fake.RejectExposure = false;
|
||||
}
|
||||
if (vm.Recipe.SelectedRegion is null) throw new Exception("区域未自动选中");
|
||||
vm.Recipe.SelectedRegion.SetBounds(new Int32Rect(200, 150, 750, 500));
|
||||
var saved = vm.Recipe.ToConfig().Sop.Regions["work"];
|
||||
@ -328,6 +361,16 @@ internal static class Program
|
||||
|
||||
internal sealed class CaptureCamera : ICameraService
|
||||
{
|
||||
public bool RejectExposure { get; set; }
|
||||
public int StartCount { get; private set; }
|
||||
public double? ExposureAtStart { get; private set; }
|
||||
private double? _exposure;
|
||||
public Task SetExposureTimeAsync(double microseconds)
|
||||
{
|
||||
if (!IsConnected || IsGrabbing || RejectExposure) throw new InvalidOperationException("测试曝光设置失败");
|
||||
_exposure = microseconds;
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
public bool IsConnected { get; private set; }
|
||||
public bool IsGrabbing { get; private set; }
|
||||
public event Action<CameraFrame>? FrameArrived;
|
||||
@ -339,6 +382,8 @@ internal sealed class CaptureCamera : ICameraService
|
||||
public Task<bool> ConnectAsync(CameraInfo camera) { IsConnected = true; ConnectionChanged?.Invoke(true); return Task.FromResult(true); }
|
||||
public async Task<bool> StartAsync()
|
||||
{
|
||||
StartCount++;
|
||||
ExposureAtStart = _exposure;
|
||||
IsGrabbing = true;
|
||||
await Task.Run(() =>
|
||||
{
|
||||
|
||||
32
tests/YoloModelSmoke/Program.cs
Normal file
32
tests/YoloModelSmoke/Program.cs
Normal file
@ -0,0 +1,32 @@
|
||||
using OpenCvSharp;
|
||||
using SopHelper.Engine.Inference;
|
||||
|
||||
if (args.Length == 0) throw new ArgumentException("用法:YoloModelSmoke model.onnx [image.jpg]");
|
||||
using var detector = new YoloDetector();
|
||||
detector.Load(args[0], [], preferGpu: false);
|
||||
if (!detector.IsReady || detector.ClassNames.Count == 0) throw new Exception("未读取模型类别元数据");
|
||||
Console.WriteLine($"PASS: 从 ONNX 元数据读取 {detector.ClassNames.Count} 个类别");
|
||||
using var frame = args.Length > 1 ? Cv2.ImRead(args[1]) : new Mat(480, 640, MatType.CV_8UC3, Scalar.Black);
|
||||
if (frame.Empty()) throw new Exception("测试图像无法读取");
|
||||
var detections = detector.Detect(frame);
|
||||
if (detections.Any(d => !float.IsFinite(d.Rect.X) || !float.IsFinite(d.Confidence) ||
|
||||
d.Confidence is < 0 or > 1 || !detector.ClassNames.Contains(d.Label)))
|
||||
throw new Exception("检测结果的坐标、置信度或类别无效");
|
||||
if (args.Length > 1 && detections.Count == 0) throw new Exception("真实样图未检出任何目标");
|
||||
foreach (var d in detections) Console.WriteLine($"{d.Label}: {d.Confidence:P0} ({d.Rect.X:F0}, {d.Rect.Y:F0}, {d.Rect.W:F0}, {d.Rect.H:F0})");
|
||||
Console.WriteLine($"PASS: 原生 ONNX 推理与输出解码,检出 {detections.Count} 个目标");
|
||||
try
|
||||
{
|
||||
detector.Load(args[0], Enumerable.Repeat("错误类别", detector.ClassNames.Count + 1).ToArray(), preferGpu: false);
|
||||
throw new Exception("未拒绝错误的类别数量");
|
||||
}
|
||||
catch (InvalidDataException)
|
||||
{
|
||||
if (detector.IsReady) throw new Exception("加载失败后保留了旧模型");
|
||||
Console.WriteLine("PASS: 拒绝类别数量不匹配,加载失败后释放模型");
|
||||
}
|
||||
|
||||
detector.Load(args[0], [], preferGpu: false);
|
||||
detector.Load(Path.Combine(Path.GetDirectoryName(args[0])!, "missing-model.onnx"), [], preferGpu: false);
|
||||
if (detector.IsReady) throw new Exception("模型路径失效后仍使用旧模型");
|
||||
Console.WriteLine("PASS: 切换到缺失模型时释放旧模型");
|
||||
12
tests/YoloModelSmoke/YoloModelSmoke.csproj
Normal file
12
tests/YoloModelSmoke/YoloModelSmoke.csproj
Normal file
@ -0,0 +1,12 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="../../src/SopHelper.Engine/SopHelper.Engine.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
Loading…
Reference in New Issue
Block a user