42#ifndef OPENCV_DNN_DNN_INL_HPP 
   43#define OPENCV_DNN_DNN_INL_HPP 
   45#include <opencv2/dnn.hpp> 
   49CV__DNN_INLINE_NS_BEGIN
 
   51template<
typename TypeIter>
 
   54    DictValue res(Param::INT, 
new AutoBuffer<int64, 1>(size));
 
   55    for (
int j = 0; j < size; begin++, j++)
 
   56        (*res.pi)[j] = *begin;
 
   60template<
typename TypeIter>
 
   64    for (
int j = 0; j < size; begin++, j++)
 
   65        (*res.pd)[j] = *begin;
 
   69template<
typename TypeIter>
 
   73    for (
int j = 0; j < size; begin++, j++)
 
   74        (*res.ps)[j] = *begin;
 
   79inline DictValue DictValue::get<DictValue>(
int idx)
 const 
   86inline int64 DictValue::get<int64>(
int idx)
 const 
   88    CV_Assert((idx == -1 && size() == 1) || (idx >= 0 && idx < size()));
 
   89    idx = (idx == -1) ? 0 : idx;
 
   91    if (type == Param::INT)
 
   95    else if (type == Param::REAL)
 
   97        double doubleValue = (*pd)[idx];
 
   99        double fracpart, intpart;
 
  100        fracpart = std::modf(doubleValue, &intpart);
 
  103        return (int64)doubleValue;
 
  105    else if (type == Param::STRING)
 
  107        return std::atoi((*ps)[idx].c_str());
 
  111        CV_Assert(isInt() || isReal() || isString());
 
  117inline int DictValue::get<int>(
int idx)
 const 
  119    return (
int)get<int64>(idx);
 
  122inline int DictValue::getIntValue(
int idx)
 const 
  124    return (
int)get<int64>(idx);
 
  128inline unsigned DictValue::get<unsigned>(
int idx)
 const 
  130    return (
unsigned)get<int64>(idx);
 
  134inline bool DictValue::get<bool>(
int idx)
 const 
  136    return (get<int64>(idx) != 0);
 
  140inline double DictValue::get<double>(
int idx)
 const 
  142    CV_Assert((idx == -1 && size() == 1) || (idx >= 0 && idx < size()));
 
  143    idx = (idx == -1) ? 0 : idx;
 
  145    if (type == Param::REAL)
 
  149    else if (type == Param::INT)
 
  151        return (
double)(*pi)[idx];
 
  153    else if (type == Param::STRING)
 
  155        return std::atof((*ps)[idx].c_str());
 
  159        CV_Assert(isReal() || isInt() || isString());
 
  164inline double DictValue::getRealValue(
int idx)
 const 
  166    return get<double>(idx);
 
  170inline float DictValue::get<float>(
int idx)
 const 
  172    return (
float)get<double>(idx);
 
  176inline String DictValue::get<String>(
int idx)
 const 
  179    CV_Assert((idx == -1 && ps->size() == 1) || (idx >= 0 && idx < (
int)ps->size()));
 
  180    return (*ps)[(idx == -1) ? 0 : idx];
 
  184inline String DictValue::getStringValue(
int idx)
 const 
  186    return get<String>(idx);
 
  189inline void DictValue::release()
 
  204    case Param::MAT_VECTOR:
 
  205    case Param::ALGORITHM:
 
  207    case Param::UNSIGNED_INT:
 
  215inline DictValue::~DictValue()
 
  220inline DictValue & DictValue::operator=(
const DictValue &r)
 
  225    if (r.type == Param::INT)
 
  227        AutoBuffer<int64, 1> *tmp = 
new AutoBuffer<int64, 1>(*r.pi);
 
  231    else if (r.type == Param::STRING)
 
  233        AutoBuffer<String, 1> *tmp = 
new AutoBuffer<String, 1>(*r.ps);
 
  237    else if (r.type == Param::REAL)
 
  239        AutoBuffer<double, 1> *tmp = 
new AutoBuffer<double, 1>(*r.pd);
 
  249inline DictValue::DictValue(
const DictValue &r)
 
  254    if (r.type == Param::INT)
 
  255        pi = 
new AutoBuffer<int64, 1>(*r.pi);
 
  256    else if (r.type == Param::STRING)
 
  257        ps = 
new AutoBuffer<String, 1>(*r.ps);
 
  258    else if (r.type == Param::REAL)
 
  259        pd = 
new AutoBuffer<double, 1>(*r.pd);
 
  262inline bool DictValue::isString()
 const 
  264    return (type == Param::STRING);
 
  267inline bool DictValue::isInt()
 const 
  269    return (type == Param::INT);
 
  272inline bool DictValue::isReal()
 const 
  274    return (type == Param::REAL || type == Param::INT);
 
  277inline int DictValue::size()
 const 
  282        return (
int)pi->size();
 
  284        return (
int)ps->size();
 
  286        return (
int)pd->size();
 
  289    case Param::MAT_VECTOR:
 
  290    case Param::ALGORITHM:
 
  292    case Param::UNSIGNED_INT:
 
  298    CV_Error_(Error::StsInternal, (
"Unhandled type (%d)", 
static_cast<int>(type)));
 
  301inline std::ostream &operator<<(std::ostream &stream, 
const DictValue &dictv)
 
  307        for (i = 0; i < dictv.size() - 1; i++)
 
  308            stream << dictv.get<int64>(i) << 
", ";
 
  309        stream << dictv.get<int64>(i);
 
  311    else if (dictv.isReal())
 
  313        for (i = 0; i < dictv.size() - 1; i++)
 
  314            stream << dictv.get<
double>(i) << 
", ";
 
  315        stream << dictv.get<
double>(i);
 
  317    else if (dictv.isString())
 
  319        for (i = 0; i < dictv.size() - 1; i++)
 
  320            stream << 
"\"" << dictv.get<String>(i) << 
"\", ";
 
  321        stream << dictv.get<String>(i);
 
  331    return dict.count(key) != 0;
 
  336    _Dict::iterator i = dict.find(key);
 
  337    return (i == dict.end()) ? NULL : &i->second;
 
  342    _Dict::const_iterator i = dict.find(key);
 
  343    return (i == dict.end()) ? NULL : &i->second;
 
  348    _Dict::const_iterator i = dict.find(key);
 
  350        CV_Error(Error::StsObjectNotFound, 
"Required argument \"" + key + 
"\" not found into dictionary");
 
  357    return this->
get(key).
get<T>();
 
  361inline T 
Dict::get(
const String &key, 
const T &defaultValue)
 const 
  363    _Dict::const_iterator i = dict.find(key);
 
  366        return i->second.get<T>();
 
  372inline const T &
Dict::set(
const String &key, 
const T &value)
 
  374    _Dict::iterator i = dict.find(key);
 
  379        dict.insert(std::make_pair(key, 
DictValue(value)));
 
  389inline std::ostream &operator<<(std::ostream &stream, 
const Dict &dict)
 
  391    Dict::_Dict::const_iterator it;
 
  392    for (it = dict.dict.begin(); it != dict.dict.end(); it++)
 
  393        stream << it->first << 
" : " << it->second << 
"\n";
 
  398inline std::map<String, DictValue>::const_iterator Dict::begin()
 const 
  403inline std::map<String, DictValue>::const_iterator Dict::end()
 const 
Automatically Allocated Buffer Class
Definition: utility.hpp:102
 
This class implements name-value dictionary, values are instances of DictValue.
Definition: dict.hpp:115
 
DictValue * ptr(const String &key)
If the key in the dictionary then returns pointer to its value, else returns NULL.
Definition: dnn.inl.hpp:334
 
const T & set(const String &key, const T &value)
Sets new value for the key, or adds new key-value pair into the dictionary.
Definition: dnn.inl.hpp:372
 
void erase(const String &key)
Erase key from the dictionary.
Definition: dnn.inl.hpp:384
 
const DictValue & get(const String &key) const
If the key in the dictionary then returns its value, else an error will be generated.
Definition: dnn.inl.hpp:346
 
bool has(const String &key) const
Checks a presence of the key in the dictionary.
Definition: dnn.inl.hpp:329
 
#define CV_Error_(code, args)
Call the error handler.
Definition: base.hpp:334
 
#define CV_Error(code, msg)
Call the error handler.
Definition: base.hpp:320
 
#define CV_Assert(expr)
Checks a condition at runtime and throws exception if it fails
Definition: base.hpp:342
 
"black box" representation of the file storage associated with a file on disk.
Definition: aruco.hpp:75
 
This struct stores the scalar value (or array) of one of the following type: double,...
Definition: dict.hpp:61
 
static DictValue arrayInt(TypeIter begin, int size)
Constructs integer array
 
static DictValue arrayString(TypeIter begin, int size)
Constructs array of strings
Definition: dnn.inl.hpp:70
 
static DictValue arrayReal(TypeIter begin, int size)
Constructs floating point array
Definition: dnn.inl.hpp:61
 
T get(int idx=-1) const
Tries to convert array element with specified index to requested type and returns its.