ReprocessCommon.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #include "ReprocessCommon.h"
  2. /// <summary>
  3. /// 将ColorType转成opencv支持的CV_8UC1这样的代号
  4. /// </summary>
  5. /// <param name="colorType"></param>
  6. /// <returns></returns>
  7. int ImageDepth::GetDepthFlag(ColorType colorType)
  8. {
  9. switch (colorType)
  10. {
  11. case Gray8:
  12. return CV_8UC1;
  13. case Gray16:
  14. return CV_16UC1;
  15. case Rgb:
  16. case Bgr:
  17. return CV_8UC3;
  18. case Bgra:
  19. case Rgba:
  20. return CV_8UC4;
  21. case GrayF32:
  22. return CV_32FC1;
  23. }
  24. char strMsgBuff[32];
  25. std::snprintf(strMsgBuff, 32, "unexpected colorType ( %i ).", colorType);
  26. throw std::invalid_argument(strMsgBuff);
  27. }
  28. /// <summary>
  29. /// 析构函数
  30. /// </summary>
  31. ErrorMsg::~ErrorMsg()
  32. {
  33. if (_errorMsg)
  34. {
  35. delete _errorMsg;
  36. _errorMsg = nullptr;
  37. }
  38. }
  39. /// <summary>
  40. /// 设置错误信息
  41. /// </summary>
  42. /// <param name="code"></param>
  43. /// <param name="errorMsgs"></param>
  44. void ErrorMsg::SetErrorMsg(std::vector<const char*> errorMsgs)
  45. {
  46. if (_errorMsg)
  47. {
  48. delete _errorMsg;
  49. _errorMsg = NULL;
  50. }
  51. int count = errorMsgs.size();
  52. std::stringstream ss;
  53. for (int ni = 0; ni < count; ni++)
  54. {
  55. ss << errorMsgs[ni];
  56. }
  57. std::string msgCombined = ss.str();
  58. int len = msgCombined.length();
  59. _errorMsg = new char[msgCombined.length() + 1];
  60. msgCombined.copy(_errorMsg, len, 0);
  61. *(_errorMsg + len) = '\0';
  62. }
  63. /// <summary>
  64. /// 获取错误信息
  65. /// </summary>
  66. /// <param name="errorCode"></param>
  67. /// <param name="errorMsg"></param>
  68. /// <param name="errorMaxLen"></param>
  69. void ErrorMsg::GetErrorMsg(char* errorMsg, const int errorMaxLen)
  70. {
  71. if (!_errorMsg)
  72. {
  73. return ;
  74. }
  75. int errorLen = strlen(_errorMsg);
  76. if (errorMaxLen > errorLen)
  77. {
  78. strcpy_s(errorMsg, errorLen + 1, _errorMsg);
  79. }
  80. else
  81. {
  82. strncpy_s(errorMsg, errorMaxLen, _errorMsg, errorMaxLen - 1);
  83. }
  84. }
  85. /// <summary>
  86. /// 初始化静态成员变量_errorMsg
  87. /// </summary>
  88. char* ErrorMsg::_errorMsg = nullptr;