You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
2.8 KiB

  1. //----------------------------------------------------------------------------
  2. // Copyright (C) 2004-2022 by EMGU Corporation. All rights reserved.
  3. //----------------------------------------------------------------------------
  4. using System;
  5. using Microsoft.VisualStudio.DebuggerVisualizers;
  6. using Emgu.CV;
  7. using Emgu.CV.Structure;
  8. using Emgu.Util;
  9. using Emgu.CV.UI;
  10. using System.Diagnostics;
  11. using System.Runtime.InteropServices;
  12. using System.Windows.Forms;
  13. [assembly: DebuggerVisualizer(
  14. typeof(Emgu.CV.DebuggerVisualizers.MatNDVisualizer),
  15. typeof(VisualizerObjectSource),
  16. Target = typeof(MatND<>),
  17. //TargetTypeName = "Emgu.CV.MatND<,>, Emgu.CV.Platform.NetStandard",
  18. Description = "MatND debugger visualizer")]
  19. namespace Emgu.CV.DebuggerVisualizers
  20. {
  21. public sealed class MatNDVisualizer : DialogDebuggerVisualizer
  22. {
  23. #if DEBUG
  24. private static void DebugVisualizer()
  25. {
  26. using (MatND<float> mat = new MatND<float>(3, 5, 1))
  27. {
  28. mat.SetRandNormal(new MCvScalar(), new MCvScalar(255));
  29. VisualizerDevelopmentHost myHost =
  30. new VisualizerDevelopmentHost(mat, typeof(MatNDVisualizer));
  31. myHost.ShowVisualizer();
  32. }
  33. }
  34. #endif
  35. protected override void Show(IDialogVisualizerService windowService, IVisualizerObjectProvider objectProvider)
  36. {
  37. UnmanagedObject matND = objectProvider.GetObject() as UnmanagedObject;
  38. if (matND != null)
  39. {
  40. MCvMatND cvMatND = (MCvMatND)Marshal.PtrToStructure(matND.Ptr, typeof(MCvMatND));
  41. if (cvMatND.dims > 3 || (cvMatND.dims == 3 && cvMatND.dim[2].Size > 4))
  42. {
  43. MessageBox.Show("MatND of dimension > 3 is not supported for debugger visualizer");
  44. return;
  45. }
  46. UnmanagedObject matrix = null;
  47. int rows = cvMatND.dim[0].Size;
  48. int cols = cvMatND.dims >= 2 ? cvMatND.dim[1].Size : 1;
  49. int channels = cvMatND.dims >= 3 ? cvMatND.dim[2].Size : 1;
  50. if (matND is MatND<float>)
  51. matrix = new Matrix<float>(rows, cols, channels);
  52. else if (matND is MatND<int>)
  53. matrix = new Matrix<int>(rows, cols, channels);
  54. else if (matND is MatND<double>)
  55. matrix = new Matrix<double>(rows, cols, channels);
  56. if (matrix == null)
  57. {
  58. MessageBox.Show(String.Format("{0} is not supported", cvMatND.type.ToString()));
  59. return;
  60. }
  61. CvInvoke.cvCopy(matND.Ptr, matrix.Ptr, IntPtr.Zero);
  62. using (MatrixViewer viewer = new MatrixViewer())
  63. {
  64. viewer.Matrix = matrix;
  65. windowService.ShowDialog(viewer);
  66. }
  67. }
  68. }
  69. }
  70. }