FocusAnalyzerl.xaml 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553
  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="{lex:Loc 打开图像}"
  135. Command="{Binding LoadImageCommand}"
  136. Padding="15,5"
  137. Margin="0,0,8,0"
  138. d:Visibility="Visible"
  139. Visibility="Collapsed" />
  140. <Button Content="{lex:Loc 检测棋盘格}"
  141. Command="{Binding DetectChessboardCommand}"
  142. Padding="15,5"
  143. Margin="0,0,8,0"
  144. d:Visibility="Visible"
  145. Visibility="Collapsed" />
  146. <TextBlock Text="{lex:Loc 相机列表}"
  147. Margin="0,0,8,0" VerticalAlignment="Center" />
  148. <ComboBox ItemsSource="{Binding CameraList}"
  149. SelectedItem="{Binding SelectedCamera}"
  150. MinWidth="100"
  151. Margin="0,0,8,0"
  152. IsEnabled="{Binding IsAnalyzing,Converter={StaticResource InvertBooleanConverter}}">
  153. <ComboBox.ItemTemplate>
  154. <DataTemplate>
  155. <StackPanel Orientation="Horizontal">
  156. <TextBlock Text="{Binding CameraNo}"
  157. VerticalAlignment="Center" />
  158. <TextBlock Text="."
  159. Margin="3,0"
  160. VerticalAlignment="Center" />
  161. <TextBlock Text="{Binding CameraName}"
  162. VerticalAlignment="Center" />
  163. </StackPanel>
  164. </DataTemplate>
  165. </ComboBox.ItemTemplate>
  166. </ComboBox>
  167. <Separator Style="{StaticResource {x:Static ToolBar.SeparatorStyleKey}}"
  168. Margin="8,0" />
  169. <TextBlock Text="{Binding StatusText}"
  170. VerticalAlignment="Center"
  171. Foreground="#666"
  172. Margin="8,0,0,0" />
  173. </StackPanel>
  174. </Border>
  175. <!-- 主内容区 -->
  176. <Grid Grid.Row="1">
  177. <Grid.ColumnDefinitions>
  178. <ColumnDefinition Width="*" />
  179. <ColumnDefinition Width="280" />
  180. </Grid.ColumnDefinitions>
  181. <!-- 左侧:图像显示区 -->
  182. <Border Grid.Column="0"
  183. Style="{StaticResource CardStyle}"
  184. Margin="10">
  185. <Grid>
  186. <!-- 图像容器 -->
  187. <Grid x:Name="ImageContainer">
  188. <!-- 图像显示 -->
  189. <Image x:Name="ImageDisplay"
  190. Source="{Binding CurrentImage}"
  191. Stretch="Uniform">
  192. </Image>
  193. <!-- ROI绘制层 -->
  194. <Canvas x:Name="RoiCanvas"
  195. Background="Transparent"
  196. IsHitTestVisible="True">
  197. <!-- ROI矩形(带旋转) -->
  198. <Rectangle x:Name="RoiRectangle"
  199. Fill="Transparent">
  200. <Rectangle.Style>
  201. <Style TargetType="Rectangle">
  202. <Setter Property="Stroke"
  203. Value="Red" />
  204. <Setter Property="StrokeThickness"
  205. Value="2" />
  206. <Setter Property="StrokeDashArray"
  207. Value="4,4" />
  208. <Setter Property="RenderTransformOrigin"
  209. Value="0.5,0.5" />
  210. <Style.Triggers>
  211. <DataTrigger Binding="{Binding RoiMode}"
  212. Value="Draw">
  213. <Setter Property="StrokeDashArray"
  214. Value="2,2" />
  215. </DataTrigger>
  216. </Style.Triggers>
  217. </Style>
  218. </Rectangle.Style>
  219. <Rectangle.RenderTransform>
  220. <RotateTransform Angle="{Binding CurrentRoi.Angle}" />
  221. </Rectangle.RenderTransform>
  222. </Rectangle>
  223. <!-- 角点控制点 -->
  224. <Ellipse x:Name="TopLeftHandle"
  225. Style="{StaticResource RoiHandleStyle}" />
  226. <Ellipse x:Name="TopRightHandle"
  227. Style="{StaticResource RoiHandleStyle}" />
  228. <Ellipse x:Name="BottomLeftHandle"
  229. Style="{StaticResource RoiHandleStyle}" />
  230. <Ellipse x:Name="BottomRightHandle"
  231. Style="{StaticResource RoiHandleStyle}" />
  232. <!-- 边中点控制点 -->
  233. <Ellipse x:Name="TopHandle"
  234. Style="{StaticResource RoiHandleStyle}" />
  235. <Ellipse x:Name="RightHandle"
  236. Style="{StaticResource RoiHandleStyle}" />
  237. <Ellipse x:Name="BottomHandle"
  238. Style="{StaticResource RoiHandleStyle}" />
  239. <Ellipse x:Name="LeftHandle"
  240. Style="{StaticResource RoiHandleStyle}" />
  241. <!-- 旋转控制点 -->
  242. <Path x:Name="RotateHandle"
  243. Style="{StaticResource RotateHandleStyle}" />
  244. </Canvas>
  245. <!-- 无图像提示 -->
  246. <!--<Border Background="#F9F9F9"
  247. BorderBrush="#E0E0E0"
  248. BorderThickness="2"
  249. CornerRadius="8"
  250. Visibility="{Binding CurrentImage, Converter={StaticResource InvertNullToVisibilityConverter}}">
  251. <StackPanel HorizontalAlignment="Center"
  252. VerticalAlignment="Center">
  253. <TextBlock Text="📷"
  254. FontSize="48"
  255. HorizontalAlignment="Center"
  256. Foreground="#CCC"
  257. Margin="0,0,0,16" />
  258. <TextBlock Text="点击【打开图像】加载棋盘格图片"
  259. FontSize="14"
  260. Foreground="#999"
  261. HorizontalAlignment="Center" />
  262. <Button Content="打开图像"
  263. Command="{Binding LoadImageCommand}"
  264. Margin="0,16,0,0"
  265. Padding="20,8" />
  266. </StackPanel>
  267. </Border>-->
  268. <!-- 操作提示 -->
  269. <Border Background="#80000000"
  270. CornerRadius="4"
  271. Padding="8"
  272. VerticalAlignment="Bottom"
  273. HorizontalAlignment="Center"
  274. Margin="0,0,0,10"
  275. Visibility="{Binding CurrentImage, Converter={StaticResource NullToVisibilityConverter}}">
  276. <StackPanel>
  277. <TextBlock Text="{lex:Loc ROI操作提示}"
  278. Foreground="White"
  279. FontWeight="Bold"
  280. Margin="0,0,0,4" />
  281. <TextBlock Text="{lex:Loc 拖动移动ROI}"
  282. Foreground="White"
  283. FontSize="11" />
  284. <TextBlock Text="{lex:Loc 角点拖动调整大小}"
  285. Foreground="White"
  286. FontSize="11" />
  287. <TextBlock Text="{lex:Loc 旋转点拖动旋转}"
  288. Foreground="White"
  289. FontSize="11" />
  290. </StackPanel>
  291. </Border>
  292. </Grid>
  293. </Grid>
  294. </Border>
  295. <!-- 右侧:控制面板 -->
  296. <Grid Grid.Column="1"
  297. Margin="0,10,10,10">
  298. <Grid.RowDefinitions>
  299. <RowDefinition Height="Auto" />
  300. <RowDefinition Height="Auto" />
  301. <RowDefinition Height="Auto" />
  302. <RowDefinition Height="Auto" />
  303. <RowDefinition Height="*" />
  304. </Grid.RowDefinitions>
  305. <!-- ROI工具栏 -->
  306. <Border Grid.Row="0"
  307. Style="{StaticResource CardStyle}">
  308. <StackPanel>
  309. <TextBlock Text="{lex:Loc ROI工具}"
  310. FontWeight="Bold"
  311. Margin="0,0,0,8" />
  312. <StackPanel Orientation="Horizontal"
  313. HorizontalAlignment="Center">
  314. <!-- 绘制模式 -->
  315. <RadioButton Content="📐"
  316. Style="{StaticResource ToolButtonStyle}"
  317. ToolTip="{lex:Loc 绘制ROI}"
  318. IsChecked="{Binding RoiMode, Converter={StaticResource EnumToBooleanConverter}, ConverterParameter={x:Static enums:RoiOperationMode.Draw}}" />
  319. <!-- 移动模式 -->
  320. <RadioButton Content="↔"
  321. Style="{StaticResource ToolButtonStyle}"
  322. ToolTip="{lex:Loc 移动ROI}"
  323. IsChecked="{Binding RoiMode, Converter={StaticResource EnumToBooleanConverter}, ConverterParameter={x:Static enums:RoiOperationMode.Move}}" />
  324. <!-- 调整大小模式 -->
  325. <RadioButton Content="⤢"
  326. Style="{StaticResource ToolButtonStyle}"
  327. ToolTip="{lex:Loc 调整大小}"
  328. IsChecked="{Binding RoiMode, Converter={StaticResource EnumToBooleanConverter}, ConverterParameter={x:Static enums:RoiOperationMode.Resize}}" />
  329. <!-- 旋转模式 -->
  330. <RadioButton Content="↻"
  331. Style="{StaticResource ToolButtonStyle}"
  332. ToolTip="{lex:Loc 旋转ROI}"
  333. IsChecked="{Binding RoiMode, Converter={StaticResource EnumToBooleanConverter}, ConverterParameter={x:Static enums:RoiOperationMode.Rotate}}" />
  334. <!-- 清除ROI -->
  335. <Button Width="30"
  336. Height="30"
  337. Margin="10,0,0,0"
  338. Padding="0"
  339. ToolTip="{lex:Loc 清除ROI}"
  340. Command="{Binding ClearRoiCommand}">
  341. <materialDesign:PackIcon Kind="ClearCircle" />
  342. </Button>
  343. </StackPanel>
  344. <!-- ROI信息 -->
  345. <Border Background="#F5F5F5"
  346. CornerRadius="3"
  347. Padding="6"
  348. Margin="0,8,0,0">
  349. <StackPanel>
  350. <TextBlock Text="{lex:Loc ROI信息}"
  351. FontWeight="SemiBold"
  352. FontSize="11" />
  353. <TextBlock>
  354. <TextBlock.Text>
  355. <MultiBinding Converter="{StaticResource RoiToTextConverter}">
  356. <Binding Path="CurrentRoi.X" />
  357. <Binding Path="CurrentRoi.Y" />
  358. <Binding Path="CurrentRoi.Width" />
  359. <Binding Path="CurrentRoi.Height" />
  360. <Binding Path="CurrentRoi.Angle" />
  361. </MultiBinding>
  362. </TextBlock.Text>
  363. </TextBlock>
  364. </StackPanel>
  365. </Border>
  366. </StackPanel>
  367. </Border>
  368. <!-- 参数设置 -->
  369. <Border Grid.Row="1"
  370. Style="{StaticResource CardStyle}"
  371. Margin="0,8,0,0">
  372. <StackPanel>
  373. <TextBlock Text="{lex:Loc 分析参数}"
  374. FontWeight="Bold"
  375. Margin="0,0,0,8" />
  376. <Grid>
  377. <Grid.RowDefinitions>
  378. <RowDefinition Height="Auto" />
  379. <RowDefinition Height="Auto" />
  380. <RowDefinition Height="Auto" />
  381. </Grid.RowDefinitions>
  382. <Grid.ColumnDefinitions>
  383. <ColumnDefinition Width="80" />
  384. <ColumnDefinition Width="*" />
  385. </Grid.ColumnDefinitions>
  386. <TextBlock Grid.Row="0"
  387. Grid.Column="0"
  388. Text="{lex:Loc 算法}"
  389. VerticalAlignment="Center" />
  390. <ComboBox Grid.Row="0"
  391. Grid.Column="1"
  392. ItemsSource="{Binding FocusMethods}"
  393. SelectedValue="{Binding Parameters.FocusMethod}"
  394. Margin="0,0,0,4" />
  395. <TextBlock Grid.Row="1"
  396. Grid.Column="0"
  397. Text="{lex:Loc 模式}"
  398. VerticalAlignment="Center" />
  399. <ComboBox Grid.Row="1"
  400. Grid.Column="1"
  401. ItemsSource="{Binding AnalysisModes}"
  402. SelectedValue="{Binding Parameters.AnalysisMode}"
  403. Margin="0,0,0,4" />
  404. <TextBlock Grid.Row="2"
  405. Grid.Column="0"
  406. Text="{lex:Loc 实时分析}"
  407. VerticalAlignment="Center" />
  408. <CheckBox Grid.Row="2"
  409. Grid.Column="1"
  410. IsChecked="{Binding Parameters.EnableRealtimeAnalysis}"
  411. VerticalAlignment="Center" />
  412. </Grid>
  413. </StackPanel>
  414. </Border>
  415. <!-- 控制按钮 -->
  416. <Border Grid.Row="2"
  417. Style="{StaticResource CardStyle}"
  418. Margin="0,8,0,0">
  419. <StackPanel>
  420. <StackPanel Orientation="Horizontal"
  421. HorizontalAlignment="Center">
  422. <Button Content="{lex:Loc 开始分析}"
  423. Command="{Binding StartAnalysisCommand}"
  424. Padding="20,8"
  425. Margin="0,0,8,0" />
  426. <Button Content="{lex:Loc 停止分析}"
  427. Command="{Binding StopAnalysisCommand}"
  428. Padding="20,8" />
  429. </StackPanel>
  430. <StackPanel Orientation="Horizontal"
  431. HorizontalAlignment="Center"
  432. Margin="0,8,0,0">
  433. <Button Content="{lex:Loc 重置}"
  434. Command="{Binding ResetCommand}"
  435. Padding="15,4"
  436. Margin="0,0,8,0" />
  437. <Button Content="{lex:Loc 导出报告}"
  438. Command="{Binding ExportCommand}"
  439. Padding="15,4" />
  440. </StackPanel>
  441. </StackPanel>
  442. </Border>
  443. <!-- 实时结果 -->
  444. <Border Grid.Row="3"
  445. Style="{StaticResource CardStyle}"
  446. Margin="0,8,0,0">
  447. <StackPanel>
  448. <TextBlock Text="{lex:Loc 实时结果}"
  449. FontWeight="Bold"
  450. Margin="0,0,0,8" />
  451. <Grid>
  452. <Grid.ColumnDefinitions>
  453. <ColumnDefinition Width="*" />
  454. <ColumnDefinition Width="*" />
  455. </Grid.ColumnDefinitions>
  456. <StackPanel Grid.Column="0">
  457. <TextBlock Text="{lex:Loc 清晰度}"
  458. FontSize="11"
  459. Foreground="#666" />
  460. <TextBlock Text="{Binding CurrentResult.Sharpness, StringFormat=F2}"
  461. FontSize="18"
  462. FontWeight="Bold"
  463. Foreground="#007ACC" />
  464. <TextBlock Text="{Binding StatusText}"
  465. FontSize="10"
  466. Foreground="#666"
  467. Margin="0,2,0,0" />
  468. </StackPanel>
  469. <StackPanel Grid.Column="1">
  470. <TextBlock Text="{lex:Loc 质量评分}"
  471. FontSize="11"
  472. Foreground="#666" />
  473. <TextBlock Text="{Binding CurrentResult.QualityScore, StringFormat=F1}"
  474. FontSize="18"
  475. FontWeight="Bold"
  476. Foreground="#4CAF50" />
  477. <TextBlock Text="/100"
  478. FontSize="11"
  479. Foreground="#999" />
  480. </StackPanel>
  481. </Grid>
  482. <ProgressBar Value="{Binding CurrentResult.Sharpness}"
  483. Maximum="50"
  484. Height="6"
  485. Margin="0,8,0,0" />
  486. <!-- 最佳值显示 -->
  487. <Border Background="#F8F9FA"
  488. CornerRadius="3"
  489. Padding="6"
  490. Margin="0,8,0,0">
  491. <StackPanel Orientation="Horizontal">
  492. <TextBlock Text="{lex:Loc 最佳清晰度}"
  493. FontSize="10"
  494. Foreground="#666" />
  495. <TextBlock Text="{Binding BestSharpnessText}"
  496. FontSize="10"
  497. FontWeight="Bold"
  498. Margin="5,0,0,0" />
  499. <TextBlock Text="{Binding FrameCountText}"
  500. FontSize="10"
  501. Foreground="#666"
  502. Margin="10,0,0,0" />
  503. </StackPanel>
  504. </Border>
  505. </StackPanel>
  506. </Border>
  507. <!-- 图表 -->
  508. <Border Grid.Row="4"
  509. Style="{StaticResource CardStyle}"
  510. Margin="0,8,0,0">
  511. <oxy:PlotView Model="{Binding PlotModel}"
  512. Height="200" />
  513. </Border>
  514. </Grid>
  515. </Grid>
  516. </Grid>
  517. </UserControl>