12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- #include "ReprocessCommon.h"
- /// <summary>
- /// 将ColorType转成opencv支持的CV_8UC1这样的代号
- /// </summary>
- /// <param name="colorType"></param>
- /// <returns></returns>
- 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);
- }
- /// <summary>
- /// 析构函数
- /// </summary>
- ErrorMsg::~ErrorMsg()
- {
- if (_errorMsg)
- {
- delete _errorMsg;
- _errorMsg = nullptr;
- }
- }
- /// <summary>
- /// 设置错误信息
- /// </summary>
- /// <param name="code"></param>
- /// <param name="errorMsgs"></param>
- void ErrorMsg::SetErrorMsg(std::vector<const char*> 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';
- }
- /// <summary>
- /// 获取错误信息
- /// </summary>
- /// <param name="errorCode"></param>
- /// <param name="errorMsg"></param>
- /// <param name="errorMaxLen"></param>
- 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);
- }
- }
- /// <summary>
- /// 初始化静态成员变量_errorMsg
- /// </summary>
- char* ErrorMsg::_errorMsg = nullptr;
|