Common.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. #pragma once
  2. #include <opencv2/opencv.hpp>
  3. #include <cmath>
  4. enum ErrorCode
  5. {
  6. None = 0,
  7. EncodeError = 1,
  8. DecodeError = 2,
  9. StraightScanDataUniformError = 3,
  10. LinearInterpolationError = 4,
  11. GetSurfaceError = 5,
  12. FusionError = 6,
  13. };
  14. enum ColorType
  15. {
  16. Gray8,
  17. Gray16,
  18. Rgb,
  19. Bgr,
  20. Bgra,
  21. Rgba,
  22. GrayF32,
  23. };
  24. typedef struct
  25. {
  26. int left;
  27. int top;
  28. int right;
  29. int bottom;
  30. int width;
  31. int height;
  32. }Rect;
  33. /// <summary>
  34. /// 表示一个平面的参数
  35. /// 已知平面上一个点M0(X0,Y0,Z0)和该平面的法向量N(A,B,C)
  36. /// 那么平面上任意点M(X,Y,Z)可以表示为A(X-X0)+B(Y-Y0)+C(Z-Z0)=0
  37. /// </summary>
  38. typedef struct
  39. {
  40. float x0;
  41. float y0;
  42. float z0;
  43. float a;
  44. float b;
  45. float c;
  46. }Plane;
  47. typedef struct
  48. {
  49. int origImgWidth;
  50. int origImgHeight;
  51. int origImgCount;
  52. ColorType colorType;
  53. Rect cropRect;
  54. int desiredImgWidth;
  55. int desiredImgHeight;
  56. int desiredImgCount;
  57. uint8_t* dataBuffer;
  58. }VolumeDataPreProcessorInfo;
  59. typedef struct
  60. {
  61. int x;
  62. int y;
  63. int z;
  64. float spacing;
  65. ColorType colorType;
  66. uint8_t* dataBuffer;
  67. }UniformVolumeDataInfo;
  68. typedef struct
  69. {
  70. int width;
  71. int height;
  72. ColorType colorType;
  73. uint8_t* dataBuffer;
  74. }ImageInfo;
  75. class ImageHelper
  76. {
  77. public:
  78. static int GetDepthFlag(ColorType colorType);
  79. static int GetBytesPerPixel(ColorType colorType);
  80. static bool NeedCrop(cv::Rect cropRect, int width, int height);
  81. };
  82. class ErrorMsg
  83. {
  84. public:
  85. ~ErrorMsg();
  86. static void SetErrorMsg(ErrorCode errorCode, std::vector<const char*> errorMsgs);
  87. static void GetErrorMsg(ErrorCode& errorCode, char* errorMsg, const int errorMaxLen);
  88. private:
  89. static char* _errorMsg;
  90. static ErrorCode _errorCode;
  91. };
  92. class MathTools
  93. {
  94. public:
  95. static float Distance(cv::Point3f point1, cv::Point3f point2);
  96. static bool SortFloatIndexPairDescend(const std::pair<float, int>& pair1, const std::pair<float, int> pair2);
  97. static bool SortFloatIndexPairAscend(const std::pair<float, int>& pair1, const std::pair<float, int> pair2);
  98. };