CalibIndependentCamera.xaml.cs 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using Cognex.VisionPro;
  2. using Cognex.VisionPro.Dimensioning;
  3. using System;
  4. using System.Windows.Controls;
  5. using TeamAAS_VP.ViewModels.Calibration;
  6. namespace TeamAAS_VP.Views.Calibration
  7. {
  8. /// <summary>
  9. /// Interaction logic for CalibIndependentCamera
  10. /// </summary>
  11. public partial class CalibIndependentCamera : UserControl
  12. {
  13. CalibIndependentCameraViewModel VM;
  14. public CalibIndependentCamera()
  15. {
  16. InitializeComponent();
  17. VM = DataContext as CalibIndependentCameraViewModel;
  18. VM.PropertyChanged += VM_PropertyChanged;
  19. this.display.VerticalScrollBar = false;
  20. this.display.HorizontalScrollBar = false;
  21. this.display.AutoFit = true;
  22. this.display.BackColor = System.Drawing.SystemColors.ActiveCaption;
  23. }
  24. private int _imageWidth;
  25. private int _imageHeight;
  26. private void VM_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
  27. {
  28. try
  29. {
  30. if (e.PropertyName == "Image")
  31. {
  32. this.display.Image = VM.Image;
  33. //图像中心点坐标
  34. _imageWidth = this.display.Image.Width;
  35. _imageHeight = this.display.Image.Height;
  36. }
  37. else if (e.PropertyName == "Graphic")
  38. {
  39. this.display.StaticGraphics.Clear();
  40. CogGraphicCollection graphic = new CogGraphicCollection();
  41. CogCreateLineTool line1 = new CogCreateLineTool();
  42. CogCreateLineTool line2 = new CogCreateLineTool();
  43. line1.InputImage = this.display.Image;
  44. line2.InputImage = this.display.Image;
  45. line1.Line.X = _imageWidth / 2;
  46. line1.Line.Y = _imageHeight / 2;
  47. line1.Line.Rotation = 0;
  48. line2.Line.X = _imageWidth / 2;
  49. line2.Line.Y = _imageHeight / 2;
  50. line2.Line.Rotation = Math.PI / 180 * 90;
  51. line1.Run();
  52. line2.Run();
  53. graphic.Add(line1.GetOutputLine());
  54. graphic.Add(line2.GetOutputLine());
  55. this.display.StaticGraphics.Clear();
  56. this.display.StaticGraphics.AddList(graphic, "");
  57. if (VM.Graphic != null)
  58. {
  59. this.display.StaticGraphics.AddList(VM.Graphic, "");
  60. }
  61. }
  62. }
  63. catch (System.Exception)
  64. {
  65. }
  66. }
  67. }
  68. }