version:2.1.5

bugfixes:
update:拨号使用ocr进行识别
This commit is contained in:
2025-05-22 14:30:12 +08:00
parent a86592005f
commit d7e830985f
226 changed files with 66016 additions and 81139 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -49,127 +49,112 @@
#define OPENCV_DNN_DNN_DICT_HPP
namespace cv {
namespace dnn {
CV__DNN_INLINE_NS_BEGIN
namespace dnn {
CV__DNN_INLINE_NS_BEGIN
//! @addtogroup dnn
//! @{
/** @brief This struct stores the scalar value (or array) of one of the following type: double, cv::String or int64.
* @todo Maybe int64 is useless because double type exactly stores at least 2^52 integers.
*/
struct CV_EXPORTS_W DictValue {
DictValue(const DictValue &r);
struct CV_EXPORTS_W DictValue
{
DictValue(const DictValue &r);
DictValue(bool i) : type(Param::INT), pi(new AutoBuffer<int64,1>) { (*pi)[0] = i ? 1 : 0; } //!< Constructs integer scalar
DictValue(int64 i = 0) : type(Param::INT), pi(new AutoBuffer<int64,1>) { (*pi)[0] = i; } //!< Constructs integer scalar
CV_WRAP DictValue(int i) : type(Param::INT), pi(new AutoBuffer<int64,1>) { (*pi)[0] = i; } //!< Constructs integer scalar
DictValue(unsigned p) : type(Param::INT), pi(new AutoBuffer<int64,1>) { (*pi)[0] = p; } //!< Constructs integer scalar
CV_WRAP DictValue(double p) : type(Param::REAL), pd(new AutoBuffer<double,1>) { (*pd)[0] = p; } //!< Constructs floating point scalar
CV_WRAP DictValue(const String &s) : type(Param::STRING), ps(new AutoBuffer<String,1>) { (*ps)[0] = s; } //!< Constructs string scalar
DictValue(const char *s) : type(Param::STRING), ps(new AutoBuffer<String,1>) { (*ps)[0] = s; } //!< @overload
DictValue(bool i) : type(Param::INT), pi(new AutoBuffer<int64, 1>) {
(*pi)[0] = i ? 1 : 0;
} //!< Constructs integer scalar
DictValue(int64 i = 0) : type(Param::INT),
pi(new AutoBuffer<int64, 1>) { (*pi)[0] = i; } //!< Constructs integer scalar
CV_WRAP DictValue(int i) : type(Param::INT),
pi(new AutoBuffer<int64, 1>) { (*pi)[0] = i; } //!< Constructs integer scalar
DictValue(unsigned p) : type(Param::INT),
pi(new AutoBuffer<int64, 1>) { (*pi)[0] = p; } //!< Constructs integer scalar
CV_WRAP DictValue(double p) : type(Param::REAL),
pd(new AutoBuffer<double, 1>) { (*pd)[0] = p; } //!< Constructs floating point scalar
CV_WRAP DictValue(const String &s) : type(Param::STRING),
ps(new AutoBuffer<String, 1>) { (*ps)[0] = s; } //!< Constructs string scalar
DictValue(const char *s) : type(Param::STRING),
ps(new AutoBuffer<String, 1>) { (*ps)[0] = s; } //!< @overload
template<typename TypeIter>
static DictValue arrayInt(TypeIter begin, int size); //!< Constructs integer array
template<typename TypeIter>
static DictValue arrayReal(TypeIter begin, int size); //!< Constructs floating point array
template<typename TypeIter>
static DictValue arrayString(TypeIter begin, int size); //!< Constructs array of strings
template<typename TypeIter>
static DictValue
arrayInt(TypeIter begin, int size); //!< Constructs integer array
template<typename TypeIter>
static DictValue
arrayReal(TypeIter begin, int size); //!< Constructs floating point array
template<typename TypeIter>
static DictValue
arrayString(TypeIter begin, int size); //!< Constructs array of strings
template<typename T>
T get(int idx = -1) const; //!< Tries to convert array element with specified index to requested type and returns its.
template<typename T>
T
get(int idx = -1) const; //!< Tries to convert array element with specified index to requested type and returns its.
int size() const;
int size() const;
CV_WRAP bool isInt() const;
CV_WRAP bool isString() const;
CV_WRAP bool isReal() const;
CV_WRAP bool isInt() const;
CV_WRAP int getIntValue(int idx = -1) const;
CV_WRAP double getRealValue(int idx = -1) const;
CV_WRAP String getStringValue(int idx = -1) const;
CV_WRAP bool isString() const;
DictValue &operator=(const DictValue &r);
CV_WRAP bool isReal() const;
friend std::ostream &operator<<(std::ostream &stream, const DictValue &dictv);
CV_WRAP int getIntValue(int idx = -1) const;
~DictValue();
CV_WRAP double getRealValue(int idx = -1) const;
private:
CV_WRAP String getStringValue(int idx = -1) const;
Param type;
DictValue &operator=(const DictValue &r);
union
{
AutoBuffer<int64, 1> *pi;
AutoBuffer<double, 1> *pd;
AutoBuffer<String, 1> *ps;
void *pv;
};
friend std::ostream &operator<<(std::ostream &stream, const DictValue &dictv);
~DictValue();
private:
Param type;
union {
AutoBuffer<int64, 1> *pi;
AutoBuffer<double, 1> *pd;
AutoBuffer<String, 1> *ps;
void *pv;
};
DictValue(Param _type, void *_p) : type(_type), pv(_p) {}
void release();
};
DictValue(Param _type, void *_p) : type(_type), pv(_p) {}
void release();
};
/** @brief This class implements name-value dictionary, values are instances of DictValue. */
class CV_EXPORTS Dict {
typedef std::map<String, DictValue> _Dict;
_Dict dict;
class CV_EXPORTS Dict
{
typedef std::map<String, DictValue> _Dict;
_Dict dict;
public:
public:
//! Checks a presence of the @p key in the dictionary.
bool has(const String &key) const;
//! Checks a presence of the @p key in the dictionary.
bool has(const String &key) const;
//! If the @p key in the dictionary then returns pointer to its value, else returns NULL.
DictValue *ptr(const String &key);
//! If the @p key in the dictionary then returns pointer to its value, else returns NULL.
DictValue *ptr(const String &key);
/** @overload */
const DictValue *ptr(const String &key) const;
/** @overload */
const DictValue *ptr(const String &key) const;
//! If the @p key in the dictionary then returns its value, else an error will be generated.
const DictValue &get(const String &key) const;
//! If the @p key in the dictionary then returns its value, else an error will be generated.
const DictValue &get(const String &key) const;
/** @overload */
template<typename T>
T get(const String &key) const;
/** @overload */
template <typename T>
T get(const String &key) const;
//! If the @p key in the dictionary then returns its value, else returns @p defaultValue.
template<typename T>
T get(const String &key, const T &defaultValue) const;
//! If the @p key in the dictionary then returns its value, else returns @p defaultValue.
template <typename T>
T get(const String &key, const T &defaultValue) const;
//! Sets new @p value for the @p key, or adds new key-value pair into the dictionary.
template<typename T>
const T &set(const String &key, const T &value);
//! Sets new @p value for the @p key, or adds new key-value pair into the dictionary.
template<typename T>
const T &set(const String &key, const T &value);
//! Erase @p key from the dictionary.
void erase(const String &key);
//! Erase @p key from the dictionary.
void erase(const String &key);
friend std::ostream &operator<<(std::ostream &stream, const Dict &dict);
friend std::ostream &operator<<(std::ostream &stream, const Dict &dict);
std::map<String, DictValue>::const_iterator begin() const;
std::map<String, DictValue>::const_iterator begin() const;
std::map<String, DictValue>::const_iterator end() const;
};
std::map<String, DictValue>::const_iterator end() const;
};
//! @}
CV__DNN_INLINE_NS_END
}
CV__DNN_INLINE_NS_END
}
}
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -45,308 +45,367 @@
#include <opencv2/dnn.hpp>
namespace cv {
namespace dnn {
CV__DNN_INLINE_NS_BEGIN
namespace dnn {
CV__DNN_INLINE_NS_BEGIN
template<typename TypeIter>
DictValue DictValue::arrayInt(TypeIter begin, int size) {
DictValue res(Param::INT, new AutoBuffer<int64, 1>(size));
for (int j = 0; j < size; begin++, j++)
(*res.pi)[j] = *begin;
return res;
}
template<typename TypeIter>
DictValue DictValue::arrayInt(TypeIter begin, int size)
{
DictValue res(Param::INT, new AutoBuffer<int64, 1>(size));
for (int j = 0; j < size; begin++, j++)
(*res.pi)[j] = *begin;
return res;
}
template<typename TypeIter>
DictValue DictValue::arrayReal(TypeIter begin, int size) {
DictValue res(Param::REAL, new AutoBuffer<double, 1>(size));
for (int j = 0; j < size; begin++, j++)
(*res.pd)[j] = *begin;
return res;
}
template<typename TypeIter>
DictValue DictValue::arrayReal(TypeIter begin, int size)
{
DictValue res(Param::REAL, new AutoBuffer<double, 1>(size));
for (int j = 0; j < size; begin++, j++)
(*res.pd)[j] = *begin;
return res;
}
template<typename TypeIter>
DictValue DictValue::arrayString(TypeIter begin, int size) {
DictValue res(Param::STRING, new AutoBuffer<String, 1>(size));
for (int j = 0; j < size; begin++, j++)
(*res.ps)[j] = *begin;
return res;
}
template<typename TypeIter>
DictValue DictValue::arrayString(TypeIter begin, int size)
{
DictValue res(Param::STRING, new AutoBuffer<String, 1>(size));
for (int j = 0; j < size; begin++, j++)
(*res.ps)[j] = *begin;
return res;
}
template<>
inline DictValue DictValue::get<DictValue>(int idx) const {
CV_Assert(idx == -1);
return *this;
}
template<>
inline DictValue DictValue::get<DictValue>(int idx) const
{
CV_Assert(idx == -1);
return *this;
}
template<>
inline int64 DictValue::get<int64>(int idx) const {
CV_Assert((idx == -1 && size() == 1) || (idx >= 0 && idx < size()));
idx = (idx == -1) ? 0 : idx;
template<>
inline int64 DictValue::get<int64>(int idx) const
{
CV_Assert((idx == -1 && size() == 1) || (idx >= 0 && idx < size()));
idx = (idx == -1) ? 0 : idx;
if (type == Param::INT) {
return (*pi)[idx];
} else if (type == Param::REAL) {
double doubleValue = (*pd)[idx];
if (type == Param::INT)
{
return (*pi)[idx];
}
else if (type == Param::REAL)
{
double doubleValue = (*pd)[idx];
double fracpart, intpart;
fracpart = std::modf(doubleValue, &intpart);
CV_Assert(fracpart == 0.0);
double fracpart, intpart;
fracpart = std::modf(doubleValue, &intpart);
CV_Assert(fracpart == 0.0);
return (int64) doubleValue;
} else if (type == Param::STRING) {
return std::atoi((*ps)[idx].c_str());
} else {
CV_Assert(isInt() || isReal() || isString());
return 0;
}
}
template<>
inline int DictValue::get<int>(int idx) const {
return (int) get < int64 > (idx);
}
inline int DictValue::getIntValue(int idx) const {
return (int) get<int64>(idx);
}
template<>
inline unsigned DictValue::get<unsigned>(int idx) const {
return (unsigned) get < int64 > (idx);
}
template<>
inline bool DictValue::get<bool>(int idx) const {
return (get < int64 > (idx) != 0);
}
template<>
inline double DictValue::get<double>(int idx) const {
CV_Assert((idx == -1 && size() == 1) || (idx >= 0 && idx < size()));
idx = (idx == -1) ? 0 : idx;
if (type == Param::REAL) {
return (*pd)[idx];
} else if (type == Param::INT) {
return (double) (*pi)[idx];
} else if (type == Param::STRING) {
return std::atof((*ps)[idx].c_str());
} else {
CV_Assert(isReal() || isInt() || isString());
return 0;
}
}
inline double DictValue::getRealValue(int idx) const {
return get<double>(idx);
}
template<>
inline float DictValue::get<float>(int idx) const {
return (float) get < double > (idx);
}
template<>
inline String DictValue::get<String>(int idx) const {
CV_Assert(isString());
CV_Assert((idx == -1 && ps->size() == 1) || (idx >= 0 && idx < (int) ps->size()));
return (*ps)[(idx == -1) ? 0 : idx];
}
inline String DictValue::getStringValue(int idx) const {
return get<String>(idx);
}
inline void DictValue::release() {
switch (type) {
case Param::INT:
delete pi;
break;
case Param::STRING:
delete ps;
break;
case Param::REAL:
delete pd;
break;
case Param::BOOLEAN:
case Param::MAT:
case Param::MAT_VECTOR:
case Param::ALGORITHM:
case Param::FLOAT:
case Param::UNSIGNED_INT:
case Param::UINT64:
case Param::UCHAR:
case Param::SCALAR:
break; // unhandled
}
}
inline DictValue::~DictValue() {
release();
}
inline DictValue &DictValue::operator=(const DictValue &r) {
if (&r == this)
return *this;
if (r.type == Param::INT) {
AutoBuffer<int64, 1> *tmp = new AutoBuffer<int64, 1>(*r.pi);
release();
pi = tmp;
} else if (r.type == Param::STRING) {
AutoBuffer<String, 1> *tmp = new AutoBuffer<String, 1>(*r.ps);
release();
ps = tmp;
} else if (r.type == Param::REAL) {
AutoBuffer<double, 1> *tmp = new AutoBuffer<double, 1>(*r.pd);
release();
pd = tmp;
}
type = r.type;
return *this;
}
inline DictValue::DictValue(const DictValue &r) {
type = r.type;
if (r.type == Param::INT)
pi = new AutoBuffer<int64, 1>(*r.pi);
else if (r.type == Param::STRING)
ps = new AutoBuffer<String, 1>(*r.ps);
else if (r.type == Param::REAL)
pd = new AutoBuffer<double, 1>(*r.pd);
}
inline bool DictValue::isString() const {
return (type == Param::STRING);
}
inline bool DictValue::isInt() const {
return (type == Param::INT);
}
inline bool DictValue::isReal() const {
return (type == Param::REAL || type == Param::INT);
}
inline int DictValue::size() const {
switch (type) {
case Param::INT:
return (int) pi->size();
case Param::STRING:
return (int) ps->size();
case Param::REAL:
return (int) pd->size();
case Param::BOOLEAN:
case Param::MAT:
case Param::MAT_VECTOR:
case Param::ALGORITHM:
case Param::FLOAT:
case Param::UNSIGNED_INT:
case Param::UINT64:
case Param::UCHAR:
case Param::SCALAR:
break; // unhandled
}
CV_Error_(Error::StsInternal, ("Unhandled type (%d)", static_cast<int>(type)));
}
inline std::ostream &operator<<(std::ostream &stream, const DictValue &dictv) {
int i;
if (dictv.isInt()) {
for (i = 0; i < dictv.size() - 1; i++)
stream << dictv.get<int64>(i) << ", ";
stream << dictv.get<int64>(i);
} else if (dictv.isReal()) {
for (i = 0; i < dictv.size() - 1; i++)
stream << dictv.get<double>(i) << ", ";
stream << dictv.get<double>(i);
} else if (dictv.isString()) {
for (i = 0; i < dictv.size() - 1; i++)
stream << "\"" << dictv.get<String>(i) << "\", ";
stream << dictv.get<String>(i);
}
return stream;
}
/////////////////////////////////////////////////////////////////
inline bool Dict::has(const String &key) const {
return dict.count(key) != 0;
}
inline DictValue *Dict::ptr(const String &key) {
_Dict::iterator i = dict.find(key);
return (i == dict.end()) ? NULL : &i->second;
}
inline const DictValue *Dict::ptr(const String &key) const {
_Dict::const_iterator i = dict.find(key);
return (i == dict.end()) ? NULL : &i->second;
}
inline const DictValue &Dict::get(const String &key) const {
_Dict::const_iterator i = dict.find(key);
if (i == dict.end())
CV_Error(Error::StsObjectNotFound,
"Required argument \"" + key + "\" not found into dictionary");
return i->second;
}
template<typename T>
inline T Dict::get(const String &key) const {
return this->get(key).get<T>();
}
template<typename T>
inline T Dict::get(const String &key, const T &defaultValue) const {
_Dict::const_iterator i = dict.find(key);
if (i != dict.end())
return i->second.get<T>();
else
return defaultValue;
}
template<typename T>
inline const T &Dict::set(const String &key, const T &value) {
_Dict::iterator i = dict.find(key);
if (i != dict.end())
i->second = DictValue(value);
else
dict.insert(std::make_pair(key, DictValue(value)));
return value;
}
inline void Dict::erase(const String &key) {
dict.erase(key);
}
inline std::ostream &operator<<(std::ostream &stream, const Dict &dict) {
Dict::_Dict::const_iterator it;
for (it = dict.dict.begin(); it != dict.dict.end(); it++)
stream << it->first << " : " << it->second << "\n";
return stream;
}
inline std::map<String, DictValue>::const_iterator Dict::begin() const {
return dict.begin();
}
inline std::map<String, DictValue>::const_iterator Dict::end() const {
return dict.end();
}
CV__DNN_INLINE_NS_END
return (int64)doubleValue;
}
else if (type == Param::STRING)
{
return std::atoi((*ps)[idx].c_str());
}
else
{
CV_Assert(isInt() || isReal() || isString());
return 0;
}
}
template<>
inline int DictValue::get<int>(int idx) const
{
return (int)get<int64>(idx);
}
inline int DictValue::getIntValue(int idx) const
{
return (int)get<int64>(idx);
}
template<>
inline unsigned DictValue::get<unsigned>(int idx) const
{
return (unsigned)get<int64>(idx);
}
template<>
inline bool DictValue::get<bool>(int idx) const
{
return (get<int64>(idx) != 0);
}
template<>
inline double DictValue::get<double>(int idx) const
{
CV_Assert((idx == -1 && size() == 1) || (idx >= 0 && idx < size()));
idx = (idx == -1) ? 0 : idx;
if (type == Param::REAL)
{
return (*pd)[idx];
}
else if (type == Param::INT)
{
return (double)(*pi)[idx];
}
else if (type == Param::STRING)
{
return std::atof((*ps)[idx].c_str());
}
else
{
CV_Assert(isReal() || isInt() || isString());
return 0;
}
}
inline double DictValue::getRealValue(int idx) const
{
return get<double>(idx);
}
template<>
inline float DictValue::get<float>(int idx) const
{
return (float)get<double>(idx);
}
template<>
inline String DictValue::get<String>(int idx) const
{
CV_Assert(isString());
CV_Assert((idx == -1 && ps->size() == 1) || (idx >= 0 && idx < (int)ps->size()));
return (*ps)[(idx == -1) ? 0 : idx];
}
inline String DictValue::getStringValue(int idx) const
{
return get<String>(idx);
}
inline void DictValue::release()
{
switch (type)
{
case Param::INT:
delete pi;
break;
case Param::STRING:
delete ps;
break;
case Param::REAL:
delete pd;
break;
case Param::BOOLEAN:
case Param::MAT:
case Param::MAT_VECTOR:
case Param::ALGORITHM:
case Param::FLOAT:
case Param::UNSIGNED_INT:
case Param::UINT64:
case Param::UCHAR:
case Param::SCALAR:
break; // unhandled
}
}
inline DictValue::~DictValue()
{
release();
}
inline DictValue & DictValue::operator=(const DictValue &r)
{
if (&r == this)
return *this;
if (r.type == Param::INT)
{
AutoBuffer<int64, 1> *tmp = new AutoBuffer<int64, 1>(*r.pi);
release();
pi = tmp;
}
else if (r.type == Param::STRING)
{
AutoBuffer<String, 1> *tmp = new AutoBuffer<String, 1>(*r.ps);
release();
ps = tmp;
}
else if (r.type == Param::REAL)
{
AutoBuffer<double, 1> *tmp = new AutoBuffer<double, 1>(*r.pd);
release();
pd = tmp;
}
type = r.type;
return *this;
}
inline DictValue::DictValue(const DictValue &r)
{
type = r.type;
if (r.type == Param::INT)
pi = new AutoBuffer<int64, 1>(*r.pi);
else if (r.type == Param::STRING)
ps = new AutoBuffer<String, 1>(*r.ps);
else if (r.type == Param::REAL)
pd = new AutoBuffer<double, 1>(*r.pd);
}
inline bool DictValue::isString() const
{
return (type == Param::STRING);
}
inline bool DictValue::isInt() const
{
return (type == Param::INT);
}
inline bool DictValue::isReal() const
{
return (type == Param::REAL || type == Param::INT);
}
inline int DictValue::size() const
{
switch (type)
{
case Param::INT:
return (int)pi->size();
case Param::STRING:
return (int)ps->size();
case Param::REAL:
return (int)pd->size();
case Param::BOOLEAN:
case Param::MAT:
case Param::MAT_VECTOR:
case Param::ALGORITHM:
case Param::FLOAT:
case Param::UNSIGNED_INT:
case Param::UINT64:
case Param::UCHAR:
case Param::SCALAR:
break; // unhandled
}
CV_Error_(Error::StsInternal, ("Unhandled type (%d)", static_cast<int>(type)));
}
inline std::ostream &operator<<(std::ostream &stream, const DictValue &dictv)
{
int i;
if (dictv.isInt())
{
for (i = 0; i < dictv.size() - 1; i++)
stream << dictv.get<int64>(i) << ", ";
stream << dictv.get<int64>(i);
}
else if (dictv.isReal())
{
for (i = 0; i < dictv.size() - 1; i++)
stream << dictv.get<double>(i) << ", ";
stream << dictv.get<double>(i);
}
else if (dictv.isString())
{
for (i = 0; i < dictv.size() - 1; i++)
stream << "\"" << dictv.get<String>(i) << "\", ";
stream << dictv.get<String>(i);
}
return stream;
}
/////////////////////////////////////////////////////////////////
inline bool Dict::has(const String &key) const
{
return dict.count(key) != 0;
}
inline DictValue *Dict::ptr(const String &key)
{
_Dict::iterator i = dict.find(key);
return (i == dict.end()) ? NULL : &i->second;
}
inline const DictValue *Dict::ptr(const String &key) const
{
_Dict::const_iterator i = dict.find(key);
return (i == dict.end()) ? NULL : &i->second;
}
inline const DictValue &Dict::get(const String &key) const
{
_Dict::const_iterator i = dict.find(key);
if (i == dict.end())
CV_Error(Error::StsObjectNotFound, "Required argument \"" + key + "\" not found into dictionary");
return i->second;
}
template <typename T>
inline T Dict::get(const String &key) const
{
return this->get(key).get<T>();
}
template <typename T>
inline T Dict::get(const String &key, const T &defaultValue) const
{
_Dict::const_iterator i = dict.find(key);
if (i != dict.end())
return i->second.get<T>();
else
return defaultValue;
}
template<typename T>
inline const T &Dict::set(const String &key, const T &value)
{
_Dict::iterator i = dict.find(key);
if (i != dict.end())
i->second = DictValue(value);
else
dict.insert(std::make_pair(key, DictValue(value)));
return value;
}
inline void Dict::erase(const String &key)
{
dict.erase(key);
}
inline std::ostream &operator<<(std::ostream &stream, const Dict &dict)
{
Dict::_Dict::const_iterator it;
for (it = dict.dict.begin(); it != dict.dict.end(); it++)
stream << it->first << " : " << it->second << "\n";
return stream;
}
inline std::map<String, DictValue>::const_iterator Dict::begin() const
{
return dict.begin();
}
inline std::map<String, DictValue>::const_iterator Dict::end() const
{
return dict.end();
}
CV__DNN_INLINE_NS_END
}
}
#endif

View File

@@ -8,8 +8,8 @@
#include <opencv2/dnn/layer.hpp>
namespace cv {
namespace dnn {
CV__DNN_INLINE_NS_BEGIN
namespace dnn {
CV__DNN_INLINE_NS_BEGIN
/** @brief Registers layer constructor in runtime.
* @param type string, containing type name of the layer.
@@ -45,32 +45,34 @@ Ptr<Layer> __LayerStaticRegisterer_func_##type(LayerParams &params) \
{ return Ptr<Layer>(new class(params)); } \
static cv::dnn::details::_LayerStaticRegisterer __LayerStaticRegisterer_##type(#type, __LayerStaticRegisterer_func_##type);
namespace details {
namespace details {
template<typename LayerClass>
Ptr <Layer> _layerDynamicRegisterer(LayerParams &params) {
return Ptr<Layer>(LayerClass::create(params));
}
template<typename LayerClass>
Ptr<Layer> _layerDynamicRegisterer(LayerParams &params)
{
return Ptr<Layer>(LayerClass::create(params));
}
//allows automatically register created layer on module load time
class _LayerStaticRegisterer {
String type;
public:
class _LayerStaticRegisterer
{
String type;
public:
_LayerStaticRegisterer(const String &layerType,
LayerFactory::Constructor layerConstructor) {
this->type = layerType;
LayerFactory::registerLayer(layerType, layerConstructor);
}
~_LayerStaticRegisterer() {
LayerFactory::unregisterLayer(type);
}
};
} // namespace
CV__DNN_INLINE_NS_END
_LayerStaticRegisterer(const String &layerType, LayerFactory::Constructor layerConstructor)
{
this->type = layerType;
LayerFactory::registerLayer(layerType, layerConstructor);
}
~_LayerStaticRegisterer()
{
LayerFactory::unregisterLayer(type);
}
};
} // namespace
CV__DNN_INLINE_NS_END
}} // namespace
#endif

View File

@@ -41,12 +41,11 @@
#ifndef OPENCV_DNN_LAYER_HPP
#define OPENCV_DNN_LAYER_HPP
#include <opencv2/dnn.hpp>
namespace cv {
namespace dnn {
CV__DNN_INLINE_NS_BEGIN
namespace dnn {
CV__DNN_INLINE_NS_BEGIN
//! @addtogroup dnn
//! @{
//!
@@ -54,32 +53,33 @@ namespace cv {
//! @{
/** @brief %Layer factory allows to create instances of registered layers. */
class CV_EXPORTS LayerFactory {
public:
class CV_EXPORTS LayerFactory
{
public:
//! Each Layer class must provide this function to the factory
typedef Ptr<Layer>(*Constructor)(LayerParams &params);
//! Each Layer class must provide this function to the factory
typedef Ptr<Layer>(*Constructor)(LayerParams &params);
//! Registers the layer class with typename @p type and specified @p constructor. Thread-safe.
static void registerLayer(const String &type, Constructor constructor);
//! Registers the layer class with typename @p type and specified @p constructor. Thread-safe.
static void registerLayer(const String &type, Constructor constructor);
//! Unregisters registered layer with specified type name. Thread-safe.
static void unregisterLayer(const String &type);
//! Unregisters registered layer with specified type name. Thread-safe.
static void unregisterLayer(const String &type);
/** @brief Creates instance of registered layer.
* @param type type name of creating layer.
* @param params parameters which will be used for layer initialization.
* @note Thread-safe.
*/
static Ptr <Layer> createLayerInstance(const String &type, LayerParams &params);
/** @brief Creates instance of registered layer.
* @param type type name of creating layer.
* @param params parameters which will be used for layer initialization.
* @note Thread-safe.
*/
static Ptr<Layer> createLayerInstance(const String &type, LayerParams& params);
private:
LayerFactory();
};
private:
LayerFactory();
};
//! @}
//! @}
CV__DNN_INLINE_NS_END
}
CV__DNN_INLINE_NS_END
}
}
#endif

View File

@@ -49,155 +49,171 @@
#include <sstream>
namespace cv {
namespace dnn {
CV__DNN_INLINE_NS_BEGIN
namespace dnn {
CV__DNN_INLINE_NS_BEGIN
//Slicing
struct _Range : public cv::Range {
_Range(const Range &r) : cv::Range(r) {}
struct _Range : public cv::Range
{
_Range(const Range &r) : cv::Range(r) {}
_Range(int start_, int size_ = 1) : cv::Range(start_, start_ + size_) {}
};
_Range(int start_, int size_ = 1) : cv::Range(start_, start_ + size_) {}
};
static inline Mat slice(const Mat &m, const _Range &r0)
{
Range ranges[CV_MAX_DIM];
for (int i = 1; i < m.dims; i++)
ranges[i] = Range::all();
ranges[0] = r0;
return m(&ranges[0]);
}
static inline Mat slice(const Mat &m, const _Range &r0) {
Range ranges[CV_MAX_DIM];
for (int i = 1; i < m.dims; i++)
ranges[i] = Range::all();
ranges[0] = r0;
return m(&ranges[0]);
}
static inline Mat slice(const Mat &m, const _Range &r0, const _Range &r1)
{
CV_Assert(m.dims >= 2);
Range ranges[CV_MAX_DIM];
for (int i = 2; i < m.dims; i++)
ranges[i] = Range::all();
ranges[0] = r0;
ranges[1] = r1;
return m(&ranges[0]);
}
static inline Mat slice(const Mat &m, const _Range &r0, const _Range &r1) {
CV_Assert(m.dims >= 2);
Range ranges[CV_MAX_DIM];
for (int i = 2; i < m.dims; i++)
ranges[i] = Range::all();
ranges[0] = r0;
ranges[1] = r1;
return m(&ranges[0]);
}
static inline Mat slice(const Mat &m, const _Range &r0, const _Range &r1, const _Range &r2)
{
CV_Assert(m.dims >= 3);
Range ranges[CV_MAX_DIM];
for (int i = 3; i < m.dims; i++)
ranges[i] = Range::all();
ranges[0] = r0;
ranges[1] = r1;
ranges[2] = r2;
return m(&ranges[0]);
}
static inline Mat
slice(const Mat &m, const _Range &r0, const _Range &r1, const _Range &r2) {
CV_Assert(m.dims >= 3);
Range ranges[CV_MAX_DIM];
for (int i = 3; i < m.dims; i++)
ranges[i] = Range::all();
ranges[0] = r0;
ranges[1] = r1;
ranges[2] = r2;
return m(&ranges[0]);
}
static inline Mat slice(const Mat &m, const _Range &r0, const _Range &r1, const _Range &r2, const _Range &r3)
{
CV_Assert(m.dims >= 4);
Range ranges[CV_MAX_DIM];
for (int i = 4; i < m.dims; i++)
ranges[i] = Range::all();
ranges[0] = r0;
ranges[1] = r1;
ranges[2] = r2;
ranges[3] = r3;
return m(&ranges[0]);
}
static inline Mat slice(const Mat &m, const _Range &r0, const _Range &r1, const _Range &r2,
const _Range &r3) {
CV_Assert(m.dims >= 4);
Range ranges[CV_MAX_DIM];
for (int i = 4; i < m.dims; i++)
ranges[i] = Range::all();
ranges[0] = r0;
ranges[1] = r1;
ranges[2] = r2;
ranges[3] = r3;
return m(&ranges[0]);
}
static inline Mat getPlane(const Mat &m, int n, int cn) {
CV_Assert(m.dims > 2);
int sz[CV_MAX_DIM];
for (int i = 2; i < m.dims; i++) {
sz[i - 2] = m.size.p[i];
}
return Mat(m.dims - 2, sz, m.type(), (void *) m.ptr<float>(n, cn));
}
static inline MatShape shape(const int *dims, const int n) {
MatShape shape;
shape.assign(dims, dims + n);
return shape;
}
static inline MatShape shape(const Mat &mat) {
return shape(mat.size.p, mat.dims);
}
static inline MatShape shape(const MatSize &sz) {
return shape(sz.p, sz.dims());
}
static inline MatShape shape(const UMat &mat) {
return shape(mat.size.p, mat.dims);
}
namespace { inline bool is_neg(int i) { return i < 0; }}
static inline MatShape shape(int a0, int a1 = -1, int a2 = -1, int a3 = -1) {
int dims[] = {a0, a1, a2, a3};
MatShape s = shape(dims, 4);
s.erase(std::remove_if(s.begin(), s.end(), is_neg), s.end());
return s;
}
static inline int total(const MatShape &shape, int start = -1, int end = -1) {
if (start == -1) start = 0;
if (end == -1) end = (int) shape.size();
if (shape.empty())
return 0;
int elems = 1;
CV_Assert(start <= (int) shape.size() && end <= (int) shape.size() &&
start <= end);
for (int i = start; i < end; i++) {
elems *= shape[i];
}
return elems;
}
static inline MatShape concat(const MatShape &a, const MatShape &b) {
MatShape c = a;
c.insert(c.end(), b.begin(), b.end());
return c;
}
static inline std::string toString(const MatShape &shape, const String &name = "") {
std::ostringstream ss;
if (!name.empty())
ss << name << ' ';
ss << '[';
for (size_t i = 0, n = shape.size(); i < n; ++i)
ss << ' ' << shape[i];
ss << " ]";
return ss.str();
}
static inline void print(const MatShape &shape, const String &name = "") {
std::cout << toString(shape, name) << std::endl;
}
static inline std::ostream &operator<<(std::ostream &out, const MatShape &shape) {
out << toString(shape);
return out;
}
inline int clamp(int ax, int dims) {
return ax < 0 ? ax + dims : ax;
}
inline int clamp(int ax, const MatShape &shape) {
return clamp(ax, (int) shape.size());
}
inline Range clamp(const Range &r, int axisSize) {
Range clamped(std::max(r.start, 0),
r.end > 0 ? std::min(r.end, axisSize) : axisSize + r.end + 1);
CV_Assert_N(clamped.start < clamped.end, clamped.end <= axisSize);
return clamped;
}
CV__DNN_INLINE_NS_END
static inline Mat getPlane(const Mat &m, int n, int cn)
{
CV_Assert(m.dims > 2);
int sz[CV_MAX_DIM];
for(int i = 2; i < m.dims; i++)
{
sz[i-2] = m.size.p[i];
}
return Mat(m.dims - 2, sz, m.type(), (void*)m.ptr<float>(n, cn));
}
static inline MatShape shape(const int* dims, const int n)
{
MatShape shape;
shape.assign(dims, dims + n);
return shape;
}
static inline MatShape shape(const Mat& mat)
{
return shape(mat.size.p, mat.dims);
}
static inline MatShape shape(const MatSize& sz)
{
return shape(sz.p, sz.dims());
}
static inline MatShape shape(const UMat& mat)
{
return shape(mat.size.p, mat.dims);
}
namespace {inline bool is_neg(int i) { return i < 0; }}
static inline MatShape shape(int a0, int a1=-1, int a2=-1, int a3=-1)
{
int dims[] = {a0, a1, a2, a3};
MatShape s = shape(dims, 4);
s.erase(std::remove_if(s.begin(), s.end(), is_neg), s.end());
return s;
}
static inline int total(const MatShape& shape, int start = -1, int end = -1)
{
if (start == -1) start = 0;
if (end == -1) end = (int)shape.size();
if (shape.empty())
return 0;
int elems = 1;
CV_Assert(start <= (int)shape.size() && end <= (int)shape.size() &&
start <= end);
for(int i = start; i < end; i++)
{
elems *= shape[i];
}
return elems;
}
static inline MatShape concat(const MatShape& a, const MatShape& b)
{
MatShape c = a;
c.insert(c.end(), b.begin(), b.end());
return c;
}
static inline std::string toString(const MatShape& shape, const String& name = "")
{
std::ostringstream ss;
if (!name.empty())
ss << name << ' ';
ss << '[';
for(size_t i = 0, n = shape.size(); i < n; ++i)
ss << ' ' << shape[i];
ss << " ]";
return ss.str();
}
static inline void print(const MatShape& shape, const String& name = "")
{
std::cout << toString(shape, name) << std::endl;
}
static inline std::ostream& operator<<(std::ostream &out, const MatShape& shape)
{
out << toString(shape);
return out;
}
inline int clamp(int ax, int dims)
{
return ax < 0 ? ax + dims : ax;
}
inline int clamp(int ax, const MatShape& shape)
{
return clamp(ax, (int)shape.size());
}
inline Range clamp(const Range& r, int axisSize)
{
Range clamped(std::max(r.start, 0),
r.end > 0 ? std::min(r.end, axisSize) : axisSize + r.end + 1);
CV_Assert_N(clamped.start < clamped.end, clamped.end <= axisSize);
return clamped;
}
CV__DNN_INLINE_NS_END
}
}
#endif

View File

@@ -10,9 +10,8 @@
#include "../dnn.hpp"
namespace cv {
namespace dnn {
CV__DNN_INLINE_NS_BEGIN
namespace cv { namespace dnn {
CV__DNN_INLINE_NS_BEGIN
/* Values for 'OPENCV_DNN_BACKEND_INFERENCE_ENGINE_TYPE' parameter */
@@ -25,7 +24,7 @@ namespace cv {
*
* Default value is controlled through `OPENCV_DNN_BACKEND_INFERENCE_ENGINE_TYPE` runtime parameter (environment variable).
*/
CV_EXPORTS_W cv::String getInferenceEngineBackendType();
CV_EXPORTS_W cv::String getInferenceEngineBackendType();
/** @brief Specify Inference Engine internal backend API.
*
@@ -33,7 +32,7 @@ namespace cv {
*
* @returns previous value of internal backend API
*/
CV_EXPORTS_W cv::String setInferenceEngineBackendType(const cv::String &newBackendType);
CV_EXPORTS_W cv::String setInferenceEngineBackendType(const cv::String& newBackendType);
/** @brief Release a Myriad device (binded by OpenCV).
@@ -41,7 +40,7 @@ namespace cv {
* Single Myriad device cannot be shared across multiple processes which uses
* Inference Engine's Myriad plugin.
*/
CV_EXPORTS_W void resetMyriadDevice();
CV_EXPORTS_W void resetMyriadDevice();
/* Values for 'OPENCV_DNN_IE_VPU_TYPE' parameter */
@@ -56,11 +55,10 @@ namespace cv {
*
* See values of `CV_DNN_INFERENCE_ENGINE_VPU_TYPE_*` macros.
*/
CV_EXPORTS_W cv::String getInferenceEngineVPUType();
CV_EXPORTS_W cv::String getInferenceEngineVPUType();
CV__DNN_INLINE_NS_END
}
} // namespace
CV__DNN_INLINE_NS_END
}} // namespace
#endif // OPENCV_DNN_UTILS_INF_ENGINE_HPP

View File

@@ -12,12 +12,7 @@
#define CV__DNN_INLINE_NS __CV_CAT(dnn4_v, OPENCV_DNN_API_VERSION)
#define CV__DNN_INLINE_NS_BEGIN namespace CV__DNN_INLINE_NS {
#define CV__DNN_INLINE_NS_END }
namespace cv {
namespace dnn {
namespace CV__DNN_INLINE_NS {}
using namespace CV__DNN_INLINE_NS;
}
}
namespace cv { namespace dnn { namespace CV__DNN_INLINE_NS { } using namespace CV__DNN_INLINE_NS; }}
#else
#define CV__DNN_INLINE_NS_BEGIN
#define CV__DNN_INLINE_NS_END