URMProcessAlg.cs 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Runtime.InteropServices;
  4. using Vinno.DataManager.Process;
  5. using Vinno.DataManager.Utilities;
  6. using Vinno.DataTypes;
  7. namespace WingAIDiagnosisService.URMManage
  8. {
  9. [StructLayout(LayoutKind.Sequential)]
  10. public class URMProcessParams
  11. {
  12. public double DownsampleIndex { get; set; }
  13. public double IntPowerDen { get; set; }
  14. public double IntPowerDir { get; set; }
  15. public double SigmaGauss { get; set; }
  16. public double VessScale { get; set; }
  17. public double VelMaxScaler { get; set; }
  18. public double VelMinScaler { get; set; }
  19. public int iterations { get; set; }
  20. public double URMSigmaDen { get; set; }
  21. public double URMSigmaStep { get; set; }
  22. public int URMDirIterGauss { get; set; }
  23. public URMProcessParams()
  24. {
  25. DownsampleIndex = 3;
  26. IntPowerDen = 0.33;
  27. IntPowerDir = 0.25;
  28. SigmaGauss = 0.8;
  29. VessScale = 0.6;
  30. VelMaxScaler = 1;
  31. VelMinScaler = 0;
  32. iterations = 1;
  33. URMSigmaDen = 5;
  34. URMSigmaStep = 0.1;
  35. URMDirIterGauss = 10;
  36. }
  37. }
  38. [StructLayout(LayoutKind.Sequential)]
  39. public class URMImgBaseParam
  40. {
  41. public IntPtr Denptr { get; set; } //Den的分析后数据
  42. public IntPtr Dirptr { get; set; } //Dir的分析后数据
  43. public IntPtr Velptr { get; set; } //Vel的分析后数据
  44. public IntPtr Angleptr { get; set; }//360图的数据
  45. public IntPtr MaskPtr { get; set; }//Mask
  46. public int Urmsrcwidth { get; set; }//URM分析后的数据宽度
  47. public int Urmsrcheight { get; set; }//URM分析后的数据高度
  48. public double Res { get; set; }
  49. public double ScaleOfPixel_x { get; set; }
  50. public double ScaleOfPixel_y { get; set; }
  51. public int ImgProcessVer { get; set; }//后处理算法版本 0 Ver2(<2.7) 1 Ver3(2.7)
  52. public int vespekeltype { get; set; }
  53. }
  54. [StructLayout(LayoutKind.Sequential)]
  55. public class URMImgDrawParam
  56. {
  57. public IntPtr Screenimgptr { get; set; }
  58. public int Screenimgwidth { get; set; }
  59. public int Screenimgheight { get; set; }
  60. public int ZoomOn { get; set; }
  61. public double ZoomRoix { get; set; }
  62. public double ZoomRoiy { get; set; }
  63. public double ZoomRoiwidth { get; set; }
  64. public double ZoomRoiheight { get; set; }
  65. public int Roix { get; set; }
  66. public int Roiy { get; set; }
  67. public int Roiwidth { get; set; }
  68. public int Roiheight { get; set; }
  69. public int LeftRight { get; set; }
  70. public int UpDown { get; set; }
  71. }
  72. [StructLayout(LayoutKind.Sequential)]
  73. public class URMVideoParam
  74. {
  75. public double _VideoDownSampleIndex { get; set; }
  76. public double _VideoType { get; set; }
  77. public double _VideoScaler { get; set; }
  78. public URMVideoParam()
  79. {
  80. _VideoDownSampleIndex = 2;
  81. _VideoType = 1;
  82. _VideoScaler = 3;
  83. }
  84. }
  85. public class URMProcessAlg
  86. {
  87. [DllImport("ImageProcessAlgWrapLib.dll")]
  88. private static extern IntPtr PIA_CreateURMProcess(IntPtr imagePP);
  89. [DllImport("ImageProcessAlgWrapLib.dll")]
  90. private static extern void PIA_SetURMParam(IntPtr handPtr, URMProcessParams srParams);
  91. [DllImport("ImageProcessAlgWrapLib.dll")]
  92. private static extern void PIA_SetURMImgBaseParams(IntPtr handPtr, URMImgBaseParam srParams);
  93. [DllImport("ImageProcessAlgWrapLib.dll")]
  94. private static extern void PIA_SetURMImgDrawParams(IntPtr handPtr, URMImgDrawParam srParams);
  95. [DllImport("ImageProcessAlgWrapLib.dll")]
  96. private static extern void PIA_CalURMImg(IntPtr handPtr, ref double barmax, ref double barmin, int type);
  97. [DllImport("ImageProcessAlgWrapLib.dll")]
  98. private static extern void PIA_DrawURMImg(IntPtr handPtr, int type, IntPtr colormap, int mixflag);
  99. [DllImport("ImageProcessAlgWrapLib.dll")]
  100. private static extern bool PIA_CalURMMeasurImg(IntPtr handle, IntPtr urmdmeasurimgptr, int urmtype, ref double barmax, ref double barmin);
  101. [DllImport("ImageProcessAlgWrapLib.dll")]
  102. private static unsafe extern void PIA_CalURMTraceMaskImg(IntPtr handle, int width, int height, DPoint* Points, int PointCount);
  103. [DllImport("ImageProcessAlgWrapLib.dll")]
  104. private static unsafe extern void PIA_CalURMVideo(IntPtr handle, IntPtr dstarray, URMVideoParam videoparam, URMPoint* Points, int framecount, int* PointsCounts, IntPtr colormap, int mixflage);
  105. [DllImport("ImageProcessAlgWrapLib.dll")]
  106. private static unsafe extern void PIA_PreURMVideo(IntPtr handle, URMVideoParam videoparam, URMPoint* Points, int framecount, int* PointsCounts, ref double barmax, ref double barmin);
  107. [DllImport("ImageProcessAlgWrapLib.dll")]
  108. private static extern void PIA_DrawURMVideo(IntPtr handle, int index, IntPtr colormapptr, int mixflag);
  109. [DllImport("ImageProcessAlgWrapLib.dll")]
  110. private static extern void PIA_URMMain_Release(IntPtr handPtr);
  111. private IntPtr _handle;
  112. public URMProcessAlg(ImagePP imgpp)
  113. {
  114. _handle = PIA_CreateURMProcess(imgpp.Handle);
  115. }
  116. public void SetURMParam(URMProcessParams srParams)
  117. {
  118. PIA_SetURMParam(_handle, srParams);
  119. }
  120. public void SetURMBaseParam(URMImgBaseParam Params)
  121. {
  122. PIA_SetURMImgBaseParams(_handle, Params);
  123. }
  124. public void SetURMDrawParam(URMImgDrawParam Params)
  125. {
  126. PIA_SetURMImgDrawParams(_handle, Params);
  127. }
  128. public void CalURMImg(ref double barmax, ref double barmin, int type)
  129. {
  130. PIA_CalURMImg(_handle, ref barmax, ref barmin, type);
  131. }
  132. public void DrawURM(int type, IntPtr colormap, int mixflag)
  133. {
  134. PIA_DrawURMImg(_handle, type, colormap, mixflag);
  135. }
  136. public void CalURMMeasurImg(IntPtr urmdmeasurimgptr,
  137. int urmtype, ref double barmax, ref double barmin)
  138. {
  139. PIA_CalURMMeasurImg(_handle, urmdmeasurimgptr, urmtype, ref barmax, ref barmin);
  140. }
  141. public unsafe void CalTraceMaskImg(int width, int height, List<DPoint> Points)
  142. {
  143. var pointarray = Points.ToArray();
  144. fixed (DPoint* pointptr = pointarray)
  145. {
  146. PIA_CalURMTraceMaskImg(_handle, width, height, pointptr, Points.Count);
  147. }
  148. }
  149. public unsafe void CalURMVideo(NativeArray dstarray, URMVideoParam videoparam, URMPoint* Points,
  150. int framecount, int* PointsCounts, IntPtr colormap, int mixflag)
  151. {
  152. PIA_CalURMVideo(_handle, dstarray.Start, videoparam, Points, framecount, PointsCounts, colormap, mixflag);
  153. }
  154. public unsafe void PreURMVideo(URMVideoParam videoparam, URMPoint* Points,
  155. int framecount, int* PointsCounts, ref double barmax, ref double barmin)
  156. {
  157. PIA_PreURMVideo(_handle, videoparam, Points, framecount, PointsCounts, ref barmax, ref barmin);
  158. }
  159. public void DrawURMVideo(int index, IntPtr colormap, int mixflag)
  160. {
  161. PIA_DrawURMVideo(_handle, index, colormap, mixflag);
  162. }
  163. public void Release()
  164. {
  165. PIA_URMMain_Release(_handle);
  166. }
  167. }
  168. }