mirror of
https://github.com/opencv/opencv.git
synced 2025-06-11 20:09:23 +08:00
core: std::string more changes
This commit is contained in:
parent
ae8dcdf40d
commit
7f73b105ca
@ -452,6 +452,39 @@ class CV_EXPORTS FileNode; //for string constructor from FileNode
|
||||
|
||||
typedef std::string String;
|
||||
|
||||
#ifndef OPENCV_DISABLE_STRING_LOWER_UPPER_CONVERSIONS
|
||||
|
||||
//! @cond IGNORED
|
||||
namespace details {
|
||||
// std::tolower is int->int
|
||||
static inline char char_tolower(char ch)
|
||||
{
|
||||
return (char)std::tolower((int)ch);
|
||||
}
|
||||
// std::toupper is int->int
|
||||
static inline char char_toupper(char ch)
|
||||
{
|
||||
return (char)std::toupper((int)ch);
|
||||
}
|
||||
} // namespace details
|
||||
//! @endcond
|
||||
|
||||
static inline std::string toLowerCase(const std::string& str)
|
||||
{
|
||||
std::string result(str);
|
||||
std::transform(result.begin(), result.end(), result.begin(), details::char_tolower);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline std::string toUpperCase(const std::string& str)
|
||||
{
|
||||
std::string result(str);
|
||||
std::transform(result.begin(), result.end(), result.begin(), details::char_toupper);
|
||||
return result;
|
||||
}
|
||||
|
||||
#endif // OPENCV_DISABLE_STRING_LOWER_UPPER_CONVERSIONS
|
||||
|
||||
//! @} core_basic
|
||||
} // cv
|
||||
|
||||
|
@ -719,7 +719,6 @@ CV_EXPORTS void writeScalar( FileStorage& fs, const String& value );
|
||||
CV_EXPORTS void read(const FileNode& node, int& value, int default_value);
|
||||
CV_EXPORTS void read(const FileNode& node, float& value, float default_value);
|
||||
CV_EXPORTS void read(const FileNode& node, double& value, double default_value);
|
||||
CV_EXPORTS void read(const FileNode& node, String& value, const String& default_value);
|
||||
CV_EXPORTS void read(const FileNode& node, std::string& value, const std::string& default_value);
|
||||
CV_EXPORTS void read(const FileNode& node, Mat& mat, const Mat& default_mat = Mat() );
|
||||
CV_EXPORTS void read(const FileNode& node, SparseMat& mat, const SparseMat& default_mat = SparseMat() );
|
||||
|
@ -72,14 +72,9 @@ static const char* get_type_name(int type)
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
// std::tolower is int->int
|
||||
static char char_tolower(char ch)
|
||||
{
|
||||
return (char)std::tolower((int)ch);
|
||||
}
|
||||
static bool parse_bool(std::string str)
|
||||
{
|
||||
std::transform(str.begin(), str.end(), str.begin(), char_tolower);
|
||||
std::transform(str.begin(), str.end(), str.begin(), details::char_tolower);
|
||||
std::istringstream is(str);
|
||||
bool b;
|
||||
is >> (str.size() > 1 ? std::boolalpha : std::noboolalpha) >> b;
|
||||
|
@ -1691,11 +1691,6 @@ static cl_device_id selectOpenCLDevice()
|
||||
return NULL;
|
||||
}
|
||||
#else
|
||||
// std::tolower is int->int
|
||||
static char char_tolower(char ch)
|
||||
{
|
||||
return (char)std::tolower((int)ch);
|
||||
}
|
||||
static cl_device_id selectOpenCLDevice()
|
||||
{
|
||||
std::string platform, deviceName;
|
||||
@ -1780,7 +1775,7 @@ static cl_device_id selectOpenCLDevice()
|
||||
{
|
||||
int deviceType = 0;
|
||||
std::string tempStrDeviceType = deviceTypes[t];
|
||||
std::transform(tempStrDeviceType.begin(), tempStrDeviceType.end(), tempStrDeviceType.begin(), char_tolower);
|
||||
std::transform(tempStrDeviceType.begin(), tempStrDeviceType.end(), tempStrDeviceType.begin(), details::char_tolower);
|
||||
|
||||
if (tempStrDeviceType == "gpu" || tempStrDeviceType == "dgpu" || tempStrDeviceType == "igpu")
|
||||
deviceType = Device::TYPE_GPU;
|
||||
|
@ -667,11 +667,6 @@ void read(const FileNode& node, double& value, double default_value)
|
||||
CV_NODE_IS_REAL(node.node->tag) ? node.node->data.f : std::numeric_limits<double>::max();
|
||||
}
|
||||
|
||||
void read(const FileNode& node, String& value, const String& default_value)
|
||||
{
|
||||
value = !node.node ? default_value : CV_NODE_IS_STRING(node.node->tag) ? String(node.node->data.str.ptr) : String();
|
||||
}
|
||||
|
||||
void read(const FileNode& node, std::string& value, const std::string& default_value)
|
||||
{
|
||||
value = !node.node ? default_value : CV_NODE_IS_STRING(node.node->tag) ? std::string(node.node->data.str.ptr) : default_value;
|
||||
|
@ -1970,7 +1970,7 @@ public:
|
||||
const Ipp64u minorFeatures = 0;
|
||||
#endif
|
||||
|
||||
env = env.toLowerCase();
|
||||
env = toLowerCase(env);
|
||||
if(env.substr(0, 2) == "ne")
|
||||
{
|
||||
useIPP_NE = true;
|
||||
|
@ -3329,7 +3329,7 @@ void LayerFactory::registerLayer(const String &type, Constructor constructor)
|
||||
CV_TRACE_ARG_VALUE(type, "type", type.c_str());
|
||||
|
||||
cv::AutoLock lock(getLayerFactoryMutex());
|
||||
String type_ = type.toLowerCase();
|
||||
String type_ = toLowerCase(type);
|
||||
LayerFactory_Impl::iterator it = getLayerFactoryImpl().find(type_);
|
||||
|
||||
if (it != getLayerFactoryImpl().end())
|
||||
@ -3347,7 +3347,7 @@ void LayerFactory::unregisterLayer(const String &type)
|
||||
CV_TRACE_ARG_VALUE(type, "type", type.c_str());
|
||||
|
||||
cv::AutoLock lock(getLayerFactoryMutex());
|
||||
String type_ = type.toLowerCase();
|
||||
String type_ = toLowerCase(type);
|
||||
|
||||
LayerFactory_Impl::iterator it = getLayerFactoryImpl().find(type_);
|
||||
if (it != getLayerFactoryImpl().end())
|
||||
@ -3365,7 +3365,7 @@ Ptr<Layer> LayerFactory::createLayerInstance(const String &type, LayerParams& pa
|
||||
CV_TRACE_ARG_VALUE(type, "type", type.c_str());
|
||||
|
||||
cv::AutoLock lock(getLayerFactoryMutex());
|
||||
String type_ = type.toLowerCase();
|
||||
String type_ = toLowerCase(type);
|
||||
LayerFactory_Impl::const_iterator it = getLayerFactoryImpl().find(type_);
|
||||
|
||||
if (it != getLayerFactoryImpl().end())
|
||||
@ -3402,7 +3402,7 @@ BackendWrapper::~BackendWrapper() {}
|
||||
|
||||
Net readNet(const String& _model, const String& _config, const String& _framework)
|
||||
{
|
||||
String framework = _framework.toLowerCase();
|
||||
String framework = toLowerCase(_framework);
|
||||
String model = _model;
|
||||
String config = _config;
|
||||
const std::string modelExt = model.substr(model.rfind('.') + 1);
|
||||
@ -3447,7 +3447,7 @@ Net readNet(const String& _model, const String& _config, const String& _framewor
|
||||
Net readNet(const String& _framework, const std::vector<uchar>& bufferModel,
|
||||
const std::vector<uchar>& bufferConfig)
|
||||
{
|
||||
String framework = _framework.toLowerCase();
|
||||
String framework = toLowerCase(_framework);
|
||||
if (framework == "caffe")
|
||||
return readNetFromCaffe(bufferConfig, bufferModel);
|
||||
else if (framework == "tensorflow")
|
||||
|
@ -163,7 +163,7 @@ public:
|
||||
|
||||
void getCodeType(const LayerParams ¶ms)
|
||||
{
|
||||
String codeTypeString = params.get<String>("code_type").toLowerCase();
|
||||
String codeTypeString = toLowerCase(params.get<String>("code_type"));
|
||||
if (codeTypeString == "center_size")
|
||||
_codeType = "CENTER_SIZE";
|
||||
else
|
||||
|
@ -71,7 +71,7 @@ public:
|
||||
op = SUM;
|
||||
if (params.has("operation"))
|
||||
{
|
||||
String operation = params.get<String>("operation").toLowerCase();
|
||||
String operation = toLowerCase(params.get<String>("operation"));
|
||||
if (operation == "prod")
|
||||
op = PROD;
|
||||
else if (operation == "sum")
|
||||
|
@ -76,7 +76,7 @@ public:
|
||||
if (params.has("pool") || params.has("kernel_size") ||
|
||||
params.has("kernel_w") || params.has("kernel_h"))
|
||||
{
|
||||
String pool = params.get<String>("pool", "max").toLowerCase();
|
||||
String pool = toLowerCase(params.get<String>("pool", "max"));
|
||||
if (pool == "max")
|
||||
type = MAX;
|
||||
else if (pool == "ave")
|
||||
|
@ -349,16 +349,16 @@ Ptr<LSTMLayer> LSTMLayer::create(const LayerParams& params)
|
||||
|
||||
int LSTMLayer::inputNameToIndex(String inputName)
|
||||
{
|
||||
if (inputName.toLowerCase() == "x")
|
||||
if (toLowerCase(inputName) == "x")
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int LSTMLayer::outputNameToIndex(const String& outputName)
|
||||
{
|
||||
if (outputName.toLowerCase() == "h")
|
||||
if (toLowerCase(outputName) == "h")
|
||||
return 0;
|
||||
else if (outputName.toLowerCase() == "c")
|
||||
else if (toLowerCase(outputName) == "c")
|
||||
return 1;
|
||||
return -1;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user