simagepro.cs 63 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489
  1. using SImagePro;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Net.NetworkInformation;
  6. using System.Runtime.CompilerServices;
  7. using System.Runtime.InteropServices;
  8. using System.Security.Cryptography.X509Certificates;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Xml.Linq;
  12. namespace SImagePro
  13. {
  14. #region SR7Link
  15. //相机IP
  16. public struct SR7IF_ETHERNET_CONFIG
  17. {
  18. [MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]
  19. public byte[] abyIpAddress;
  20. }
  21. #endregion
  22. #region 函数返回值
  23. public enum RTNCODE
  24. {
  25. RTN_CODE_OK = 0, //成功
  26. RTN_CODE_ERROR = -1, //一般性错误
  27. RTN_CODE_CAMERA_NOT_ONLINE = -999, //相机未连接.
  28. RTN_CODE_NULL_PTR = -998, //参数指针为null.
  29. RTN_CODE_ERROR_PARAMETER = -997, //参数错误.
  30. RTN_CODE_ERROR_MEMORY = -996, //内存(溢出/定义)错误.
  31. RTN_CODE_ERROR_TIMEOUT = -995, //计算超时.
  32. RTN_CODE_ERROR_ROI = -994, //roi错误
  33. RTN_CODE_ERROR_INIT = -993, //内存申请错误
  34. }
  35. #endregion
  36. #region SCVTYPE
  37. //旋转参数
  38. public enum ROTATE_TYPE
  39. {
  40. ONE_VERTICAL_ROTATE = 0x0000, //顺时针转90°
  41. TWO_VERTICAL_ROTATE, //顺时针旋转180°
  42. THREE_VERTICAL_ROTATE, //顺时针旋转270°
  43. LR_MIRROR_ROTATE, //左右镜像翻转
  44. UD_MIRROR_ROTATE, //上下镜像翻转
  45. CENTER_ROTATE, //中心对称反转
  46. }
  47. //平面点结构
  48. public struct SPoint2D
  49. {
  50. public double x;
  51. public double y;
  52. public SPoint2D(double x, double y)
  53. {
  54. this.x = x;
  55. this.y = y;
  56. }
  57. };
  58. //像素点结构
  59. public struct SPoint2DPix
  60. {
  61. public int x;
  62. public int y;
  63. public SPoint2DPix(int x, int y)
  64. {
  65. this.x = x;
  66. this.y = y;
  67. }
  68. };
  69. //空间结构
  70. public struct SPoint3D
  71. {
  72. public double x;
  73. public double y;
  74. public double z;
  75. public SPoint3D(double x, double y, double z)
  76. {
  77. this.x = x;
  78. this.y = y;
  79. this.z = z;
  80. }
  81. };
  82. //2D直线方程:a*x+b*y+c=0
  83. public struct SLine2D
  84. {
  85. public double a;
  86. public double b;
  87. public double c;
  88. public SLine2D(double a, double b, double c)
  89. {
  90. this.a = a;
  91. this.b = b;
  92. this.c = c;
  93. }
  94. };
  95. //3D直线
  96. public struct SLine3D
  97. {
  98. public float a;
  99. public float b;
  100. public float c;
  101. public SPoint3D pt;
  102. public SLine3D(float a, float b, float c, SPoint3D pt)
  103. {
  104. this.a = a;
  105. this.b = b;
  106. this.c = c;
  107. this.pt = pt;
  108. }
  109. };
  110. //线段
  111. public struct SLineSegment2D
  112. {
  113. public SPoint2D startPoint;
  114. public SPoint2D endPoint;
  115. public SLineSegment2D(SPoint2D startPoint, SPoint2D endPoint)
  116. {
  117. this.startPoint = startPoint;
  118. this.endPoint = endPoint;
  119. }
  120. };
  121. //平面方程:a*x+b*y+c*z+d=0
  122. public struct SPlane
  123. {
  124. public double a;
  125. public double b;
  126. public double c;
  127. public double d;
  128. public SPlane(double a, double b, double c, double d)
  129. {
  130. this.a = a;
  131. this.b = b;
  132. this.c = c;
  133. this.d = d;
  134. }
  135. };
  136. //圆结构
  137. public struct SCircle2D
  138. {
  139. public SPoint2D center; //圆心
  140. public double radius; //半径
  141. };
  142. //圆环结构
  143. public struct SRing2D
  144. {
  145. public SPoint2D center; //圆心
  146. public double maxR; //外径
  147. public double minR; //内径
  148. };
  149. //椭圆结构
  150. public struct SEllipse2D
  151. {
  152. public SPoint2D center; //中心点
  153. public double width; //宽度
  154. public double height; //高度
  155. public double angle; //角度
  156. };
  157. //圆弧结构
  158. public struct SArc2D
  159. {
  160. public SCircle2D Circle; //圆形
  161. public double startAngle; //圆弧起始角度
  162. public double arcAngle; //逆时针方向圆弧角度
  163. };
  164. //矩形
  165. public struct SRect
  166. {
  167. public SPoint2D center; //中心坐标
  168. public double angle; //角度
  169. public double width; //矩形宽度
  170. public double height; //矩形高度
  171. };
  172. //无角度矩形
  173. public struct SURect
  174. {
  175. public double leftX; //左下角X坐标
  176. public double leftY; //左下角Y坐标
  177. public double width; //矩形宽度
  178. public double height; //矩形高度
  179. };
  180. //球体结构
  181. public struct SSphere
  182. {
  183. public SPoint3D center; //球心
  184. public double radius; //半径
  185. };
  186. //空间矩形
  187. public struct SClipBox
  188. {
  189. public SPoint3D center; //中心点坐标
  190. public double lengthX; //X方向宽度
  191. public double lengthY; //Y方向宽度
  192. public double lengthZ; //Z方向宽度
  193. public double angleX; //绕X轴角度
  194. public double angleY; //绕Y轴角度
  195. public double angleZ; //绕Z轴角度
  196. public SClipBox(SPoint3D center, double lengthX, double lengthY, double lengthZ, double angleX, double angleY, double angleZ)
  197. {
  198. this.center = center;
  199. this.lengthX = lengthX;
  200. this.lengthY = lengthY;
  201. this.lengthZ = lengthZ;
  202. this.angleX = angleX;
  203. this.angleY = angleY;
  204. this.angleZ = angleZ;
  205. }
  206. };
  207. //3D变换参数
  208. public struct S3DAngle
  209. {
  210. public double x;
  211. public double y;
  212. public double z;
  213. public double angleX;
  214. public double angleY;
  215. public double angleZ;
  216. public double scale;
  217. public S3DAngle(double x, double y, double z, double angleX, double angleY, double angleZ, double scale)
  218. {
  219. this.x = x;
  220. this.y = y;
  221. this.z = z;
  222. this.angleX = angleX;
  223. this.angleY = angleY;
  224. this.angleZ = angleZ;
  225. this.scale = scale;
  226. }
  227. };
  228. //矩形卡尺
  229. public struct SRectCaliper
  230. {
  231. public double calspacing; //卡尺间距
  232. public double calheight; //高度为矩形高度
  233. public double calwidth; //卡尺宽度(高度为矩形高度)
  234. public SRect rect; //矩形
  235. };
  236. //腰形卡尺
  237. public struct SWaistCaliper
  238. {
  239. public double calspacing; //卡尺间距
  240. public double calheight; //高度为矩形高度
  241. public double calwidth; //卡尺宽度(高度为矩形高度)
  242. public SRect rect; //矩形
  243. };
  244. //圆形卡尺
  245. public struct SCircleCaliper
  246. {
  247. public double calspacing; //卡尺间距
  248. public double calheight; //高度为矩形高度
  249. public double calwidth; //卡尺宽度
  250. public double startAngle; //圆弧开始角度 单位:度
  251. public double endAngle; //圆弧终止角度 单位:度
  252. public SCircle2D Circle; //圆形
  253. };
  254. //拟合表面缺陷检测参数
  255. public struct SPlaneFlawsParm
  256. {
  257. public double humpHeightCheck; //凸起高度阈值
  258. public double humpAreaCheck; //凸起面积阈值
  259. public double sunkenDepthCheck; //凹陷深度阈值
  260. public double sunkenAreaCheck; //凹陷面积阈值
  261. public double blockBorderPhy; //计算点块边长
  262. };
  263. //拟合表面缺陷检测参数
  264. public struct SSurfaceFlawsParm
  265. {
  266. public double humpHeightCheck; //凸起高度阈值
  267. public double humpAreaCheck; //凸起面积阈值
  268. public double sunkenDepthCheck; //凹陷深度阈值
  269. public double sunkenAreaCheck; //凹陷面积阈值
  270. public double blockBorderPhy; //计算点块边长
  271. public double fitBorderPhyX; //拟合区域块X长度
  272. public double fitBorderPhyY; //拟合区域块Y长度
  273. public double fitExcluding; //异常值剔除比率
  274. public int blockSample; //计算点降采样倍率
  275. public int fitSample; //拟合点降采样倍率
  276. public int fitSurfaceN; //曲面拟合次数
  277. public int fitMethod; //拟合模式 0:曲面, 1:平面
  278. };
  279. //规则面(拟合线)缺陷测参数
  280. public struct SRuleFlawsParm
  281. {
  282. public double humpHeightCheck; //凸起高度阈值
  283. public double humpAreaCheck; //凸起面积阈值
  284. public double sunkenDepthCheck; //凹陷深度阈值
  285. public double sunkenAreaCheck; //凹陷面积阈值
  286. public int fitMethod; //0: 曲线 1:直线
  287. public int fitCurveMaxIndex; //拟合曲线最大指数
  288. public double outlieDelRate; //异常值剔除比率
  289. public double blockLength; //分段长
  290. public double deleteRate; //线拟合剔除比率
  291. public double minValidRate; //有效的点最少占比
  292. public double Samplewidth; //采样宽度
  293. };
  294. //ROI类型
  295. public enum ROI_TYPE
  296. {
  297. RECT, //矩形
  298. CIRCLE, //圆形
  299. RING, //圆环
  300. POLYGON, //多边形
  301. ELLIPSE, //椭圆
  302. ELLIPSP_RING, //椭圆环
  303. CALLIPERS_RECT, //矩形卡尺
  304. CALLIPERS_CIRCULAR,//圆形卡尺
  305. }
  306. //ROI
  307. public struct SRoi
  308. {
  309. public ROI_TYPE RoiType; //roi类型
  310. public SRect RectRoi; //常规矩形
  311. public SCircle2D CircleRoi; //圆
  312. public SRing2D RingRoi; //圆环
  313. public SPoint2D[] PointsRoi; //任意多边形
  314. public uint PointsSize;
  315. };
  316. //平面度结果
  317. public struct FlatnessParam
  318. {
  319. public SPlane plane; //平面方程
  320. public double minDis; //点到平面最小距离
  321. public double maxDis; //点到平面最大距离
  322. public SPoint3D maxPt; //到平面最小距离点
  323. public SPoint3D minPt; //到平面最小距离点
  324. };
  325. //边界
  326. public struct SBorder
  327. {
  328. public double minX;
  329. public double maxX;
  330. public double minY;
  331. public double maxY;
  332. };
  333. //点云头结构(zInterval初始化为 1e-5)
  334. public struct SPointCloudHead
  335. {
  336. public uint height; //点云行数
  337. public uint width; //点云列数
  338. public double xInterval; //点云列间距
  339. public double yInterval; //点云行间距
  340. public double zInterval; //点云z方向分辨率系数
  341. public SPointCloudHead(uint height, uint width, double xInterval, double yInterval, double zInterval)
  342. {
  343. this.height = height;
  344. this.width = width;
  345. this.xInterval = xInterval;
  346. this.yInterval = yInterval;
  347. this.zInterval = zInterval;
  348. }
  349. };
  350. //TIF文件信息
  351. public struct STifField
  352. {
  353. public uint height; //行数
  354. public uint width; //列数
  355. public uint bitDepth; //位宽
  356. public uint channels; //通道数
  357. public int type; //数据类型 1是signed 2是unsigned
  358. };
  359. //3D显示点结构
  360. public struct SPoint3DRGB
  361. {
  362. public SPoint3D point3D;
  363. public byte r;
  364. public byte g;
  365. public byte b;
  366. };
  367. //缺陷检测结果
  368. public struct FlawsData
  369. {
  370. public SPoint2D[] flawsContours; //缺陷轮廓
  371. public int contoursNum; //缺陷轮廓点数
  372. public double flawsAreas; //缺陷面积
  373. public double flawsHeight; //缺陷最深
  374. public SRect flawsRects; //缺陷矩形框
  375. };
  376. public struct CalData
  377. {
  378. public SPoint3D[] fitPoints;
  379. public int pointsNum;
  380. };
  381. //空间显示点结构
  382. public struct SDisplay3DPoint
  383. {
  384. public double x;
  385. public double y;
  386. public double z;
  387. public byte r;
  388. public byte g;
  389. public byte b;
  390. public int AdaptiveRGB;
  391. public SDisplay3DPoint(double x, double y, double z, byte r, byte g, byte b, int AdaptiveRGB)
  392. {
  393. this.x = x;
  394. this.y = y;
  395. this.z = z;
  396. this.r = r;
  397. this.g = g;
  398. this.b = b;
  399. this.AdaptiveRGB = AdaptiveRGB;
  400. }
  401. };
  402. #endregion
  403. internal class SCV
  404. {
  405. #region 常量
  406. public const double INVALID_VALUE_MIN = -1000000000;
  407. public const double INVALID_VALUE_MAX = 1000000000;
  408. #endregion
  409. #region SR7Link
  410. ///<summary>
  411. /// 通信连接------与相机连接
  412. /// </summary>
  413. /// <param name="lDeviceId"></param> 设备ID号,范围为0-3
  414. /// <param name="pEthernetConfig"></param> (网口)通信设定
  415. /// <returns></returns> 0:成功; 小于0:失败
  416. /// <remarks></remarks>
  417. [DllImport("SR7Link.dll", CallingConvention = CallingConvention.Cdecl)]
  418. internal static extern int SR7IF_EthernetOpen(int lDeviceId, ref SR7IF_ETHERNET_CONFIG pEthernetConfig);
  419. #endregion
  420. #region 3D计算相关算法
  421. /*************************************************
  422. Function: PointPlaneDistance(区分正负)
  423. Description: 点到平面距离
  424. Input: @point 3D点
  425. @plane 平面方程
  426. Output: @distance 输出距离
  427. Return: <0: 失败.
  428. =0: 成功
  429. Others: 无
  430. *************************************************/
  431. [DllImport("SImagePro.dll", CallingConvention = CallingConvention.Cdecl)]
  432. internal static extern int PointPlaneDistance(SPoint3D point, SPlane plane, ref double distance);
  433. /*************************************************
  434. Function: VolumeMeasurement
  435. Description: 体积测量
  436. Input: @HeightData 高度图
  437. @pcHead 高度头文件
  438. @ROI ROI
  439. @plane 平面方程
  440. @upper、lower 高度上下限制
  441. Output: @volume 输出体积MM^3
  442. Return: <0: 失败.
  443. =0: 成功
  444. Others: 无
  445. *************************************************/
  446. [DllImport("SImagePro.dll", CallingConvention = CallingConvention.Cdecl)]
  447. internal static extern int VolumeMeasurement(int[] HeightData, SPointCloudHead pcHead, SRoi ROI, SPlane plane, double upper, double lower, ref double volume);
  448. /*************************************************
  449. Function: ThreePointHeightDiff
  450. Description: 三点高度差
  451. Input: @sPt:开始点 ePt:结束点 cPt:中间点
  452. Output: @distance 输出三点高度差
  453. Return: <0: 失败.
  454. =0: 成功
  455. Others: 无
  456. *************************************************/
  457. [DllImport("SImagePro.dll", CallingConvention = CallingConvention.Cdecl)]
  458. internal static extern int ThreePointHeightDiff(SPoint3D sPt, SPoint3D ePt, SPoint3D cPt, ref double distance);
  459. /*************************************************
  460. Function: FitPlane
  461. Description: 平面拟合
  462. Input: @points 用于拟合的点
  463. @ptSize 拟合点数量
  464. Output: @plane 输出平面方程
  465. Return: <0: 失败.
  466. =0: 成功
  467. Others: 无
  468. *************************************************/
  469. [DllImport("SImagePro.dll", CallingConvention = CallingConvention.Cdecl)]
  470. internal static extern int FitPlane(SPoint3D[] points, int ptSize, ref SPlane plane);
  471. /*************************************************
  472. Function: PlanePlaneAngle
  473. Description: 平面角度
  474. Input: @plane1 输入平面1
  475. @plane2 输入平面2
  476. Output: @angle 角度
  477. Return: <0: 失败.
  478. =0: 成功.
  479. Others: 无
  480. *************************************************/
  481. [DllImport("SImagePro.dll", CallingConvention = CallingConvention.Cdecl)]
  482. internal static extern int PlanePlaneAngle(SPlane plane1, SPlane plane2, ref double angle);
  483. /*************************************************
  484. Function: PlanePlaneLin
  485. Description: 平面交线
  486. Input: @plane1 输入平面1
  487. @plane2 输入平面2
  488. Output: @dstLine 交线
  489. Return: <0: 失败.
  490. =0: 成功.
  491. Others: 无
  492. *************************************************/
  493. [DllImport("SImagePro.dll", CallingConvention = CallingConvention.Cdecl)]
  494. internal static extern int PlanePlaneLine(SPlane plane1, SPlane plane2, ref SLine3D dstLine);
  495. /*************************************************
  496. Function: Line3DIntersection
  497. Description: 空间直线交点
  498. Input: @line1 空间直线1
  499. @line2 空间直线2
  500. Output: @dstPoint 交点
  501. Return: <0: 失败.
  502. =0: 成功.
  503. Others: 无
  504. *************************************************/
  505. [DllImport("SImagePro.dll", CallingConvention = CallingConvention.Cdecl)]
  506. internal static extern int Line3DIntersection(SLine3D line1, SLine3D line2, ref SPoint3D dstPoint);
  507. /*************************************************
  508. Function: Point3dDistance
  509. Description: 3D点距离
  510. Input: @point1 空间点1
  511. @point2 空间点2
  512. Output: @distance 交点
  513. Return: <0: 失败.
  514. =0: 成功.
  515. Others: 无
  516. *************************************************/
  517. [DllImport("SImagePro.dll", CallingConvention = CallingConvention.Cdecl)]
  518. internal static extern int Point3dDistance(SPoint3D point1, SPoint3D point2, ref double distance);
  519. /*************************************************
  520. Function: FitLine3D
  521. Description: 3D点距离
  522. Input: @point1 空间点1
  523. @point2 空间点2
  524. Output: @distance 距离
  525. Return: <0: 失败.
  526. =0: 成功.
  527. Others: 无
  528. *************************************************/
  529. [DllImport("SImagePro.dll", CallingConvention = CallingConvention.Cdecl)]
  530. internal static extern int FitLine3D(SPoint3D[] points, int pointnum, ref SLine3D line);
  531. /*************************************************
  532. Function: PointToLine3dDistance
  533. Description: 3D点到直线距离
  534. Input: @poin 空间点
  535. @line 空间直线
  536. Output: @distance 距离
  537. Return: <0: 失败.
  538. =0: 成功.
  539. Others: 无
  540. *************************************************/
  541. [DllImport("SImagePro.dll", CallingConvention = CallingConvention.Cdecl)]
  542. internal static extern int PointToLine3dDistance(SPoint3D point, SLine3D line, ref double distance);
  543. /*************************************************
  544. Function: PlaneIntersection
  545. Description: 三平面交点
  546. Input: @planes 平面,lanes[0]为标定块顶面或底面,planes[1]和planes[2]均为侧面
  547. Output: @dstPt 交点
  548. Return: <0: 失败.
  549. =0: 成功.
  550. Others: 无
  551. *************************************************/
  552. [DllImport("SImagePro.dll", CallingConvention = CallingConvention.Cdecl)]
  553. internal static extern int PlaneIntersection(SPlane[] planes, ref SPoint3D dstPt);
  554. /*************************************************
  555. Function: MedianFiltering
  556. Description: 中值滤波
  557. Input: @srcHeightImage 原始点云
  558. @pcHead 点云头
  559. @hThreshold 高度阈值
  560. @wThreshold 窗口大小
  561. @ACC 加速率
  562. Output: @dstHeightImage 滤波后点云
  563. Return: <0: 失败.
  564. =0: 成功
  565. Others: 无
  566. *************************************************/
  567. [DllImport("SImagePro.dll", CallingConvention = CallingConvention.Cdecl)]
  568. internal static extern int MedianFiltering(int[] srcHeightImage, int[] dstHeightImage, ref SPointCloudHead pcHead, double hThreshold, uint Wthreshold, uint ACC);
  569. /*************************************************
  570. Function: PointCloudFiltering
  571. Description: 图像滤波(点云滤波),支持ROI
  572. Input: @srcHeightImage 原始点云数据
  573. @pcHead 点云头文件
  574. @rois roi(如果ROI为null或者数量为0,那么就对全图进行滤波)
  575. @RoiSize Roi数量
  576. @distanceRate 点与点之间的有效距离比,值越大认为两点之间的联系关系越强(范围0~1), 默认值为0.5
  577. @minValidArea 最小有效关联点,如果区域内关联点的个数小于此值,则这个区域会被去掉,默认值为200
  578. Output: @dstHeightImage 滤波后云数据
  579. Return: <0 失败.
  580. = 成功
  581. Others: 无
  582. *************************************************/
  583. [DllImport("SImagePro.dll", CallingConvention = CallingConvention.Cdecl)]
  584. internal static extern int PointCloudFiltering(
  585. int[] srcHeightImage,
  586. int[] dstHeightImaget,
  587. SPointCloudHead pcHead,
  588. SRoi[] rois,
  589. int RoiSize,
  590. float distanceRate,
  591. int minValidArea);
  592. /*************************************************
  593. Function: HeightFiltering
  594. Description: 图像滤波(高度滤波),支持ROI
  595. Input: @srcHeightImage 原始点云数据
  596. @pcHead 点云头文件
  597. @rois roi(如果ROI为null或者数量为0,那么就对全图进行滤波)
  598. @RoiSize Roi数量
  599. @maxValidDis 高度阈值,单位:mm
  600. @minValidArea 面积阈值,单位:像素
  601. Output: @dstHeightImage 滤波后云数据
  602. Return: <0 失败.
  603. = 成功
  604. Others: 无
  605. *************************************************/
  606. [DllImport("SImagePro.dll", CallingConvention = CallingConvention.Cdecl)]
  607. internal static extern int HeightFiltering(
  608. int[] srcHeightImage,
  609. int[] dstHeightImaget,
  610. SPointCloudHead pcHead,
  611. SRoi[] rois,
  612. int RoiSize,
  613. double maxValidDis,
  614. int minValidArea);
  615. /*************************************************
  616. Function: ImageComplements
  617. Description: 图像补点
  618. Input: @heightImage 补点图像图像
  619. @pcHead 点云头
  620. @mode 模式: 0:只补X ,1:只补Y,2:两个方向都补
  621. @complementsNum 补点数量
  622. @angle 补点角度,超过该角度以后补水平直线
  623. Output: @heightImage 补点图像图像
  624. Return: <0: 失败.
  625. =0: 成功
  626. Others: 无
  627. *************************************************/
  628. [DllImport("SImagePro.dll", CallingConvention = CallingConvention.Cdecl)]
  629. internal static extern int ImageComplements(int[] heightImage, SPointCloudHead pcHead, int mode, int complementsNum, double angle);
  630. /*************************************************
  631. Function: CalFlatnessOfRegion
  632. Description: 按区域拟合,计算平面度
  633. Input: @heightImage 原始高度值
  634. @RoiMaskImage ROI区域Mask图
  635. @pcHead 点云头
  636. @xRoiPixs,yRoiPixs 拟合区域单位分块大小
  637. @Plane3D 基准平面(没有就填NULL)
  638. Output: @FlatnessParam 返回平面方程,最大最小点的距离
  639. Return: <0: 失败.
  640. =0: 成功
  641. Others: 无
  642. *************************************************/
  643. [DllImport("SImagePro.dll", CallingConvention = CallingConvention.Cdecl)]
  644. internal static extern int CalFlatnessOfRegion(
  645. int[] heightImage,
  646. byte[] RoiMaskImage,
  647. SPointCloudHead pcHead,
  648. int xRoiPixs,
  649. int yRoiPixs,
  650. SPlane[] basePlane,
  651. ref FlatnessParam FlatnessPlne);
  652. #endregion
  653. #region 标定校正相关算法
  654. /*************************************************
  655. Function: GetShakeCalibData
  656. Description: 获取图像校正数据(校正机构抖动)
  657. Input: @heightImage 输入原始图像数据
  658. @width 图像宽度
  659. @height 图像高度
  660. @fStepX X间距
  661. @fStepY Y间距
  662. @plane 基准平面
  663. @rectROI 基准校正区域
  664. Output: @outCalibData 校正数据申请内存 大小为 (nHeight* 10) 个字节,外部申请内存
  665. Return: <0: 失败.
  666. =0: 成功
  667. Others: 无
  668. *************************************************/
  669. [DllImport("SImagePro.dll", CallingConvention = CallingConvention.Cdecl)]
  670. internal static extern int GetShakeCalibData(
  671. int[] heightImage,
  672. int width,
  673. int height,
  674. float fStepX,
  675. float fStepY,
  676. SPlane plane,
  677. SRect rectROI,
  678. IntPtr outCalibData);
  679. /*************************************************
  680. Function: GenShakeCalibImage
  681. Description: 校正图像(校正机构抖动)
  682. Input: @heightImage 输入原始图像数据
  683. @width 图像宽度
  684. @height 图像高度
  685. @Data 输入校正数据
  686. Output: @outHeightImage 校正后图像数据,pDstData存储大小和pSrcData一致
  687. Return: <0: 失败.
  688. =0: 成功
  689. Others: 无
  690. *************************************************/
  691. [DllImport("SImagePro.dll", CallingConvention = CallingConvention.Cdecl)]
  692. internal static extern int GenShakeCalibImage(int[] heightImage, int width, int height, IntPtr Data, int[] outHeightImage);
  693. /*************************************************
  694. Function: GetRouletteCalibData
  695. Description: 获取圆盘标定数
  696. Input: @imagePointXYs[18], 棋盘格的9个点在原始灰度图像像素里的坐标, 格式为{x1,y1,x2,y2,x3,...,x9,y9}
  697. @pixelSizeBeforeTransform, X方向像素大小
  698. @pixelSizeAfterTransform, 转换后像素大小
  699. @leftRealX, 左边点X真实坐标
  700. @rightRealX, 右边点X真实坐标
  701. @upRealY, 上面点X真实坐标
  702. @downRealY, 下面点Y真实坐标
  703. Output: @outCalibData, 输出的标定数据结果
  704. @outMessage[256] 输出信息提示
  705. Return: <0 失败.
  706. = 成功
  707. Others: 无
  708. *************************************************/
  709. [DllImport("SImagePro.dll", CallingConvention = CallingConvention.Cdecl)]
  710. internal static extern int GetRouletteCalibData(
  711. SPoint2D[] imagePointXY,
  712. double pixelSizeBeforeTransform,
  713. double pixelSizeAfterTransform,
  714. double leftRealX,
  715. double rightRealX,
  716. double upRealY,
  717. double downRealY,
  718. IntPtr outCalibData,
  719. ref double outMessage);
  720. /*************************************************
  721. Function: GenRouletteCalibImage
  722. Description: 圆盘标定校正图像
  723. Input: @heightImage, 原始深度图
  724. @pointsWidth, 点云宽度
  725. @int pointsHeight, 点云高度
  726. @calibData, 标定数据
  727. @int imageWidth, 转换后图像宽度
  728. @int imageHeight, 转换后图像高度
  729. @centerX, 裁剪中心X
  730. @centerY, 裁剪中心Y
  731. @ centerZ, 裁剪中心Z
  732. @ ratioMMPerPixel, 转换后像素大小
  733. Output: @dst, 转换后3D数据
  734. Return: <0: 失败.
  735. =0: 成功
  736. Others: 无
  737. *************************************************/
  738. [DllImport("SImagePro.dll", CallingConvention = CallingConvention.Cdecl)]
  739. internal static extern int GenRouletteCalibImage(
  740. int[] heightImage,
  741. int pointsWidth,
  742. int pointsHeight,
  743. IntPtr calibData,
  744. int[] dstHeightImage,
  745. int imageWidth,
  746. int imageHeight,
  747. double centerX,
  748. double centerY,
  749. double centerZ,
  750. double ratioMMPerPixel);
  751. /*************************************************
  752. Function: AffineTransMatrix3D
  753. Description: 根据输入点求矩阵
  754. Input: @ptSeneor 原始点
  755. @ptPhysical 目标点
  756. @ptSize 点数
  757. Output: @dstMatrix 输出的变换矩阵
  758. Return: <0: 失败.
  759. =0: 成功
  760. Others: 无
  761. *************************************************/
  762. [DllImport("SImagePro.dll", CallingConvention = CallingConvention.Cdecl)]
  763. internal static extern int AffineTransMatrix3D(SPoint3D[] ptSeneor, SPoint3D[] ptPhysical, int nSize, double[] dstMatrix);
  764. /*************************************************
  765. Function: AffineTransPoint3D
  766. Description: 根据矩阵求变换后的坐标
  767. Input: @srcPt 转换前3D点
  768. @matrix 仿射变换4*4矩阵
  769. @dstPt 转换后3D点
  770. Output: @dstPt 转换后的3D点
  771. Return: <0: 失败.
  772. =0: 成功
  773. Others: 无
  774. *************************************************/
  775. [DllImport("SImagePro.dll", CallingConvention = CallingConvention.Cdecl)]
  776. internal static extern int AffineTransPoint3D(ref SPoint3D srcPt, double[] matrix, ref SPoint3D dstPt);
  777. /*************************************************
  778. Function: AffineTransImage
  779. Description: 点云变换
  780. Input: @heightImage 变化前高度图
  781. @grayImage 变化前亮度图(没有时可以为NULL)
  782. @pcHead 点云头
  783. @matrix 仿射变换4*4矩阵
  784. @newPcHead 变化点云头
  785. @centerX 、centerY、centerZ 转换后图像偏移
  786. @hMax、hMin 高度上下限
  787. Output: @newHeightImage 变化后高度图
  788. @newGrayImage 变化后灰度图
  789. Return: <0: 失败.
  790. =0: 成功
  791. Others: 无
  792. *************************************************/
  793. [DllImport("SImagePro.dll", CallingConvention = CallingConvention.Cdecl)]
  794. internal static extern int AffineTransImage(
  795. int[] heightImage,
  796. byte[] grayImage,
  797. SPointCloudHead pcHead,
  798. double[] matrix,
  799. SPointCloudHead newPcHead,
  800. double centerX,
  801. double centerY,
  802. double centerZ,
  803. int[] newHeightImage,
  804. byte[] newGrayImage,
  805. double hMax = INVALID_VALUE_MAX,
  806. double hMin = INVALID_VALUE_MIN);
  807. /*************************************************
  808. Function: CorrectZAxisRotation
  809. Description: 相机绕Z方向旋转校正
  810. Input: @heightImage 校正前高度图
  811. @grayImage 校正前亮度图(没有时可以为NULL)
  812. @pcHead 点云头
  813. @angle 旋转角度
  814. @centerX 、centerY、centerZ 转换后图像偏移
  815. @newPcHead 校正后头文件
  816. Output: @newHeightImage 校正后高度图
  817. @newGrayImage 校正后灰度图
  818. Return: <0: 失败.
  819. =0: 成功
  820. Others: 无
  821. *************************************************/
  822. [DllImport("SImagePro.dll", CallingConvention = CallingConvention.Cdecl)]
  823. internal static extern int CorrectZAxisRotation(
  824. int[] heightImage,
  825. byte[] grayImage,
  826. ref SPointCloudHead pcHead,
  827. double angle,
  828. SPointCloudHead newPcHead,
  829. double centerX,
  830. double centerY,
  831. double centerZ,
  832. int[] newHeightImage,
  833. byte[] newGrayImage);
  834. /*************************************************
  835. Function: PoseToMatrix
  836. Description: 根据角度求矩阵
  837. Input: @angleX 绕X轴旋转角度
  838. @angleY 绕Y轴旋转角度
  839. @angleZ 绕Z轴旋转角度
  840. @thetaXofPd 矫正角度
  841. @ceberX X方向偏移值
  842. @ceberY Y方向偏移值
  843. @ceberZ Z方向偏移值
  844. Output: @matrix 计算得到的角度矩阵
  845. Return: <0: 失败.
  846. =0: 成功
  847. *************************************************/
  848. [DllImport("SImagePro.dll", CallingConvention = CallingConvention.Cdecl)]
  849. internal static extern int PoseToMatrix(double AngleX, double AngleY, double AngleZ, double thetaXofPd, double CeberX, double CeberY, double CeberZ, double[] matrix);
  850. /*************************************************
  851. Function: GetMatrixFromPlane
  852. Description: 通过平面方程计算旋转矩阵
  853. Input: @plane 平面方程
  854. Output: @matrix 计算得到的角度矩阵
  855. Return: <0: 失败.
  856. =0: 成功
  857. Others: 无
  858. *************************************************/
  859. [DllImport("SImagePro.dll", CallingConvention = CallingConvention.Cdecl)]
  860. internal static extern int GetMatrixFromPlane(ref SPlane plane, double[] matrix);
  861. /*************************************************
  862. Function: CorrectXAxisRotation
  863. Description: 矫正绕相机绕X旋转的角度
  864. Input: @heightData 原始图像
  865. @pcHead 点云头
  866. @anglex X的角度
  867. @CeberY Y方向偏移行数
  868. @isHeigh 是否偏移高度值
  869. Output: @dstheightData 偏移后原图像
  870. Return: <0: 失败.
  871. =0: 成功
  872. Others: 无
  873. *************************************************/
  874. [DllImport("SImagePro.dll", CallingConvention = CallingConvention.Cdecl)]
  875. internal static extern int CorrectXAxisRotation(int[] heightData, SPointCloudHead pcHead, double anglex, int CeberY, bool isHeigh, int[] dstheightData);
  876. /*************************************************
  877. Function: ImageRotate
  878. Description: 图像旋转
  879. Input: @heightData 原始图像
  880. @pcHead 点云头
  881. @rotateType 旋转方式
  882. Output: @dstheightData 偏移后原图像
  883. Return: <0: 失败.
  884. =0: 成功
  885. Others: 无
  886. *************************************************/
  887. [DllImport("SImagePro.dll", CallingConvention = CallingConvention.Cdecl)]
  888. internal static extern int ImageRotate(int[] heightData, int[] dstheightData, ref SPointCloudHead pcHead, ROTATE_TYPE rotateType);
  889. #endregion
  890. #region 工具类
  891. /*************************************************
  892. Function: ArrayFilter
  893. Description: 数组数据筛选
  894. Input: @data 输入数组
  895. @dataSize 数组大小
  896. @filterType 极值(0:正常,1:极大值,2:极小值)
  897. @valueType 结果计算方式(0:平均值,1:中位数)
  898. @delPara 阈值m,大于等于1按个数,小于1按比例
  899. @samPara 阈值n,大于等于1按个数,小于1按比例
  900. @upper 数值上限
  901. @lower 数值下限
  902. Output: @outValue 剔除后数值
  903. @outData 剔除后数组
  904. @outDataSize剔除后数组大小
  905. Return: <0: 失败.
  906. =0: 成功
  907. Others: 正常:去除最大m个点,去除最小n个点;
  908. 极大值:去除最大m个点;
  909. 极小值:去除最小m个点;
  910. *************************************************/
  911. [DllImport("SImagePro.dll", CallingConvention = CallingConvention.Cdecl)]
  912. internal static extern int ArrayFilter(
  913. double[] data,
  914. int dataSize,
  915. int filterType,
  916. int valueType,
  917. double delPara,
  918. double samPara,
  919. double upper,
  920. double lower,
  921. ref double outValue,
  922. double[] outData,
  923. ref int outDataSize);
  924. /*************************************************
  925. Function: RoiArea
  926. Description: 求ROI面积大小,用于提取ROI内点时候申请内存
  927. Input: @roi 输入ROI
  928. Output:
  929. Return: <0: 失败.
  930. >0: ROI像素面积.
  931. Others: 无
  932. *************************************************/
  933. [DllImport("SImagePro.dll", CallingConvention = CallingConvention.Cdecl)]
  934. internal static extern int RoiArea(SRoi roiInfo);
  935. /*************************************************
  936. Function: Point3DFilter
  937. Description: 3D点数组数据筛选
  938. Input: @points 输入数组
  939. @ptSize 数组大小
  940. @filterType 极值(0:正常,1:极大值,2:极小值)
  941. @valueType 结果计算方式(0:平均值,1:中位数)
  942. @priorityType 优先级(0:X方向,1:Y方向,2:Z方向)
  943. @delPara 阈值m,大于等于1按个数,小于1按比例
  944. @samPara 阈值n,大于等于1按个数,小于1按比例
  945. @upper 数值上限
  946. @lower 数值下限
  947. Output: @outValue 剔除后数值
  948. @outPoints 剔除后数组
  949. @outPtSize 剔除后数组大小
  950. Return: <0: 失败.
  951. =0: 成功
  952. Others: 正常:去除最大m个点,去除最小n个点;
  953. 极大值:去除最大m个点;
  954. 极小值:去除最小m个点;
  955. *************************************************/
  956. [DllImport("SImagePro.dll", CallingConvention = CallingConvention.Cdecl)]
  957. internal static extern int Point3DFilter(
  958. SPoint3D[] points,
  959. int ptSize,
  960. int filterType,
  961. int valueType,
  962. int priorityType,
  963. double delPara,
  964. double samPara,
  965. ref SPoint3D outValue,
  966. SPoint3D[] outPoints,
  967. ref int outPtSize,
  968. double upper = INVALID_VALUE_MAX,
  969. double lower = INVALID_VALUE_MIN);
  970. /*************************************************
  971. Function: GetAllPointsFromRoi
  972. Description: ROI内点提取
  973. Input: @data 高度数据
  974. @pcHead 点云头结构
  975. @roiInfo ROI
  976. @accelerate 降采样比率,默认填1
  977. Output: @roiData 输出ROI内3D点(SPoint3D[])
  978. @dstanum 3D点数组大小
  979. Return: <0: 失败.
  980. =0: 成功
  981. *************************************************/
  982. [DllImport("SImagePro.dll", CallingConvention = CallingConvention.Cdecl)]
  983. internal static extern int GetAllPointsFromRoi(int[] heightImage, SPointCloudHead pcHead, SRoi roiInfo, IntPtr roiData, ref int dstanum, int accelerate = 1);
  984. /*************************************************
  985. Function: GetFilteredPointFromROI
  986. Description: ROi获取单点高度
  987. Input: @heightImage高度数据
  988. @pcHead 点云头结构
  989. @roiInfo ROI
  990. @accelerate 降采样比率,默认填1
  991. @filterType 极值(0:正常,1:极大值,2:极小值)
  992. @valueType 结果计算方式(0:平均值,1:中位数)
  993. @delPara 阈值m,大于等于1按个数,小于1按比例
  994. @samPara 阈值n,大于等于1按个数,小于1按比例
  995. @upper 数值上限
  996. @lower 数值下限
  997. Output: @outValue 剔除后数值
  998. @outPoints 剔除后数组
  999. @outPtSize 剔除后数组大小
  1000. Return: <0: 失败.
  1001. =0: 成功
  1002. Others: 正常:去除最大m个点,去除最小n个点;
  1003. 极大值:去除最大m个点;
  1004. 极小值:去除最小m个点;
  1005. *************************************************/
  1006. [DllImport("SImagePro.dll", CallingConvention = CallingConvention.Cdecl)]
  1007. internal static extern int GetFilteredPointFromROI(
  1008. int[] heightData,
  1009. SPointCloudHead pcHead,
  1010. SRoi roiInfo,
  1011. int filterType,
  1012. int valueType,
  1013. double delPara,
  1014. double samPara,
  1015. ref SPoint3D outValue,
  1016. IntPtr outPoints,
  1017. ref int outPtSize,
  1018. int accelerate = 1,
  1019. double upper = INVALID_VALUE_MAX,
  1020. double lower = INVALID_VALUE_MIN);
  1021. /*************************************************
  1022. Function: GetFilteredPointFromROIOnBasePlane
  1023. Description: ROi获取单点高度(基于平面)
  1024. Input: @heightImage高度数据
  1025. @pcHead 点云头结构
  1026. @roiInfo ROI
  1027. @accelerate 降采样比率,默认填1
  1028. @filterType 极值(0:正常,1:极大值,2:极小值)
  1029. @valueType 结果计算方式(0:平均值,1:中位数)
  1030. @delPara 阈值m,大于等于1按个数,小于1按比例
  1031. @samPara 阈值n,大于等于1按个数,小于1按比例
  1032. @upper 数值上限
  1033. @lower 数值下限
  1034. @plane 平面方程
  1035. Output: @outValue 剔除后数值
  1036. @outPoints 剔除后数组
  1037. @outPtSize 剔除后数组大小
  1038. Return: <0: 失败.
  1039. =0: 成功
  1040. Others: 正常:去除最大m个点,去除最小n个点;
  1041. 极大值:去除最大m个点;
  1042. 极小值:去除最小m个点;
  1043. *************************************************/
  1044. [DllImport("SImagePro.dll", CallingConvention = CallingConvention.Cdecl)]
  1045. internal static extern int GetFilteredPointFromROIOnBasePlane(
  1046. int[] heightImage,
  1047. SPointCloudHead pcHead,
  1048. SRoi roiInfo,
  1049. int filterType,
  1050. int valueType,
  1051. double delPara,
  1052. double samPara,
  1053. SPlane plane,
  1054. ref double outValue,
  1055. IntPtr outPoints,
  1056. ref int outPtSize,
  1057. int accelerate = 1,
  1058. double upper = INVALID_VALUE_MAX,
  1059. double lower = INVALID_VALUE_MIN);
  1060. /*************************************************
  1061. Function: GetMaskFromRoi
  1062. Description: 获取ROI区域Mask图
  1063. Input: @Roi 输入ROI
  1064. @pcHead 点云头
  1065. Output: @mask 输出Mask图,大小与原始点云一样;
  1066. Return: <0 失败.
  1067. =0 成功
  1068. *************************************************/
  1069. [DllImport("SImagePro.dll", CallingConvention = CallingConvention.Cdecl)]
  1070. internal static extern int GetMaskFromRoi(SRoi Roi, SPointCloudHead pcHead, byte[] mask);
  1071. /*************************************************
  1072. Function: GetMaskFromPoints
  1073. Description: 根据点坐标生成Mask图
  1074. Input: @pt 输入点坐标
  1075. @ptSize 点个数
  1076. @width 图像宽度
  1077. @height 图像高度
  1078. Output: @mask 输出Mask图;
  1079. Return: <0 失败.
  1080. =0 成功
  1081. *************************************************/
  1082. [DllImport("SImagePro.dll", CallingConvention = CallingConvention.Cdecl)]
  1083. internal static extern int GetMaskFromPoints(SPoint2D[] inPt, int ptSize, int width, int height, byte[] mask);
  1084. /*************************************************
  1085. Function: GenHeightImageFromMask
  1086. Description: 获取加掩膜以后的高度图图
  1087. Input: @mask Mask图
  1088. @pcHead 点云头
  1089. @data 高度数据
  1090. Output: @data 高度数据
  1091. Return: <0 失败.
  1092. =0 成功
  1093. Others: 无
  1094. *************************************************/
  1095. [DllImport("SImagePro.dll", CallingConvention = CallingConvention.Cdecl)]
  1096. internal static extern int GenHeightImageFromMask(SPointCloudHead pcHead, byte[] mask, int[] data);
  1097. #endregion
  1098. #region 图像转换类
  1099. /*************************************************
  1100. Function: CalUpperAndLower
  1101. Description: 求图像上下限
  1102. Input: @points 输入图像
  1103. @width height 图像长宽
  1104. Output: @upper lower 高度上下限,原始int高度,单位1/100000 mm
  1105. Return: <0: 失败.
  1106. =0: 成功
  1107. Others: 无
  1108. *************************************************/
  1109. [DllImport("SImagePro.dll", CallingConvention = CallingConvention.Cdecl)]
  1110. internal static extern int CalUpperAndLower(int[] points, uint hight, uint width, ref double upper, ref double lower);
  1111. /*************************************************
  1112. Function: PointToGrayData
  1113. Description: 高度转灰度
  1114. Input: @points 输入图像
  1115. @width height 图像长宽
  1116. @upper lower 高度上下限,原始int高度,单位1/100000 mm
  1117. Output: @grayData 灰度图
  1118. Return: <0: 失败.
  1119. =0: 成功
  1120. Others: 无
  1121. *************************************************/
  1122. [DllImport("SImagePro.dll", CallingConvention = CallingConvention.Cdecl)]
  1123. internal static extern int PointToGrayData(int[] points, uint width, uint height, double upper, double lower, byte[] grayData);
  1124. /*************************************************
  1125. Function: PointToRGBData
  1126. Description: 高度转RGB显示
  1127. Input: @points 输入图像
  1128. @width height 模式:0 只通过高度计算RGB,1、2 通过高度分布计算RGB
  1129. @upper lower 高度上下限,原始int高度,单位1/100000 mm
  1130. Output: @R、G、B RBG颜色
  1131. Return: <0: 失败.
  1132. =0: 成功
  1133. Others: 无
  1134. *************************************************/
  1135. [DllImport("SImagePro.dll", CallingConvention = CallingConvention.Cdecl)]
  1136. internal static extern int PointToRGBData(int[] points, uint width, uint height, int mode, double upper, double lower, byte[] R, byte[] G, byte[] B);
  1137. /*************************************************
  1138. Function: GetPointCloudHead
  1139. Description: 读取ECD头文件
  1140. Input: @file 输入文件名
  1141. Output: @pcHead 输出头文件
  1142. Return: <0: 失败.
  1143. =0: 成功
  1144. Others: 无
  1145. *************************************************/
  1146. [DllImport("SImagePro.dll", CallingConvention = CallingConvention.Cdecl)]
  1147. internal static extern int GetPointCloudHead(char[] file, ref SPointCloudHead pcHead);
  1148. /*************************************************
  1149. Function: ReadEcd
  1150. Description: 读取ECD文件
  1151. Input: @file 输入文件名
  1152. Output: @pcHead 输出头文件
  1153. @heightImage 高度数据
  1154. Return: <0: 失败.
  1155. =0: 成功
  1156. Others: 无
  1157. *************************************************/
  1158. [DllImport("SImagePro.dll", CallingConvention = CallingConvention.Cdecl)]
  1159. internal static extern int ReadEcd(char[] file, int[] heightImage, ref SPointCloudHead pcHead);
  1160. /*************************************************
  1161. Function: WriteEcd
  1162. Description: 写入ECD头文件
  1163. Input: @file 输入文件名
  1164. Output: @pcHead 输出头文件
  1165. @heightImage 高度数据
  1166. Return: <0: 失败.
  1167. =0: 成功
  1168. Others: 无
  1169. *************************************************/
  1170. [DllImport("SImagePro.dll", CallingConvention = CallingConvention.Cdecl)]
  1171. internal static extern int WriteEcd(char[] file, int[] heightImage, SPointCloudHead pcHead);
  1172. /*************************************************
  1173. Function: WritePly
  1174. Description: 保存PLY
  1175. Input: @file 输入文件名
  1176. @points 点云数据
  1177. @pointSize 3D点数量
  1178. Output:
  1179. Return: <0: 失败.
  1180. =0: 成功
  1181. Others: 无
  1182. *************************************************/
  1183. [DllImport("SImagePro.dll", CallingConvention = CallingConvention.Cdecl)]
  1184. internal static extern int WritePly(char[] file, SPoint3D[] points, int pointSize);
  1185. /*************************************************
  1186. Function: SavePly
  1187. Description: 保存PLY
  1188. Input: @file 输入文件名
  1189. @pcHead 输出头文件
  1190. @heightImage 高度数据
  1191. Output:
  1192. Return: <0: 失败.
  1193. =0: 成功
  1194. Others: 无
  1195. *************************************************/
  1196. [DllImport("SImagePro.dll", CallingConvention = CallingConvention.Cdecl)]
  1197. internal static extern int SavePly(char[] file, int[] heightImage, SPointCloudHead pcHead);
  1198. /*************************************************
  1199. Function: SavePcd
  1200. Description: 保存Ply格式
  1201. Input: @file 文件名
  1202. @heightImage 高度数据
  1203. @PointCloudHead 头文件
  1204. Output:
  1205. Return: <0: 失败.
  1206. =0: 成功.
  1207. Others: 无
  1208. *************************************************/
  1209. [DllImport("SImagePro.dll", CallingConvention = CallingConvention.Cdecl)]
  1210. internal static extern int SavePcd(char[] file, int[] heightImage, SPointCloudHead pcHead);
  1211. /*************************************************
  1212. Function: Save32Tif
  1213. Description: 保存32位Tiff格式
  1214. Input: @file 文件名
  1215. @heightImage 高度数据
  1216. @PointCloudHead 头文件
  1217. Output:
  1218. Return: <0: 失败.
  1219. =0: 成功.
  1220. Others: 无
  1221. *************************************************/
  1222. [DllImport("SImagePro.dll", CallingConvention = CallingConvention.Cdecl)]
  1223. internal static extern int Save32Tif(char[] file, int[] heightImage, SPointCloudHead pcHead);
  1224. /*************************************************
  1225. Function: Save16Tif
  1226. Description: 保存16位Tiff格式
  1227. Input: @file 文件名
  1228. @heightImage 高度数据
  1229. @PointCloudHead 头文件
  1230. @HeightMax、HeightMin 高度上下限区间(参考对应相机景深范围)
  1231. Output: @z_scale 返回缩放比例
  1232. Return: <0: 失败.
  1233. =0: 成功.
  1234. Others: 无
  1235. *************************************************/
  1236. [DllImport("SImagePro.dll", CallingConvention = CallingConvention.Cdecl)]
  1237. internal static extern int Save16Tif(char[] file, int[] heightImage, SPointCloudHead pcHead, double HeightMax, double HeightMin, ref double z_scale);
  1238. /*************************************************
  1239. Function: Save16Tif
  1240. Description: 保存16位Tiff格式
  1241. Input: @file 文件名
  1242. @heightImage 高度数据
  1243. @PointCloudHead 头文件
  1244. @z_scale 输入缩放比例
  1245. Output: 无
  1246. Return: <0: 失败.
  1247. =0: 成功.
  1248. Others: 无
  1249. *************************************************/
  1250. [DllImport("SImagePro.dll", CallingConvention = CallingConvention.Cdecl)]
  1251. internal static extern int Save16TifOfScale(char[] file, int[] heightImage, SPointCloudHead pcHead, double z_scale);
  1252. [DllImport("SImagePro.dll", CallingConvention = CallingConvention.Cdecl)]
  1253. internal static extern int Save16TifOfShort(char[] file, short[] heightImage, SPointCloudHead pcHead, double z_scale, int isSigned);
  1254. /*************************************************
  1255. Function: GetTifField
  1256. Description: 获取tiff图片字段信息
  1257. Input: @file 文件名
  1258. Output: @tiffield 字段信息
  1259. Return: <0: 失败.
  1260. =0: 成功.
  1261. Others: 无
  1262. *************************************************/
  1263. [DllImport("SImagePro.dll", CallingConvention = CallingConvention.Cdecl)]
  1264. internal static extern int GetTifField(char[] file, ref STifField tiffield);
  1265. /*************************************************
  1266. Function: Read32Tif
  1267. Description: 读取32位tiff图片
  1268. Input: @file 文件名
  1269. Output: @data 高度信息
  1270. Return: <0: 失败.
  1271. =0: 成功.
  1272. Others: 无
  1273. *************************************************/
  1274. [DllImport("SImagePro.dll", CallingConvention = CallingConvention.Cdecl)]
  1275. internal static extern int Read32Tif(char[] file, int[] heightImage);
  1276. /*************************************************
  1277. Function: Read32Tif
  1278. Description: 读取32位tiff图片
  1279. Input: @file 文件名
  1280. @zInterval 缩放比率
  1281. Output: @dataheightImage 高度信息
  1282. Return: <0: 失败.
  1283. =0: 成功.
  1284. Others: 无
  1285. *************************************************/
  1286. [DllImport("SImagePro.dll", CallingConvention = CallingConvention.Cdecl)]
  1287. internal static extern int Read16Tif(char[] file, double zInterval, int[] heightImage);
  1288. /*************************************************
  1289. Function: ReadBmp
  1290. Description: 读取Bmp图片
  1291. Input: @file 文件名
  1292. Output: @imageData 图像数据
  1293. @width、height 图像长宽
  1294. Return: <0: 失败.
  1295. =0: 成功.
  1296. Others: 无
  1297. *************************************************/
  1298. [DllImport("SImagePro.dll", CallingConvention = CallingConvention.Cdecl)]
  1299. internal static extern int ReadBmp(char[] file, byte[] imageData,ref int width,ref int height);
  1300. /*************************************************
  1301. Function: SaveBmp
  1302. Description: 保存Bmp图片
  1303. Input: @file 文件名
  1304. @imageData 图像数据
  1305. @width、height 图像长宽
  1306. Output: 无
  1307. Return: <0: 失败.
  1308. =0: 成功.
  1309. Others: 无
  1310. *************************************************/
  1311. [DllImport("SImagePro.dll", CallingConvention = CallingConvention.Cdecl)]
  1312. internal static extern int SaveBmp(char[] file, byte[] imageData, int width, int height);
  1313. /*************************************************
  1314. Function: Save24Bmp
  1315. Description: 保存3通道24bitBmp图片
  1316. Input: @file 文件名
  1317. @DataR、DataG、DataR 图像rgb数据
  1318. @width、height 图像长宽
  1319. Output: 无
  1320. Return: <0: 失败.
  1321. =0: 成功.
  1322. Others: 无
  1323. *************************************************/
  1324. [DllImport("SImagePro.dll", CallingConvention = CallingConvention.Cdecl)]
  1325. internal static extern int Save24Bmp(char[] file, byte[] DataR, byte[] DataG, byte[] DataB, int width, int height);
  1326. #endregion
  1327. #region 3D显示
  1328. /*************************************************
  1329. Function: Show3DPoint
  1330. Description: 显示3D点
  1331. Input: @Points 需要显示的点集 SDisplay3DPoint[]
  1332. @PointsSize 每块点云数量
  1333. @PointsNum 点云块数量
  1334. @streamline 精简点数
  1335. @width 窗口宽度
  1336. @height 窗口高度
  1337. @left 窗口左边距
  1338. @top 窗口右边距
  1339. Output:
  1340. Return: <0: 失败.
  1341. =0: 成功.
  1342. Others: 无
  1343. Author: FYX
  1344. Date: 2024-05-31
  1345. *************************************************/
  1346. [DllImport("SShow3DImage.dll", CallingConvention = CallingConvention.Cdecl)]
  1347. internal static extern int Show3DPoint(
  1348. SDisplay3DPoint[] Points,
  1349. int[] PointsSize,
  1350. int PointsNum,
  1351. int streamline = 1,
  1352. int width = 960,
  1353. int height = 720,
  1354. int left = 50,
  1355. int top = 50);
  1356. /*************************************************
  1357. Function: Show3DPoint
  1358. Description: 显示3D点
  1359. Input: @Points 需要显示的点集
  1360. @PointsSize 每块点云数量
  1361. @Num 点云块数量
  1362. @streamline 精简点数
  1363. @width 窗口宽度
  1364. @height 窗口高度
  1365. @left 窗口左边距
  1366. @top 窗口右边距
  1367. Output:
  1368. Return: <0: 失败.
  1369. =0: 成功.
  1370. Others: 无
  1371. Author: FYX
  1372. Date: 2024-05-31
  1373. *************************************************/
  1374. [DllImport("SShow3DImage.dll", CallingConvention = CallingConvention.Cdecl)]
  1375. internal static extern int Show3DImage(
  1376. int[] heightImage,
  1377. int ImageWidth,
  1378. int ImageHeight,
  1379. double ImageXinterval,
  1380. double ImageYinterval,
  1381. int streamline = 1,
  1382. int width = 960,
  1383. int height = 720,
  1384. int left = 50,
  1385. int top = 50);
  1386. #endregion
  1387. }
  1388. }