FocusAnalyzerl.xaml 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528
  1. <UserControl x:Class="TeamAAS_VP.Views.DebugMod.FocusAnalyzer"
  2. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  3. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  4. xmlns:local="clr-namespace:TeamAAS_VP.Views.DebugMod"
  5. xmlns:oxy="http://oxyplot.org/wpf"
  6. xmlns:prism="http://prismlibrary.com/"
  7. xmlns:c="clr-namespace:TeamAAS_VP.ValueConverter"
  8. xmlns:enums="clr-namespace:TeamAAS_VP.Enums"
  9. xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  10. xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  11. xmlns:vm="clr-namespace:TeamAAS_VP.ViewModels.DebugMod"
  12. xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
  13. xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls"
  14. xmlns:b="http://schemas.microsoft.com/xaml/behaviors"
  15. xmlns:sys="clr-namespace:System;assembly=mscorlib"
  16. xmlns:uControl="clr-namespace:TeamAAS_VP.Controls"
  17. xmlns:convert="clr-namespace:TeamAAS_VP.ValueConverter"
  18. xmlns:localbehaviors="clr-namespace:TeamAAS_VP.Behaviors"
  19. xmlns:lex="http://wpflocalizeextension.codeplex.com"
  20. lex:LocalizeDictionary.DesignCulture="zh-CN"
  21. lex:ResxLocalizationProvider.DefaultAssembly="TeamAAS-VP"
  22. lex:ResxLocalizationProvider.DefaultDictionary="Lang"
  23. prism:ViewModelLocator.AutoWireViewModel="True"
  24. mc:Ignorable="d"
  25. d:Width="1024"
  26. d:Height="768"
  27. d:Background="White"
  28. d:DataContext="{d:DesignInstance Type=vm:FocusAnalyzerViewModel}"
  29. FontFamily="{DynamicResource DefaultFont}">
  30. <UserControl.Resources>
  31. <!-- 转换器 -->
  32. <c:ObjectToVisibilityConverter x:Key="NullToVisibilityConverter" />
  33. <c:ObjectToVisibilityConverter x:Key="InvertNullToVisibilityConverter"
  34. Invert="True" />
  35. <c:EnumToBooleanConverter x:Key="EnumToBooleanConverter" />
  36. <c:RoiToTextConverter x:Key="RoiToTextConverter" />
  37. <!-- 样式 -->
  38. <Style x:Key="CardStyle"
  39. TargetType="Border">
  40. <Setter Property="Background"
  41. Value="#FFFFFF" />
  42. <Setter Property="CornerRadius"
  43. Value="4" />
  44. <Setter Property="BorderBrush"
  45. Value="#E0E0E0" />
  46. <Setter Property="BorderThickness"
  47. Value="1" />
  48. <Setter Property="Padding"
  49. Value="8" />
  50. <Setter Property="Margin"
  51. Value="4" />
  52. </Style>
  53. <Style x:Key="ToolButtonStyle"
  54. TargetType="RadioButton">
  55. <Setter Property="Width"
  56. Value="30" />
  57. <Setter Property="Height"
  58. Value="30" />
  59. <Setter Property="Margin"
  60. Value="2" />
  61. <Setter Property="Cursor"
  62. Value="Hand" />
  63. <Setter Property="Template">
  64. <Setter.Value>
  65. <ControlTemplate TargetType="RadioButton">
  66. <Border Background="{TemplateBinding Background}"
  67. BorderBrush="{TemplateBinding BorderBrush}"
  68. BorderThickness="1"
  69. CornerRadius="4">
  70. <ContentPresenter HorizontalAlignment="Center"
  71. VerticalAlignment="Center" />
  72. </Border>
  73. <ControlTemplate.Triggers>
  74. <Trigger Property="IsChecked"
  75. Value="True">
  76. <Setter Property="Background"
  77. Value="#007ACC" />
  78. <Setter Property="Foreground"
  79. Value="White" />
  80. </Trigger>
  81. <Trigger Property="IsMouseOver"
  82. Value="True">
  83. <Setter Property="Background"
  84. Value="#F0F0F0" />
  85. </Trigger>
  86. </ControlTemplate.Triggers>
  87. </ControlTemplate>
  88. </Setter.Value>
  89. </Setter>
  90. </Style>
  91. <!-- ROI控制点样式 -->
  92. <Style x:Key="RoiHandleStyle"
  93. TargetType="Ellipse">
  94. <Setter Property="Width"
  95. Value="8" />
  96. <Setter Property="Height"
  97. Value="8" />
  98. <Setter Property="Fill"
  99. Value="White" />
  100. <Setter Property="Stroke"
  101. Value="Red" />
  102. <Setter Property="StrokeThickness"
  103. Value="1" />
  104. <Setter Property="Cursor"
  105. Value="SizeAll" />
  106. </Style>
  107. <!-- 旋转控制点样式 -->
  108. <Style x:Key="RotateHandleStyle"
  109. TargetType="Path">
  110. <Setter Property="Fill"
  111. Value="Red" />
  112. <Setter Property="Stroke"
  113. Value="White" />
  114. <Setter Property="StrokeThickness"
  115. Value="1" />
  116. <Setter Property="Cursor"
  117. Value="SizeAll" />
  118. <Setter Property="Data"
  119. Value="M 0,0 L 5,0 L 2.5,5 Z" />
  120. </Style>
  121. </UserControl.Resources>
  122. <Grid>
  123. <Grid.RowDefinitions>
  124. <RowDefinition Height="Auto" />
  125. <RowDefinition Height="*" />
  126. </Grid.RowDefinitions>
  127. <!-- 工具栏 -->
  128. <Border Grid.Row="0"
  129. Background="#F5F5F5"
  130. BorderBrush="#E0E0E0"
  131. BorderThickness="0,0,0,1"
  132. Padding="10,8">
  133. <StackPanel Orientation="Horizontal">
  134. <Button Content="打开图像"
  135. Command="{Binding LoadImageCommand}"
  136. Padding="15,5"
  137. Margin="0,0,8,0" />
  138. <Button Content="检测棋盘格"
  139. Command="{Binding DetectChessboardCommand}"
  140. Padding="15,5"
  141. Margin="0,0,8,0" />
  142. <Separator Style="{StaticResource {x:Static ToolBar.SeparatorStyleKey}}"
  143. Margin="8,0" />
  144. <TextBlock Text="{Binding StatusText}"
  145. VerticalAlignment="Center"
  146. Foreground="#666"
  147. Margin="8,0,0,0" />
  148. </StackPanel>
  149. </Border>
  150. <!-- 主内容区 -->
  151. <Grid Grid.Row="1">
  152. <Grid.ColumnDefinitions>
  153. <ColumnDefinition Width="*" />
  154. <ColumnDefinition Width="280" />
  155. </Grid.ColumnDefinitions>
  156. <!-- 左侧:图像显示区 -->
  157. <Border Grid.Column="0"
  158. Style="{StaticResource CardStyle}"
  159. Margin="10">
  160. <Grid>
  161. <!-- 图像容器 -->
  162. <Grid x:Name="ImageContainer">
  163. <!-- 图像显示 -->
  164. <Image x:Name="ImageDisplay"
  165. Source="{Binding CurrentImage}"
  166. Stretch="Uniform">
  167. </Image>
  168. <!-- ROI绘制层 -->
  169. <Canvas x:Name="RoiCanvas"
  170. Background="Transparent"
  171. IsHitTestVisible="True">
  172. <!-- ROI矩形(带旋转) -->
  173. <Rectangle x:Name="RoiRectangle"
  174. Fill="Transparent">
  175. <Rectangle.Style>
  176. <Style TargetType="Rectangle">
  177. <Setter Property="Stroke"
  178. Value="Red" />
  179. <Setter Property="StrokeThickness"
  180. Value="2" />
  181. <Setter Property="StrokeDashArray"
  182. Value="4,4" />
  183. <Setter Property="RenderTransformOrigin"
  184. Value="0.5,0.5" />
  185. <Style.Triggers>
  186. <DataTrigger Binding="{Binding RoiMode}"
  187. Value="Draw">
  188. <Setter Property="StrokeDashArray"
  189. Value="2,2" />
  190. </DataTrigger>
  191. </Style.Triggers>
  192. </Style>
  193. </Rectangle.Style>
  194. <Rectangle.RenderTransform>
  195. <RotateTransform Angle="{Binding CurrentRoi.Angle}" />
  196. </Rectangle.RenderTransform>
  197. </Rectangle>
  198. <!-- 角点控制点 -->
  199. <Ellipse x:Name="TopLeftHandle"
  200. Style="{StaticResource RoiHandleStyle}" />
  201. <Ellipse x:Name="TopRightHandle"
  202. Style="{StaticResource RoiHandleStyle}" />
  203. <Ellipse x:Name="BottomLeftHandle"
  204. Style="{StaticResource RoiHandleStyle}" />
  205. <Ellipse x:Name="BottomRightHandle"
  206. Style="{StaticResource RoiHandleStyle}" />
  207. <!-- 边中点控制点 -->
  208. <Ellipse x:Name="TopHandle"
  209. Style="{StaticResource RoiHandleStyle}" />
  210. <Ellipse x:Name="RightHandle"
  211. Style="{StaticResource RoiHandleStyle}" />
  212. <Ellipse x:Name="BottomHandle"
  213. Style="{StaticResource RoiHandleStyle}" />
  214. <Ellipse x:Name="LeftHandle"
  215. Style="{StaticResource RoiHandleStyle}" />
  216. <!-- 旋转控制点 -->
  217. <Path x:Name="RotateHandle"
  218. Style="{StaticResource RotateHandleStyle}" />
  219. </Canvas>
  220. <!-- 无图像提示 -->
  221. <Border Background="#F9F9F9"
  222. BorderBrush="#E0E0E0"
  223. BorderThickness="2"
  224. CornerRadius="8"
  225. Visibility="{Binding CurrentImage, Converter={StaticResource InvertNullToVisibilityConverter}}">
  226. <StackPanel HorizontalAlignment="Center"
  227. VerticalAlignment="Center">
  228. <TextBlock Text="📷"
  229. FontSize="48"
  230. HorizontalAlignment="Center"
  231. Foreground="#CCC"
  232. Margin="0,0,0,16" />
  233. <TextBlock Text="点击【打开图像】加载棋盘格图片"
  234. FontSize="14"
  235. Foreground="#999"
  236. HorizontalAlignment="Center" />
  237. <Button Content="打开图像"
  238. Command="{Binding LoadImageCommand}"
  239. Margin="0,16,0,0"
  240. Padding="20,8" />
  241. </StackPanel>
  242. </Border>
  243. <!-- 操作提示 -->
  244. <Border Background="#80000000"
  245. CornerRadius="4"
  246. Padding="8"
  247. VerticalAlignment="Bottom"
  248. HorizontalAlignment="Center"
  249. Margin="0,0,0,10"
  250. Visibility="{Binding CurrentImage, Converter={StaticResource NullToVisibilityConverter}}">
  251. <StackPanel>
  252. <TextBlock Text="ROI操作提示"
  253. Foreground="White"
  254. FontWeight="Bold"
  255. Margin="0,0,0,4" />
  256. <TextBlock Text="拖动: 移动ROI"
  257. Foreground="White"
  258. FontSize="11" />
  259. <TextBlock Text="角点拖动: 调整大小"
  260. Foreground="White"
  261. FontSize="11" />
  262. <TextBlock Text="旋转点拖动: 旋转"
  263. Foreground="White"
  264. FontSize="11" />
  265. </StackPanel>
  266. </Border>
  267. </Grid>
  268. </Grid>
  269. </Border>
  270. <!-- 右侧:控制面板 -->
  271. <Grid Grid.Column="1"
  272. Margin="0,10,10,10">
  273. <Grid.RowDefinitions>
  274. <RowDefinition Height="Auto" />
  275. <RowDefinition Height="Auto" />
  276. <RowDefinition Height="Auto" />
  277. <RowDefinition Height="Auto" />
  278. <RowDefinition Height="*" />
  279. </Grid.RowDefinitions>
  280. <!-- ROI工具栏 -->
  281. <Border Grid.Row="0"
  282. Style="{StaticResource CardStyle}">
  283. <StackPanel>
  284. <TextBlock Text="ROI工具"
  285. FontWeight="Bold"
  286. Margin="0,0,0,8" />
  287. <StackPanel Orientation="Horizontal"
  288. HorizontalAlignment="Center">
  289. <!-- 绘制模式 -->
  290. <RadioButton Content="📐"
  291. Style="{StaticResource ToolButtonStyle}"
  292. ToolTip="绘制ROI"
  293. IsChecked="{Binding RoiMode, Converter={StaticResource EnumToBooleanConverter}, ConverterParameter={x:Static enums:RoiOperationMode.Draw}}" />
  294. <!-- 移动模式 -->
  295. <RadioButton Content="↔"
  296. Style="{StaticResource ToolButtonStyle}"
  297. ToolTip="移动ROI"
  298. IsChecked="{Binding RoiMode, Converter={StaticResource EnumToBooleanConverter}, ConverterParameter={x:Static enums:RoiOperationMode.Move}}" />
  299. <!-- 调整大小模式 -->
  300. <RadioButton Content="⤢"
  301. Style="{StaticResource ToolButtonStyle}"
  302. ToolTip="调整大小"
  303. IsChecked="{Binding RoiMode, Converter={StaticResource EnumToBooleanConverter}, ConverterParameter={x:Static enums:RoiOperationMode.Resize}}" />
  304. <!-- 旋转模式 -->
  305. <RadioButton Content="↻"
  306. Style="{StaticResource ToolButtonStyle}"
  307. ToolTip="旋转ROI"
  308. IsChecked="{Binding RoiMode, Converter={StaticResource EnumToBooleanConverter}, ConverterParameter={x:Static enums:RoiOperationMode.Rotate}}" />
  309. <!-- 清除ROI -->
  310. <Button Width="30"
  311. Height="30"
  312. Margin="10,0,0,0"
  313. Padding="0"
  314. Content="&#xE14C;"
  315. ToolTip="清除ROI"
  316. Command="{Binding ClearRoiCommand}">
  317. </Button>
  318. </StackPanel>
  319. <!-- ROI信息 -->
  320. <Border Background="#F5F5F5"
  321. CornerRadius="3"
  322. Padding="6"
  323. Margin="0,8,0,0">
  324. <StackPanel>
  325. <TextBlock Text="ROI信息"
  326. FontWeight="SemiBold"
  327. FontSize="11" />
  328. <TextBlock>
  329. <TextBlock.Text>
  330. <MultiBinding Converter="{StaticResource RoiToTextConverter}">
  331. <Binding Path="CurrentRoi.X" />
  332. <Binding Path="CurrentRoi.Y" />
  333. <Binding Path="CurrentRoi.Width" />
  334. <Binding Path="CurrentRoi.Height" />
  335. <Binding Path="CurrentRoi.Angle" />
  336. </MultiBinding>
  337. </TextBlock.Text>
  338. </TextBlock>
  339. </StackPanel>
  340. </Border>
  341. </StackPanel>
  342. </Border>
  343. <!-- 参数设置 -->
  344. <Border Grid.Row="1"
  345. Style="{StaticResource CardStyle}"
  346. Margin="0,8,0,0">
  347. <StackPanel>
  348. <TextBlock Text="分析参数"
  349. FontWeight="Bold"
  350. Margin="0,0,0,8" />
  351. <Grid>
  352. <Grid.RowDefinitions>
  353. <RowDefinition Height="Auto" />
  354. <RowDefinition Height="Auto" />
  355. <RowDefinition Height="Auto" />
  356. </Grid.RowDefinitions>
  357. <Grid.ColumnDefinitions>
  358. <ColumnDefinition Width="80" />
  359. <ColumnDefinition Width="*" />
  360. </Grid.ColumnDefinitions>
  361. <TextBlock Grid.Row="0"
  362. Grid.Column="0"
  363. Text="算法:"
  364. VerticalAlignment="Center" />
  365. <ComboBox Grid.Row="0"
  366. Grid.Column="1"
  367. ItemsSource="{Binding FocusMethods}"
  368. SelectedValue="{Binding Parameters.FocusMethod}"
  369. Margin="0,0,0,4" />
  370. <TextBlock Grid.Row="1"
  371. Grid.Column="0"
  372. Text="模式:"
  373. VerticalAlignment="Center" />
  374. <ComboBox Grid.Row="1"
  375. Grid.Column="1"
  376. ItemsSource="{Binding AnalysisModes}"
  377. SelectedValue="{Binding Parameters.AnalysisMode}"
  378. Margin="0,0,0,4" />
  379. <TextBlock Grid.Row="2"
  380. Grid.Column="0"
  381. Text="实时分析:"
  382. VerticalAlignment="Center" />
  383. <CheckBox Grid.Row="2"
  384. Grid.Column="1"
  385. IsChecked="{Binding Parameters.EnableRealtimeAnalysis}"
  386. VerticalAlignment="Center" />
  387. </Grid>
  388. </StackPanel>
  389. </Border>
  390. <!-- 控制按钮 -->
  391. <Border Grid.Row="2"
  392. Style="{StaticResource CardStyle}"
  393. Margin="0,8,0,0">
  394. <StackPanel>
  395. <StackPanel Orientation="Horizontal"
  396. HorizontalAlignment="Center">
  397. <Button Content="开始分析"
  398. Command="{Binding StartAnalysisCommand}"
  399. Padding="20,8"
  400. Margin="0,0,8,0" />
  401. <Button Content="停止分析"
  402. Command="{Binding StopAnalysisCommand}"
  403. Padding="20,8" />
  404. </StackPanel>
  405. <StackPanel Orientation="Horizontal"
  406. HorizontalAlignment="Center"
  407. Margin="0,8,0,0">
  408. <Button Content="重置"
  409. Command="{Binding ResetCommand}"
  410. Padding="15,4"
  411. Margin="0,0,8,0" />
  412. <Button Content="导出报告"
  413. Command="{Binding ExportCommand}"
  414. Padding="15,4" />
  415. </StackPanel>
  416. </StackPanel>
  417. </Border>
  418. <!-- 实时结果 -->
  419. <Border Grid.Row="3"
  420. Style="{StaticResource CardStyle}"
  421. Margin="0,8,0,0">
  422. <StackPanel>
  423. <TextBlock Text="实时结果"
  424. FontWeight="Bold"
  425. Margin="0,0,0,8" />
  426. <Grid>
  427. <Grid.ColumnDefinitions>
  428. <ColumnDefinition Width="*" />
  429. <ColumnDefinition Width="*" />
  430. </Grid.ColumnDefinitions>
  431. <StackPanel Grid.Column="0">
  432. <TextBlock Text="清晰度"
  433. FontSize="11"
  434. Foreground="#666" />
  435. <TextBlock Text="{Binding CurrentResult.Sharpness, StringFormat=F2}"
  436. FontSize="18"
  437. FontWeight="Bold"
  438. Foreground="#007ACC" />
  439. <TextBlock Text="{Binding StatusText}"
  440. FontSize="10"
  441. Foreground="#666"
  442. Margin="0,2,0,0" />
  443. </StackPanel>
  444. <StackPanel Grid.Column="1">
  445. <TextBlock Text="质量评分"
  446. FontSize="11"
  447. Foreground="#666" />
  448. <TextBlock Text="{Binding CurrentResult.QualityScore, StringFormat=F1}"
  449. FontSize="18"
  450. FontWeight="Bold"
  451. Foreground="#4CAF50" />
  452. <TextBlock Text="/100"
  453. FontSize="11"
  454. Foreground="#999" />
  455. </StackPanel>
  456. </Grid>
  457. <ProgressBar Value="{Binding CurrentResult.Sharpness}"
  458. Maximum="50"
  459. Height="6"
  460. Margin="0,8,0,0" />
  461. <!-- 最佳值显示 -->
  462. <Border Background="#F8F9FA"
  463. CornerRadius="3"
  464. Padding="6"
  465. Margin="0,8,0,0">
  466. <StackPanel Orientation="Horizontal">
  467. <TextBlock Text="最佳清晰度:"
  468. FontSize="10"
  469. Foreground="#666" />
  470. <TextBlock Text="{Binding BestSharpnessText}"
  471. FontSize="10"
  472. FontWeight="Bold"
  473. Margin="5,0,0,0" />
  474. <TextBlock Text="{Binding FrameCountText}"
  475. FontSize="10"
  476. Foreground="#666"
  477. Margin="10,0,0,0" />
  478. </StackPanel>
  479. </Border>
  480. </StackPanel>
  481. </Border>
  482. <!-- 图表 -->
  483. <Border Grid.Row="4"
  484. Style="{StaticResource CardStyle}"
  485. Margin="0,8,0,0">
  486. <oxy:PlotView Model="{Binding PlotModel}"
  487. Height="200" />
  488. </Border>
  489. </Grid>
  490. </Grid>
  491. </Grid>
  492. </UserControl>