#include "ReprocessCommon.h" /// /// 将ColorType转成opencv支持的CV_8UC1这样的代号 /// /// /// int ImageDepth::GetDepthFlag(ColorType colorType) { switch (colorType) { case Gray8: return CV_8UC1; case Gray16: return CV_16UC1; case Rgb: case Bgr: return CV_8UC3; case Bgra: case Rgba: return CV_8UC4; case GrayF32: return CV_32FC1; } char strMsgBuff[32]; std::snprintf(strMsgBuff, 32, "unexpected colorType ( %i ).", colorType); throw std::invalid_argument(strMsgBuff); } /// /// 析构函数 /// ErrorMsg::~ErrorMsg() { if (_errorMsg) { delete _errorMsg; _errorMsg = nullptr; } } /// /// 设置错误信息 /// /// /// void ErrorMsg::SetErrorMsg(std::vector errorMsgs) { if (_errorMsg) { delete _errorMsg; _errorMsg = NULL; } int count = errorMsgs.size(); std::stringstream ss; for (int ni = 0; ni < count; ni++) { ss << errorMsgs[ni]; } std::string msgCombined = ss.str(); int len = msgCombined.length(); _errorMsg = new char[msgCombined.length() + 1]; msgCombined.copy(_errorMsg, len, 0); *(_errorMsg + len) = '\0'; } /// /// 获取错误信息 /// /// /// /// void ErrorMsg::GetErrorMsg(char* errorMsg, const int errorMaxLen) { if (!_errorMsg) { return ; } int errorLen = strlen(_errorMsg); if (errorMaxLen > errorLen) { strcpy_s(errorMsg, errorLen + 1, _errorMsg); } else { strncpy_s(errorMsg, errorMaxLen, _errorMsg, errorMaxLen - 1); } } /// /// 初始化静态成员变量_errorMsg /// char* ErrorMsg::_errorMsg = nullptr;