FocusAnalyzerControl.xaml 25 KB

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