2012-01-24 21:14:07 +01:00
|
|
|
/*M///////////////////////////////////////////////////////////////////////////////////////
|
2012-05-25 15:16:16 +02:00
|
|
|
//
|
2012-01-24 21:14:07 +01:00
|
|
|
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
|
|
|
//
|
|
|
|
// By downloading, copying, installing or using the software you agree to this license.
|
|
|
|
// If you do not agree to this license, do not download, install,
|
|
|
|
// copy or use the software.
|
|
|
|
//
|
|
|
|
//
|
2012-06-09 17:00:04 +02:00
|
|
|
// License Agreement
|
2012-01-24 21:14:07 +01:00
|
|
|
// For Open Source Computer Vision Library
|
|
|
|
//
|
|
|
|
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
|
|
|
// Copyright (C) 2009-2011, Willow Garage Inc., all rights reserved.
|
|
|
|
// Third party copyrights are property of their respective owners.
|
|
|
|
//
|
|
|
|
// Redistribution and use in source and binary forms, with or without modification,
|
|
|
|
// are permitted provided that the following conditions are met:
|
|
|
|
//
|
|
|
|
// * Redistribution's of source code must retain the above copyright notice,
|
|
|
|
// this list of conditions and the following disclaimer.
|
|
|
|
//
|
|
|
|
// * Redistribution's in binary form must reproduce the above copyright notice,
|
|
|
|
// this list of conditions and the following disclaimer in the documentation
|
|
|
|
// and/or other materials provided with the distribution.
|
|
|
|
//
|
|
|
|
// * The name of the copyright holders may not be used to endorse or promote products
|
|
|
|
// derived from this software without specific prior written permission.
|
|
|
|
//
|
|
|
|
// This software is provided by the copyright holders and contributors "as is" and
|
|
|
|
// any express or implied warranties, including, but not limited to, the implied
|
|
|
|
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
|
|
|
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
|
|
|
// indirect, incidental, special, exemplary, or consequential damages
|
|
|
|
// (including, but not limited to, procurement of substitute goods or services;
|
|
|
|
// loss of use, data, or profits; or business interruption) however caused
|
|
|
|
// and on any theory of liability, whether in contract, strict liability,
|
|
|
|
// or tort (including negligence or otherwise) arising in any way out of
|
|
|
|
// the use of this software, even if advised of the possibility of such damage.
|
|
|
|
//
|
|
|
|
//M*/
|
|
|
|
|
|
|
|
#include "precomp.hpp"
|
|
|
|
|
|
|
|
namespace cv
|
|
|
|
{
|
|
|
|
|
|
|
|
template<typename _KeyTp, typename _ValueTp> struct sorted_vector
|
|
|
|
{
|
|
|
|
sorted_vector() {}
|
|
|
|
void clear() { vec.clear(); }
|
|
|
|
size_t size() const { return vec.size(); }
|
|
|
|
_ValueTp& operator [](size_t idx) { return vec[idx]; }
|
|
|
|
const _ValueTp& operator [](size_t idx) const { return vec[idx]; }
|
2012-06-09 17:00:04 +02:00
|
|
|
|
2012-01-24 21:14:07 +01:00
|
|
|
void add(const _KeyTp& k, const _ValueTp& val)
|
|
|
|
{
|
2013-02-24 17:14:01 +01:00
|
|
|
std::pair<_KeyTp, _ValueTp> p(k, val);
|
2012-01-24 21:14:07 +01:00
|
|
|
vec.push_back(p);
|
|
|
|
size_t i = vec.size()-1;
|
|
|
|
for( ; i > 0 && vec[i].first < vec[i-1].first; i-- )
|
|
|
|
std::swap(vec[i-1], vec[i]);
|
|
|
|
CV_Assert( i == 0 || vec[i].first != vec[i-1].first );
|
|
|
|
}
|
2012-06-09 17:00:04 +02:00
|
|
|
|
2012-01-24 21:14:07 +01:00
|
|
|
bool find(const _KeyTp& key, _ValueTp& value) const
|
|
|
|
{
|
|
|
|
size_t a = 0, b = vec.size();
|
|
|
|
while( b > a )
|
|
|
|
{
|
|
|
|
size_t c = (a + b)/2;
|
|
|
|
if( vec[c].first < key )
|
|
|
|
a = c+1;
|
|
|
|
else
|
|
|
|
b = c;
|
|
|
|
}
|
2012-06-09 17:00:04 +02:00
|
|
|
|
2012-03-15 15:36:01 +01:00
|
|
|
if( a < vec.size() && vec[a].first == key )
|
2012-01-24 21:14:07 +01:00
|
|
|
{
|
|
|
|
value = vec[a].second;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2012-06-09 17:00:04 +02:00
|
|
|
|
2013-02-24 17:14:01 +01:00
|
|
|
void get_keys(std::vector<_KeyTp>& keys) const
|
2012-01-24 21:14:07 +01:00
|
|
|
{
|
|
|
|
size_t i = 0, n = vec.size();
|
|
|
|
keys.resize(n);
|
2012-06-09 17:00:04 +02:00
|
|
|
|
2012-01-24 21:14:07 +01:00
|
|
|
for( i = 0; i < n; i++ )
|
|
|
|
keys[i] = vec[i].first;
|
|
|
|
}
|
2012-06-09 17:00:04 +02:00
|
|
|
|
2013-02-24 17:14:01 +01:00
|
|
|
std::vector<std::pair<_KeyTp, _ValueTp> > vec;
|
2012-01-24 21:14:07 +01:00
|
|
|
};
|
|
|
|
|
2012-06-09 17:00:04 +02:00
|
|
|
|
2013-03-22 17:37:49 +01:00
|
|
|
template<typename _ValueTp> inline const _ValueTp* findstr(const sorted_vector<String, _ValueTp>& vec,
|
2012-01-24 21:14:07 +01:00
|
|
|
const char* key)
|
|
|
|
{
|
|
|
|
if( !key )
|
|
|
|
return 0;
|
2012-06-09 17:00:04 +02:00
|
|
|
|
2012-01-24 21:14:07 +01:00
|
|
|
size_t a = 0, b = vec.vec.size();
|
|
|
|
while( b > a )
|
|
|
|
{
|
|
|
|
size_t c = (a + b)/2;
|
|
|
|
if( strcmp(vec.vec[c].first.c_str(), key) < 0 )
|
|
|
|
a = c+1;
|
|
|
|
else
|
|
|
|
b = c;
|
|
|
|
}
|
2012-06-09 17:00:04 +02:00
|
|
|
|
2012-10-23 19:37:27 +02:00
|
|
|
if( ( a < vec.vec.size() ) && ( strcmp(vec.vec[a].first.c_str(), key) == 0 ))
|
2012-01-24 21:14:07 +01:00
|
|
|
return &vec.vec[a].second;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-06-09 17:00:04 +02:00
|
|
|
|
2012-01-24 21:14:07 +01:00
|
|
|
Param::Param()
|
|
|
|
{
|
|
|
|
type = 0;
|
|
|
|
offset = 0;
|
|
|
|
readonly = false;
|
|
|
|
getter = 0;
|
|
|
|
setter = 0;
|
|
|
|
}
|
|
|
|
|
2012-06-09 17:00:04 +02:00
|
|
|
|
2012-01-24 21:14:07 +01:00
|
|
|
Param::Param(int _type, bool _readonly, int _offset,
|
|
|
|
Algorithm::Getter _getter, Algorithm::Setter _setter,
|
2013-03-22 17:37:49 +01:00
|
|
|
const String& _help)
|
2012-01-24 21:14:07 +01:00
|
|
|
{
|
|
|
|
type = _type;
|
|
|
|
readonly = _readonly;
|
|
|
|
offset = _offset;
|
|
|
|
getter = _getter;
|
|
|
|
setter = _setter;
|
|
|
|
help = _help;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct CV_EXPORTS AlgorithmInfoData
|
|
|
|
{
|
2013-03-22 17:37:49 +01:00
|
|
|
sorted_vector<String, Param> params;
|
|
|
|
String _name;
|
2012-01-24 21:14:07 +01:00
|
|
|
};
|
|
|
|
|
2012-06-09 17:00:04 +02:00
|
|
|
|
2013-03-22 17:37:49 +01:00
|
|
|
static sorted_vector<String, Algorithm::Constructor>& alglist()
|
2012-04-13 23:50:59 +02:00
|
|
|
{
|
2013-03-22 17:37:49 +01:00
|
|
|
static sorted_vector<String, Algorithm::Constructor> alglist_var;
|
2012-04-13 23:50:59 +02:00
|
|
|
return alglist_var;
|
|
|
|
}
|
2012-01-24 21:14:07 +01:00
|
|
|
|
2013-03-22 17:37:49 +01:00
|
|
|
void Algorithm::getList(std::vector<String>& algorithms)
|
2012-01-24 21:14:07 +01:00
|
|
|
{
|
2012-04-13 23:50:59 +02:00
|
|
|
alglist().get_keys(algorithms);
|
2012-01-24 21:14:07 +01:00
|
|
|
}
|
|
|
|
|
2013-03-22 17:37:49 +01:00
|
|
|
Ptr<Algorithm> Algorithm::_create(const String& name)
|
2012-01-24 21:14:07 +01:00
|
|
|
{
|
|
|
|
Algorithm::Constructor c = 0;
|
2012-04-13 23:50:59 +02:00
|
|
|
if( !alglist().find(name, c) )
|
2012-01-24 21:14:07 +01:00
|
|
|
return Ptr<Algorithm>();
|
|
|
|
return c();
|
|
|
|
}
|
|
|
|
|
|
|
|
Algorithm::Algorithm()
|
|
|
|
{
|
|
|
|
}
|
2012-06-09 17:00:04 +02:00
|
|
|
|
2012-01-24 21:14:07 +01:00
|
|
|
Algorithm::~Algorithm()
|
|
|
|
{
|
|
|
|
}
|
2012-06-09 17:00:04 +02:00
|
|
|
|
2013-03-22 17:37:49 +01:00
|
|
|
String Algorithm::name() const
|
2012-01-24 21:14:07 +01:00
|
|
|
{
|
|
|
|
return info()->name();
|
|
|
|
}
|
2012-06-09 17:00:04 +02:00
|
|
|
|
2013-03-22 17:37:49 +01:00
|
|
|
void Algorithm::set(const String& parameter, int value)
|
2012-03-15 15:36:01 +01:00
|
|
|
{
|
2012-06-09 17:00:04 +02:00
|
|
|
info()->set(this, parameter.c_str(), ParamType<int>::type, &value);
|
2012-03-15 15:36:01 +01:00
|
|
|
}
|
|
|
|
|
2013-03-22 17:37:49 +01:00
|
|
|
void Algorithm::set(const String& parameter, double value)
|
2012-03-15 15:36:01 +01:00
|
|
|
{
|
2012-06-09 17:00:04 +02:00
|
|
|
info()->set(this, parameter.c_str(), ParamType<double>::type, &value);
|
2012-03-15 15:36:01 +01:00
|
|
|
}
|
|
|
|
|
2013-03-22 17:37:49 +01:00
|
|
|
void Algorithm::set(const String& parameter, bool value)
|
2012-03-15 15:36:01 +01:00
|
|
|
{
|
2012-06-09 17:00:04 +02:00
|
|
|
info()->set(this, parameter.c_str(), ParamType<bool>::type, &value);
|
2012-03-15 15:36:01 +01:00
|
|
|
}
|
|
|
|
|
2013-03-22 17:37:49 +01:00
|
|
|
void Algorithm::set(const String& parameter, const String& value)
|
2012-03-15 15:36:01 +01:00
|
|
|
{
|
2013-03-22 17:37:49 +01:00
|
|
|
info()->set(this, parameter.c_str(), ParamType<String>::type, &value);
|
2012-03-15 15:36:01 +01:00
|
|
|
}
|
|
|
|
|
2013-03-22 17:37:49 +01:00
|
|
|
void Algorithm::set(const String& parameter, const Mat& value)
|
2012-03-15 15:36:01 +01:00
|
|
|
{
|
2012-06-09 17:00:04 +02:00
|
|
|
info()->set(this, parameter.c_str(), ParamType<Mat>::type, &value);
|
2012-03-15 15:36:01 +01:00
|
|
|
}
|
|
|
|
|
2013-03-22 17:37:49 +01:00
|
|
|
void Algorithm::set(const String& parameter, const std::vector<Mat>& value)
|
2012-04-13 23:50:59 +02:00
|
|
|
{
|
2013-02-24 17:14:01 +01:00
|
|
|
info()->set(this, parameter.c_str(), ParamType<std::vector<Mat> >::type, &value);
|
2012-06-09 17:00:04 +02:00
|
|
|
}
|
|
|
|
|
2013-03-22 17:37:49 +01:00
|
|
|
void Algorithm::set(const String& parameter, const Ptr<Algorithm>& value)
|
2012-03-15 15:36:01 +01:00
|
|
|
{
|
2012-06-09 17:00:04 +02:00
|
|
|
info()->set(this, parameter.c_str(), ParamType<Algorithm>::type, &value);
|
2012-03-15 15:36:01 +01:00
|
|
|
}
|
|
|
|
|
2012-06-09 17:00:04 +02:00
|
|
|
void Algorithm::set(const char* parameter, int value)
|
2012-03-15 15:36:01 +01:00
|
|
|
{
|
2012-06-09 17:00:04 +02:00
|
|
|
info()->set(this, parameter, ParamType<int>::type, &value);
|
2012-03-15 15:36:01 +01:00
|
|
|
}
|
|
|
|
|
2012-06-09 17:00:04 +02:00
|
|
|
void Algorithm::set(const char* parameter, double value)
|
2012-03-15 15:36:01 +01:00
|
|
|
{
|
2012-06-09 17:00:04 +02:00
|
|
|
info()->set(this, parameter, ParamType<double>::type, &value);
|
2012-03-15 15:36:01 +01:00
|
|
|
}
|
|
|
|
|
2012-06-09 17:00:04 +02:00
|
|
|
void Algorithm::set(const char* parameter, bool value)
|
2012-03-15 15:36:01 +01:00
|
|
|
{
|
2012-06-09 17:00:04 +02:00
|
|
|
info()->set(this, parameter, ParamType<bool>::type, &value);
|
2012-03-15 15:36:01 +01:00
|
|
|
}
|
|
|
|
|
2013-03-22 17:37:49 +01:00
|
|
|
void Algorithm::set(const char* parameter, const String& value)
|
2012-03-15 15:36:01 +01:00
|
|
|
{
|
2013-03-22 17:37:49 +01:00
|
|
|
info()->set(this, parameter, ParamType<String>::type, &value);
|
2012-03-15 15:36:01 +01:00
|
|
|
}
|
|
|
|
|
2012-06-09 17:00:04 +02:00
|
|
|
void Algorithm::set(const char* parameter, const Mat& value)
|
2012-03-15 15:36:01 +01:00
|
|
|
{
|
2012-06-09 17:00:04 +02:00
|
|
|
info()->set(this, parameter, ParamType<Mat>::type, &value);
|
2012-03-15 15:36:01 +01:00
|
|
|
}
|
|
|
|
|
2013-02-24 17:14:01 +01:00
|
|
|
void Algorithm::set(const char* parameter, const std::vector<Mat>& value)
|
2012-04-13 23:50:59 +02:00
|
|
|
{
|
2013-02-24 17:14:01 +01:00
|
|
|
info()->set(this, parameter, ParamType<std::vector<Mat> >::type, &value);
|
2012-06-09 17:00:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Algorithm::set(const char* parameter, const Ptr<Algorithm>& value)
|
2012-03-15 15:36:01 +01:00
|
|
|
{
|
2012-06-09 17:00:04 +02:00
|
|
|
info()->set(this, parameter, ParamType<Algorithm>::type, &value);
|
2012-03-15 15:36:01 +01:00
|
|
|
}
|
2012-06-09 17:00:04 +02:00
|
|
|
|
2012-10-23 19:37:27 +02:00
|
|
|
|
2013-03-22 17:37:49 +01:00
|
|
|
void Algorithm::setInt(const String& parameter, int value)
|
2012-10-23 19:37:27 +02:00
|
|
|
{
|
|
|
|
info()->set(this, parameter.c_str(), ParamType<int>::type, &value);
|
|
|
|
}
|
|
|
|
|
2013-03-22 17:37:49 +01:00
|
|
|
void Algorithm::setDouble(const String& parameter, double value)
|
2012-10-23 19:37:27 +02:00
|
|
|
{
|
|
|
|
info()->set(this, parameter.c_str(), ParamType<double>::type, &value);
|
|
|
|
}
|
|
|
|
|
2013-03-22 17:37:49 +01:00
|
|
|
void Algorithm::setBool(const String& parameter, bool value)
|
2012-10-23 19:37:27 +02:00
|
|
|
{
|
|
|
|
info()->set(this, parameter.c_str(), ParamType<bool>::type, &value);
|
|
|
|
}
|
|
|
|
|
2013-03-22 17:37:49 +01:00
|
|
|
void Algorithm::setString(const String& parameter, const String& value)
|
2012-10-23 19:37:27 +02:00
|
|
|
{
|
2013-03-22 17:37:49 +01:00
|
|
|
info()->set(this, parameter.c_str(), ParamType<String>::type, &value);
|
2012-10-23 19:37:27 +02:00
|
|
|
}
|
|
|
|
|
2013-03-22 17:37:49 +01:00
|
|
|
void Algorithm::setMat(const String& parameter, const Mat& value)
|
2012-10-23 19:37:27 +02:00
|
|
|
{
|
|
|
|
info()->set(this, parameter.c_str(), ParamType<Mat>::type, &value);
|
|
|
|
}
|
|
|
|
|
2013-03-22 17:37:49 +01:00
|
|
|
void Algorithm::setMatVector(const String& parameter, const std::vector<Mat>& value)
|
2012-10-23 19:37:27 +02:00
|
|
|
{
|
2013-02-24 17:14:01 +01:00
|
|
|
info()->set(this, parameter.c_str(), ParamType<std::vector<Mat> >::type, &value);
|
2012-10-23 19:37:27 +02:00
|
|
|
}
|
|
|
|
|
2013-03-22 17:37:49 +01:00
|
|
|
void Algorithm::setAlgorithm(const String& parameter, const Ptr<Algorithm>& value)
|
2012-10-23 19:37:27 +02:00
|
|
|
{
|
|
|
|
info()->set(this, parameter.c_str(), ParamType<Algorithm>::type, &value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Algorithm::setInt(const char* parameter, int value)
|
|
|
|
{
|
|
|
|
info()->set(this, parameter, ParamType<int>::type, &value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Algorithm::setDouble(const char* parameter, double value)
|
|
|
|
{
|
|
|
|
info()->set(this, parameter, ParamType<double>::type, &value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Algorithm::setBool(const char* parameter, bool value)
|
|
|
|
{
|
|
|
|
info()->set(this, parameter, ParamType<bool>::type, &value);
|
|
|
|
}
|
|
|
|
|
2013-03-22 17:37:49 +01:00
|
|
|
void Algorithm::setString(const char* parameter, const String& value)
|
2012-10-23 19:37:27 +02:00
|
|
|
{
|
2013-03-22 17:37:49 +01:00
|
|
|
info()->set(this, parameter, ParamType<String>::type, &value);
|
2012-10-23 19:37:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Algorithm::setMat(const char* parameter, const Mat& value)
|
|
|
|
{
|
|
|
|
info()->set(this, parameter, ParamType<Mat>::type, &value);
|
|
|
|
}
|
|
|
|
|
2013-02-24 17:14:01 +01:00
|
|
|
void Algorithm::setMatVector(const char* parameter, const std::vector<Mat>& value)
|
2012-10-23 19:37:27 +02:00
|
|
|
{
|
2013-02-24 17:14:01 +01:00
|
|
|
info()->set(this, parameter, ParamType<std::vector<Mat> >::type, &value);
|
2012-10-23 19:37:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Algorithm::setAlgorithm(const char* parameter, const Ptr<Algorithm>& value)
|
|
|
|
{
|
|
|
|
info()->set(this, parameter, ParamType<Algorithm>::type, &value);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-03-22 17:37:49 +01:00
|
|
|
int Algorithm::getInt(const String& parameter) const
|
2012-04-30 16:33:52 +02:00
|
|
|
{
|
2012-06-09 17:00:04 +02:00
|
|
|
return get<int>(parameter);
|
2012-04-30 16:33:52 +02:00
|
|
|
}
|
2012-06-09 17:00:04 +02:00
|
|
|
|
2013-03-22 17:37:49 +01:00
|
|
|
double Algorithm::getDouble(const String& parameter) const
|
2012-04-30 16:33:52 +02:00
|
|
|
{
|
2012-06-09 17:00:04 +02:00
|
|
|
return get<double>(parameter);
|
2012-04-30 16:33:52 +02:00
|
|
|
}
|
|
|
|
|
2013-03-22 17:37:49 +01:00
|
|
|
bool Algorithm::getBool(const String& parameter) const
|
2012-04-30 16:33:52 +02:00
|
|
|
{
|
2012-06-09 17:00:04 +02:00
|
|
|
return get<bool>(parameter);
|
2012-04-30 16:33:52 +02:00
|
|
|
}
|
|
|
|
|
2013-03-22 17:37:49 +01:00
|
|
|
String Algorithm::getString(const String& parameter) const
|
2012-04-30 16:33:52 +02:00
|
|
|
{
|
2013-03-22 17:37:49 +01:00
|
|
|
return get<String>(parameter);
|
2012-04-30 16:33:52 +02:00
|
|
|
}
|
|
|
|
|
2013-03-22 17:37:49 +01:00
|
|
|
Mat Algorithm::getMat(const String& parameter) const
|
2012-04-30 16:33:52 +02:00
|
|
|
{
|
2012-06-09 17:00:04 +02:00
|
|
|
return get<Mat>(parameter);
|
2012-04-30 16:33:52 +02:00
|
|
|
}
|
|
|
|
|
2013-03-22 17:37:49 +01:00
|
|
|
std::vector<Mat> Algorithm::getMatVector(const String& parameter) const
|
2012-04-30 16:33:52 +02:00
|
|
|
{
|
2013-02-24 17:14:01 +01:00
|
|
|
return get<std::vector<Mat> >(parameter);
|
2012-04-30 16:33:52 +02:00
|
|
|
}
|
|
|
|
|
2013-03-22 17:37:49 +01:00
|
|
|
Ptr<Algorithm> Algorithm::getAlgorithm(const String& parameter) const
|
2012-04-30 16:33:52 +02:00
|
|
|
{
|
2012-06-09 17:00:04 +02:00
|
|
|
return get<Algorithm>(parameter);
|
2012-04-30 16:33:52 +02:00
|
|
|
}
|
2012-06-09 17:00:04 +02:00
|
|
|
|
2013-03-22 17:37:49 +01:00
|
|
|
String Algorithm::paramHelp(const String& parameter) const
|
2012-01-24 21:14:07 +01:00
|
|
|
{
|
2012-06-09 17:00:04 +02:00
|
|
|
return info()->paramHelp(parameter.c_str());
|
2012-01-24 21:14:07 +01:00
|
|
|
}
|
2012-06-09 17:00:04 +02:00
|
|
|
|
2013-03-22 17:37:49 +01:00
|
|
|
int Algorithm::paramType(const String& parameter) const
|
2012-01-24 21:14:07 +01:00
|
|
|
{
|
2012-06-09 17:00:04 +02:00
|
|
|
return info()->paramType(parameter.c_str());
|
2012-01-24 21:14:07 +01:00
|
|
|
}
|
|
|
|
|
2012-06-09 17:00:04 +02:00
|
|
|
int Algorithm::paramType(const char* parameter) const
|
2012-01-24 21:14:07 +01:00
|
|
|
{
|
2012-06-09 17:00:04 +02:00
|
|
|
return info()->paramType(parameter);
|
|
|
|
}
|
|
|
|
|
2013-03-22 17:37:49 +01:00
|
|
|
void Algorithm::getParams(std::vector<String>& names) const
|
2012-01-24 21:14:07 +01:00
|
|
|
{
|
|
|
|
info()->getParams(names);
|
|
|
|
}
|
2012-06-09 17:00:04 +02:00
|
|
|
|
2012-01-24 21:14:07 +01:00
|
|
|
void Algorithm::write(FileStorage& fs) const
|
|
|
|
{
|
|
|
|
info()->write(this, fs);
|
|
|
|
}
|
2012-06-09 17:00:04 +02:00
|
|
|
|
2012-01-24 21:14:07 +01:00
|
|
|
void Algorithm::read(const FileNode& fn)
|
|
|
|
{
|
|
|
|
info()->read(this, fn);
|
2012-06-09 17:00:04 +02:00
|
|
|
}
|
|
|
|
|
2012-01-24 21:14:07 +01:00
|
|
|
|
2013-03-22 17:37:49 +01:00
|
|
|
AlgorithmInfo::AlgorithmInfo(const String& _name, Algorithm::Constructor create)
|
2012-01-24 21:14:07 +01:00
|
|
|
{
|
|
|
|
data = new AlgorithmInfoData;
|
|
|
|
data->_name = _name;
|
2012-07-01 23:14:16 +02:00
|
|
|
if (!alglist().find(_name, create))
|
|
|
|
alglist().add(_name, create);
|
2012-01-24 21:14:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
AlgorithmInfo::~AlgorithmInfo()
|
|
|
|
{
|
|
|
|
delete data;
|
2012-06-09 17:00:04 +02:00
|
|
|
}
|
|
|
|
|
2012-01-24 21:14:07 +01:00
|
|
|
void AlgorithmInfo::write(const Algorithm* algo, FileStorage& fs) const
|
|
|
|
{
|
2012-04-30 16:33:52 +02:00
|
|
|
size_t i = 0, nparams = data->params.vec.size();
|
2012-01-24 21:14:07 +01:00
|
|
|
cv::write(fs, "name", algo->name());
|
2012-04-30 16:33:52 +02:00
|
|
|
for( i = 0; i < nparams; i++ )
|
2012-01-24 21:14:07 +01:00
|
|
|
{
|
|
|
|
const Param& p = data->params.vec[i].second;
|
2013-03-22 17:37:49 +01:00
|
|
|
const String& pname = data->params.vec[i].first;
|
2012-01-24 21:14:07 +01:00
|
|
|
if( p.type == Param::INT )
|
|
|
|
cv::write(fs, pname, algo->get<int>(pname));
|
|
|
|
else if( p.type == Param::BOOLEAN )
|
|
|
|
cv::write(fs, pname, (int)algo->get<bool>(pname));
|
|
|
|
else if( p.type == Param::REAL )
|
|
|
|
cv::write(fs, pname, algo->get<double>(pname));
|
|
|
|
else if( p.type == Param::STRING )
|
2013-03-22 17:37:49 +01:00
|
|
|
cv::write(fs, pname, algo->get<String>(pname));
|
2012-01-24 21:14:07 +01:00
|
|
|
else if( p.type == Param::MAT )
|
|
|
|
cv::write(fs, pname, algo->get<Mat>(pname));
|
2012-04-13 23:50:59 +02:00
|
|
|
else if( p.type == Param::MAT_VECTOR )
|
2013-02-24 17:14:01 +01:00
|
|
|
cv::write(fs, pname, algo->get<std::vector<Mat> >(pname));
|
2012-01-24 21:14:07 +01:00
|
|
|
else if( p.type == Param::ALGORITHM )
|
|
|
|
{
|
2013-04-01 17:18:05 +02:00
|
|
|
internal::WriteStructContext ws(fs, pname, CV_NODE_MAP);
|
2012-01-24 21:14:07 +01:00
|
|
|
Ptr<Algorithm> nestedAlgo = algo->get<Algorithm>(pname);
|
|
|
|
nestedAlgo->write(fs);
|
|
|
|
}
|
2013-02-04 17:25:18 +01:00
|
|
|
else if( p.type == Param::FLOAT)
|
2013-02-21 16:49:37 +01:00
|
|
|
cv::write(fs, pname, algo->getDouble(pname));
|
2013-02-04 17:25:18 +01:00
|
|
|
else if( p.type == Param::UNSIGNED_INT)
|
|
|
|
cv::write(fs, pname, algo->getInt(pname));//TODO: implement cv::write(, , unsigned int)
|
|
|
|
else if( p.type == Param::UINT64)
|
|
|
|
cv::write(fs, pname, algo->getInt(pname));//TODO: implement cv::write(, , uint64)
|
|
|
|
else if( p.type == Param::UCHAR)
|
|
|
|
cv::write(fs, pname, algo->getInt(pname));
|
2012-01-24 21:14:07 +01:00
|
|
|
else
|
2012-10-25 16:59:10 +02:00
|
|
|
{
|
2013-03-22 17:37:49 +01:00
|
|
|
String msg = format("unknown/unsupported type of '%s' parameter == %d", pname.c_str(), p.type);
|
2012-10-25 16:59:10 +02:00
|
|
|
CV_Error( CV_StsUnsupportedFormat, msg.c_str());
|
|
|
|
}
|
2012-01-24 21:14:07 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AlgorithmInfo::read(Algorithm* algo, const FileNode& fn) const
|
|
|
|
{
|
2012-04-30 16:33:52 +02:00
|
|
|
size_t i = 0, nparams = data->params.vec.size();
|
|
|
|
AlgorithmInfo* info = algo->info();
|
2012-06-09 17:00:04 +02:00
|
|
|
|
2012-04-30 16:33:52 +02:00
|
|
|
for( i = 0; i < nparams; i++ )
|
2012-01-24 21:14:07 +01:00
|
|
|
{
|
|
|
|
const Param& p = data->params.vec[i].second;
|
2013-03-22 17:37:49 +01:00
|
|
|
const String& pname = data->params.vec[i].first;
|
2012-04-13 23:50:59 +02:00
|
|
|
const FileNode n = fn[pname];
|
2012-01-24 21:14:07 +01:00
|
|
|
if( n.empty() )
|
|
|
|
continue;
|
|
|
|
if( p.type == Param::INT )
|
2012-04-30 16:33:52 +02:00
|
|
|
{
|
|
|
|
int val = (int)n;
|
|
|
|
info->set(algo, pname.c_str(), p.type, &val, true);
|
|
|
|
}
|
2012-01-24 21:14:07 +01:00
|
|
|
else if( p.type == Param::BOOLEAN )
|
2012-04-30 16:33:52 +02:00
|
|
|
{
|
|
|
|
bool val = (int)n != 0;
|
|
|
|
info->set(algo, pname.c_str(), p.type, &val, true);
|
|
|
|
}
|
2012-01-24 21:14:07 +01:00
|
|
|
else if( p.type == Param::REAL )
|
2012-04-30 16:33:52 +02:00
|
|
|
{
|
|
|
|
double val = (double)n;
|
|
|
|
info->set(algo, pname.c_str(), p.type, &val, true);
|
|
|
|
}
|
2012-01-24 21:14:07 +01:00
|
|
|
else if( p.type == Param::STRING )
|
2012-04-30 16:33:52 +02:00
|
|
|
{
|
2013-03-22 17:37:49 +01:00
|
|
|
String val = (String)n;
|
2012-04-30 16:33:52 +02:00
|
|
|
info->set(algo, pname.c_str(), p.type, &val, true);
|
|
|
|
}
|
2012-01-24 21:14:07 +01:00
|
|
|
else if( p.type == Param::MAT )
|
|
|
|
{
|
|
|
|
Mat m;
|
2012-04-13 23:50:59 +02:00
|
|
|
cv::read(n, m);
|
2012-04-30 16:33:52 +02:00
|
|
|
info->set(algo, pname.c_str(), p.type, &m, true);
|
2012-01-24 21:14:07 +01:00
|
|
|
}
|
2012-04-13 23:50:59 +02:00
|
|
|
else if( p.type == Param::MAT_VECTOR )
|
|
|
|
{
|
2013-02-24 17:14:01 +01:00
|
|
|
std::vector<Mat> mv;
|
2012-04-13 23:50:59 +02:00
|
|
|
cv::read(n, mv);
|
2012-04-30 16:33:52 +02:00
|
|
|
info->set(algo, pname.c_str(), p.type, &mv, true);
|
2012-04-13 23:50:59 +02:00
|
|
|
}
|
2012-01-24 21:14:07 +01:00
|
|
|
else if( p.type == Param::ALGORITHM )
|
|
|
|
{
|
2013-03-22 17:37:49 +01:00
|
|
|
Ptr<Algorithm> nestedAlgo = Algorithm::_create((String)n["name"]);
|
2012-01-24 21:14:07 +01:00
|
|
|
CV_Assert( !nestedAlgo.empty() );
|
|
|
|
nestedAlgo->read(n);
|
2012-04-30 16:33:52 +02:00
|
|
|
info->set(algo, pname.c_str(), p.type, &nestedAlgo, true);
|
2012-01-24 21:14:07 +01:00
|
|
|
}
|
2013-02-04 17:25:18 +01:00
|
|
|
else if( p.type == Param::FLOAT )
|
|
|
|
{
|
|
|
|
float val = (float)n;
|
|
|
|
info->set(algo, pname.c_str(), p.type, &val, true);
|
|
|
|
}
|
|
|
|
else if( p.type == Param::UNSIGNED_INT )
|
|
|
|
{
|
|
|
|
unsigned int val = (unsigned int)((int)n);//TODO: implement conversion (unsigned int)FileNode
|
|
|
|
info->set(algo, pname.c_str(), p.type, &val, true);
|
|
|
|
}
|
|
|
|
else if( p.type == Param::UINT64)
|
|
|
|
{
|
|
|
|
uint64 val = (uint64)((int)n);//TODO: implement conversion (uint64)FileNode
|
|
|
|
info->set(algo, pname.c_str(), p.type, &val, true);
|
|
|
|
}
|
|
|
|
else if( p.type == Param::UCHAR)
|
|
|
|
{
|
|
|
|
uchar val = (uchar)((int)n);
|
|
|
|
info->set(algo, pname.c_str(), p.type, &val, true);
|
|
|
|
}
|
2012-01-24 21:14:07 +01:00
|
|
|
else
|
2012-10-25 16:59:10 +02:00
|
|
|
{
|
2013-03-22 17:37:49 +01:00
|
|
|
String msg = format("unknown/unsupported type of '%s' parameter == %d", pname.c_str(), p.type);
|
2012-10-25 16:59:10 +02:00
|
|
|
CV_Error( CV_StsUnsupportedFormat, msg.c_str());
|
|
|
|
}
|
2012-01-24 21:14:07 +01:00
|
|
|
}
|
2012-06-09 17:00:04 +02:00
|
|
|
}
|
2012-01-24 21:14:07 +01:00
|
|
|
|
2013-03-22 17:37:49 +01:00
|
|
|
String AlgorithmInfo::name() const
|
2012-01-24 21:14:07 +01:00
|
|
|
{
|
|
|
|
return data->_name;
|
|
|
|
}
|
2012-06-09 17:00:04 +02:00
|
|
|
|
2012-01-24 21:14:07 +01:00
|
|
|
union GetSetParam
|
|
|
|
{
|
|
|
|
int (Algorithm::*get_int)() const;
|
|
|
|
bool (Algorithm::*get_bool)() const;
|
|
|
|
double (Algorithm::*get_double)() const;
|
2013-03-22 17:37:49 +01:00
|
|
|
String (Algorithm::*get_string)() const;
|
2012-01-24 21:14:07 +01:00
|
|
|
Mat (Algorithm::*get_mat)() const;
|
2013-02-24 17:14:01 +01:00
|
|
|
std::vector<Mat> (Algorithm::*get_mat_vector)() const;
|
2012-01-24 21:14:07 +01:00
|
|
|
Ptr<Algorithm> (Algorithm::*get_algo)() const;
|
2013-02-04 17:25:18 +01:00
|
|
|
float (Algorithm::*get_float)() const;
|
|
|
|
unsigned int (Algorithm::*get_uint)() const;
|
|
|
|
uint64 (Algorithm::*get_uint64)() const;
|
|
|
|
uchar (Algorithm::*get_uchar)() const;
|
2012-06-09 17:00:04 +02:00
|
|
|
|
2012-01-24 21:14:07 +01:00
|
|
|
void (Algorithm::*set_int)(int);
|
|
|
|
void (Algorithm::*set_bool)(bool);
|
|
|
|
void (Algorithm::*set_double)(double);
|
2013-03-22 17:37:49 +01:00
|
|
|
void (Algorithm::*set_string)(const String&);
|
2012-01-24 21:14:07 +01:00
|
|
|
void (Algorithm::*set_mat)(const Mat&);
|
2013-02-24 17:14:01 +01:00
|
|
|
void (Algorithm::*set_mat_vector)(const std::vector<Mat>&);
|
2012-01-24 21:14:07 +01:00
|
|
|
void (Algorithm::*set_algo)(const Ptr<Algorithm>&);
|
2013-02-04 17:25:18 +01:00
|
|
|
void (Algorithm::*set_float)(float);
|
|
|
|
void (Algorithm::*set_uint)(unsigned int);
|
|
|
|
void (Algorithm::*set_uint64)(uint64);
|
|
|
|
void (Algorithm::*set_uchar)(uchar);
|
2012-01-24 21:14:07 +01:00
|
|
|
};
|
2012-04-30 16:33:52 +02:00
|
|
|
|
2013-03-22 17:37:49 +01:00
|
|
|
static String getNameOfType(int argType);
|
2012-10-23 19:37:27 +02:00
|
|
|
|
2013-03-22 17:37:49 +01:00
|
|
|
static String getNameOfType(int argType)
|
2012-10-23 19:37:27 +02:00
|
|
|
{
|
|
|
|
switch(argType)
|
|
|
|
{
|
|
|
|
case Param::INT: return "integer";
|
|
|
|
case Param::BOOLEAN: return "boolean";
|
|
|
|
case Param::REAL: return "double";
|
|
|
|
case Param::STRING: return "string";
|
|
|
|
case Param::MAT: return "cv::Mat";
|
|
|
|
case Param::MAT_VECTOR: return "std::vector<cv::Mat>";
|
|
|
|
case Param::ALGORITHM: return "algorithm";
|
2013-02-04 17:25:18 +01:00
|
|
|
case Param::FLOAT: return "float";
|
|
|
|
case Param::UNSIGNED_INT: return "unsigned int";
|
|
|
|
case Param::UINT64: return "unsigned int64";
|
|
|
|
case Param::UCHAR: return "unsigned char";
|
2012-10-23 19:37:27 +02:00
|
|
|
default: CV_Error(CV_StsBadArg, "Wrong argument type");
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
2013-02-24 17:14:01 +01:00
|
|
|
|
2013-03-22 17:37:49 +01:00
|
|
|
static String getErrorMessageForWrongArgumentInSetter(String algoName, String paramName, int paramType, int argType)
|
2012-10-23 19:37:27 +02:00
|
|
|
{
|
2013-03-22 17:37:49 +01:00
|
|
|
String message = String("Argument error: the setter")
|
2012-10-23 19:37:27 +02:00
|
|
|
+ " method was called for the parameter '" + paramName + "' of the algorithm '" + algoName
|
|
|
|
+"', the parameter has " + getNameOfType(paramType) + " type, ";
|
|
|
|
|
2013-02-04 17:25:18 +01:00
|
|
|
if (paramType == Param::INT || paramType == Param::BOOLEAN || paramType == Param::REAL
|
|
|
|
|| paramType == Param::FLOAT || paramType == Param::UNSIGNED_INT || paramType == Param::UINT64 || paramType == Param::UCHAR)
|
2012-10-23 19:37:27 +02:00
|
|
|
{
|
2013-03-20 14:53:13 +01:00
|
|
|
message = message + "so it should be set by integer, unsigned integer, uint64, unsigned char, boolean, float or double value, ";
|
2012-10-23 19:37:27 +02:00
|
|
|
}
|
2013-03-20 14:53:13 +01:00
|
|
|
message = message + "but the setter was called with " + getNameOfType(argType) + " value";
|
2012-10-23 19:37:27 +02:00
|
|
|
|
|
|
|
return message;
|
|
|
|
}
|
|
|
|
|
2013-03-22 17:37:49 +01:00
|
|
|
static String getErrorMessageForWrongArgumentInGetter(String algoName, String paramName, int paramType, int argType)
|
2012-10-23 19:37:27 +02:00
|
|
|
{
|
2013-03-22 17:37:49 +01:00
|
|
|
String message = String("Argument error: the getter")
|
2012-10-23 19:37:27 +02:00
|
|
|
+ " method was called for the parameter '" + paramName + "' of the algorithm '" + algoName
|
|
|
|
+"', the parameter has " + getNameOfType(paramType) + " type, ";
|
|
|
|
|
|
|
|
if (paramType == Param::BOOLEAN)
|
|
|
|
{
|
2013-03-20 14:53:13 +01:00
|
|
|
message = message + "so it should be get as integer, unsigned integer, uint64, boolean, unsigned char, float or double value, ";
|
2012-10-23 19:37:27 +02:00
|
|
|
}
|
2013-02-04 17:25:18 +01:00
|
|
|
else if (paramType == Param::INT || paramType == Param::UNSIGNED_INT || paramType == Param::UINT64 || paramType == Param::UCHAR)
|
2012-10-23 19:37:27 +02:00
|
|
|
{
|
2013-03-20 14:53:13 +01:00
|
|
|
message = message + "so it should be get as integer, unsigned integer, uint64, unsigned char, float or double value, ";
|
2012-10-23 19:37:27 +02:00
|
|
|
}
|
2013-03-20 14:53:13 +01:00
|
|
|
message = message + "but the getter was called to get a " + getNameOfType(argType) + " value";
|
2012-10-23 19:37:27 +02:00
|
|
|
|
|
|
|
return message;
|
|
|
|
}
|
|
|
|
|
2012-06-09 17:00:04 +02:00
|
|
|
void AlgorithmInfo::set(Algorithm* algo, const char* parameter, int argType, const void* value, bool force) const
|
2012-01-24 21:14:07 +01:00
|
|
|
{
|
2012-06-09 17:00:04 +02:00
|
|
|
const Param* p = findstr(data->params, parameter);
|
2012-04-30 16:33:52 +02:00
|
|
|
|
2012-01-24 21:14:07 +01:00
|
|
|
if( !p )
|
2012-06-09 17:00:04 +02:00
|
|
|
CV_Error_( CV_StsBadArg, ("No parameter '%s' is found", parameter ? parameter : "<NULL>") );
|
2012-04-30 16:33:52 +02:00
|
|
|
|
|
|
|
if( !force && p->readonly )
|
2012-06-09 17:00:04 +02:00
|
|
|
CV_Error_( CV_StsError, ("Parameter '%s' is readonly", parameter));
|
2012-04-30 16:33:52 +02:00
|
|
|
|
2012-01-24 21:14:07 +01:00
|
|
|
GetSetParam f;
|
|
|
|
f.set_int = p->setter;
|
2012-04-30 16:33:52 +02:00
|
|
|
|
2013-02-28 08:10:40 +01:00
|
|
|
if( argType == Param::INT || argType == Param::BOOLEAN || argType == Param::REAL
|
2013-02-04 17:25:18 +01:00
|
|
|
|| argType == Param::FLOAT || argType == Param::UNSIGNED_INT || argType == Param::UINT64 || argType == Param::UCHAR)
|
2012-01-24 21:14:07 +01:00
|
|
|
{
|
2013-02-04 17:25:18 +01:00
|
|
|
if ( !( p->type == Param::INT || p->type == Param::REAL || p->type == Param::BOOLEAN
|
2013-02-28 08:10:40 +01:00
|
|
|
|| p->type == Param::UNSIGNED_INT || p->type == Param::UINT64 || p->type == Param::FLOAT || argType == Param::UCHAR) )
|
2012-10-23 19:37:27 +02:00
|
|
|
{
|
2013-03-22 17:37:49 +01:00
|
|
|
String message = getErrorMessageForWrongArgumentInSetter(algo->name(), parameter, p->type, argType);
|
2012-10-23 19:37:27 +02:00
|
|
|
CV_Error(CV_StsBadArg, message);
|
|
|
|
}
|
2012-04-30 16:33:52 +02:00
|
|
|
|
2012-01-24 21:14:07 +01:00
|
|
|
if( p->type == Param::INT )
|
|
|
|
{
|
2013-02-04 17:25:18 +01:00
|
|
|
bool is_ok = true;
|
2012-01-24 21:14:07 +01:00
|
|
|
int val = argType == Param::INT ? *(const int*)value :
|
2013-02-28 08:10:40 +01:00
|
|
|
argType == Param::BOOLEAN ? (int)*(const bool*)value :
|
2013-02-04 17:25:18 +01:00
|
|
|
argType == Param::REAL ? saturate_cast<int>(*(const double*)value) :
|
|
|
|
argType == Param::FLOAT ? saturate_cast<int>(*(const float*)value) :
|
|
|
|
argType == Param::UNSIGNED_INT ? (int)*(const unsigned int*)value :
|
|
|
|
argType == Param::UINT64 ? (int)*(const uint64*)value :
|
|
|
|
argType == Param::UCHAR ? (int)*(const uchar*)value :
|
|
|
|
(int)(is_ok = false);
|
|
|
|
|
|
|
|
if (!is_ok)
|
|
|
|
{
|
|
|
|
CV_Error(CV_StsBadArg, "Wrong argument type in the setter");
|
|
|
|
}
|
|
|
|
|
2012-01-24 21:14:07 +01:00
|
|
|
if( p->setter )
|
|
|
|
(algo->*f.set_int)(val);
|
|
|
|
else
|
|
|
|
*(int*)((uchar*)algo + p->offset) = val;
|
|
|
|
}
|
|
|
|
else if( p->type == Param::BOOLEAN )
|
|
|
|
{
|
2013-02-04 17:25:18 +01:00
|
|
|
bool is_ok = true;
|
2012-01-24 21:14:07 +01:00
|
|
|
bool val = argType == Param::INT ? *(const int*)value != 0 :
|
|
|
|
argType == Param::BOOLEAN ? *(const bool*)value :
|
2013-02-04 17:25:18 +01:00
|
|
|
argType == Param::REAL ? (*(const double*)value != 0) :
|
|
|
|
argType == Param::FLOAT ? (*(const float*)value != 0) :
|
|
|
|
argType == Param::UNSIGNED_INT ? (*(const unsigned int*)value != 0):
|
|
|
|
argType == Param::UINT64 ? (*(const uint64*)value != 0):
|
|
|
|
argType == Param::UCHAR ? (*(const uchar*)value != 0):
|
|
|
|
(int)(is_ok = false);
|
|
|
|
|
|
|
|
if (!is_ok)
|
|
|
|
{
|
|
|
|
CV_Error(CV_StsBadArg, "Wrong argument type in the setter");
|
|
|
|
}
|
|
|
|
|
2012-01-24 21:14:07 +01:00
|
|
|
if( p->setter )
|
|
|
|
(algo->*f.set_bool)(val);
|
|
|
|
else
|
|
|
|
*(bool*)((uchar*)algo + p->offset) = val;
|
|
|
|
}
|
2013-02-04 17:25:18 +01:00
|
|
|
else if( p->type == Param::REAL )
|
2012-01-24 21:14:07 +01:00
|
|
|
{
|
2013-02-04 17:25:18 +01:00
|
|
|
bool is_ok = true;
|
2012-01-24 21:14:07 +01:00
|
|
|
double val = argType == Param::INT ? (double)*(const int*)value :
|
|
|
|
argType == Param::BOOLEAN ? (double)*(const bool*)value :
|
2013-02-04 17:25:18 +01:00
|
|
|
argType == Param::REAL ? (double)(*(const double*)value ) :
|
|
|
|
argType == Param::FLOAT ? (double)(*(const float*)value ) :
|
|
|
|
argType == Param::UNSIGNED_INT ? (double)(*(const unsigned int*)value ) :
|
|
|
|
argType == Param::UINT64 ? (double)(*(const uint64*)value ) :
|
|
|
|
argType == Param::UCHAR ? (double)(*(const uchar*)value ) :
|
|
|
|
(double)(is_ok = false);
|
|
|
|
|
|
|
|
if (!is_ok)
|
|
|
|
{
|
|
|
|
CV_Error(CV_StsBadArg, "Wrong argument type in the setter");
|
|
|
|
}
|
2012-01-24 21:14:07 +01:00
|
|
|
if( p->setter )
|
|
|
|
(algo->*f.set_double)(val);
|
|
|
|
else
|
|
|
|
*(double*)((uchar*)algo + p->offset) = val;
|
|
|
|
}
|
2013-02-04 17:25:18 +01:00
|
|
|
else if( p->type == Param::FLOAT )
|
|
|
|
{
|
|
|
|
bool is_ok = true;
|
|
|
|
double val = argType == Param::INT ? (double)*(const int*)value :
|
|
|
|
argType == Param::BOOLEAN ? (double)*(const bool*)value :
|
|
|
|
argType == Param::REAL ? (double)(*(const double*)value ) :
|
|
|
|
argType == Param::FLOAT ? (double)(*(const float*)value ) :
|
|
|
|
argType == Param::UNSIGNED_INT ? (double)(*(const unsigned int*)value ) :
|
|
|
|
argType == Param::UINT64 ? (double)(*(const uint64*)value ) :
|
|
|
|
argType == Param::UCHAR ? (double)(*(const uchar*)value ) :
|
|
|
|
(double)(is_ok = false);
|
|
|
|
|
|
|
|
if (!is_ok)
|
|
|
|
{
|
|
|
|
CV_Error(CV_StsBadArg, "Wrong argument type in the setter");
|
|
|
|
}
|
|
|
|
if( p->setter )
|
|
|
|
(algo->*f.set_float)((float)val);
|
|
|
|
else
|
|
|
|
*(float*)((uchar*)algo + p->offset) = (float)val;
|
|
|
|
}
|
|
|
|
else if( p->type == Param::UNSIGNED_INT )
|
|
|
|
{
|
|
|
|
bool is_ok = true;
|
|
|
|
unsigned int val = argType == Param::INT ? (unsigned int)*(const int*)value :
|
|
|
|
argType == Param::BOOLEAN ? (unsigned int)*(const bool*)value :
|
|
|
|
argType == Param::REAL ? saturate_cast<unsigned int>(*(const double*)value ) :
|
|
|
|
argType == Param::FLOAT ? saturate_cast<unsigned int>(*(const float*)value ) :
|
|
|
|
argType == Param::UNSIGNED_INT ? (unsigned int)(*(const unsigned int*)value ) :
|
|
|
|
argType == Param::UINT64 ? (unsigned int)(*(const uint64*)value ) :
|
|
|
|
argType == Param::UCHAR ? (unsigned int)(*(const uchar*)value ) :
|
|
|
|
(int)(is_ok = false);
|
|
|
|
|
|
|
|
if (!is_ok)
|
|
|
|
{
|
|
|
|
CV_Error(CV_StsBadArg, "Wrong argument type in the setter");
|
|
|
|
}
|
|
|
|
if( p->setter )
|
|
|
|
(algo->*f.set_uint)(val);
|
|
|
|
else
|
|
|
|
*(unsigned int*)((uchar*)algo + p->offset) = val;
|
|
|
|
}
|
|
|
|
else if( p->type == Param::UINT64 )
|
|
|
|
{
|
|
|
|
bool is_ok = true;
|
|
|
|
uint64 val = argType == Param::INT ? (uint64)*(const int*)value :
|
|
|
|
argType == Param::BOOLEAN ? (uint64)*(const bool*)value :
|
|
|
|
argType == Param::REAL ? saturate_cast<uint64>(*(const double*)value ) :
|
|
|
|
argType == Param::FLOAT ? saturate_cast<uint64>(*(const float*)value ) :
|
|
|
|
argType == Param::UNSIGNED_INT ? (uint64)(*(const unsigned int*)value ) :
|
|
|
|
argType == Param::UINT64 ? (uint64)(*(const uint64*)value ) :
|
|
|
|
argType == Param::UCHAR ? (uint64)(*(const uchar*)value ) :
|
|
|
|
(int)(is_ok = false);
|
|
|
|
|
|
|
|
if (!is_ok)
|
|
|
|
{
|
|
|
|
CV_Error(CV_StsBadArg, "Wrong argument type in the setter");
|
|
|
|
}
|
|
|
|
if( p->setter )
|
|
|
|
(algo->*f.set_uint64)(val);
|
|
|
|
else
|
|
|
|
*(uint64*)((uchar*)algo + p->offset) = val;
|
|
|
|
}
|
|
|
|
else if( p->type == Param::UCHAR )
|
|
|
|
{
|
|
|
|
bool is_ok = true;
|
|
|
|
uchar val = argType == Param::INT ? (uchar)*(const int*)value :
|
|
|
|
argType == Param::BOOLEAN ? (uchar)*(const bool*)value :
|
|
|
|
argType == Param::REAL ? saturate_cast<uchar>(*(const double*)value ) :
|
|
|
|
argType == Param::FLOAT ? saturate_cast<uchar>(*(const float*)value ) :
|
|
|
|
argType == Param::UNSIGNED_INT ? (uchar)(*(const unsigned int*)value ) :
|
|
|
|
argType == Param::UINT64 ? (uchar)(*(const uint64*)value ) :
|
|
|
|
argType == Param::UCHAR ? (uchar)(*(const uchar*)value ) :
|
|
|
|
(int)(is_ok = false);
|
|
|
|
|
|
|
|
if (!is_ok)
|
|
|
|
{
|
|
|
|
CV_Error(CV_StsBadArg, "Wrong argument type in the setter");
|
|
|
|
}
|
|
|
|
if( p->setter )
|
|
|
|
(algo->*f.set_uchar)(val);
|
|
|
|
else
|
|
|
|
*(uchar*)((uchar*)algo + p->offset) = val;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
CV_Error(CV_StsBadArg, "Wrong parameter type in the setter");
|
2012-01-24 21:14:07 +01:00
|
|
|
}
|
|
|
|
else if( argType == Param::STRING )
|
|
|
|
{
|
2012-10-23 19:37:27 +02:00
|
|
|
if( p->type != Param::STRING )
|
|
|
|
{
|
2013-03-22 17:37:49 +01:00
|
|
|
String message = getErrorMessageForWrongArgumentInSetter(algo->name(), parameter, p->type, argType);
|
2012-10-23 19:37:27 +02:00
|
|
|
CV_Error(CV_StsBadArg, message);
|
|
|
|
}
|
2012-04-30 16:33:52 +02:00
|
|
|
|
2013-03-22 17:37:49 +01:00
|
|
|
const String& val = *(const String*)value;
|
2012-01-24 21:14:07 +01:00
|
|
|
if( p->setter )
|
|
|
|
(algo->*f.set_string)(val);
|
|
|
|
else
|
2013-03-22 17:37:49 +01:00
|
|
|
*(String*)((uchar*)algo + p->offset) = val;
|
2012-01-24 21:14:07 +01:00
|
|
|
}
|
|
|
|
else if( argType == Param::MAT )
|
|
|
|
{
|
2012-10-23 19:37:27 +02:00
|
|
|
if( p->type != Param::MAT )
|
|
|
|
{
|
2013-03-22 17:37:49 +01:00
|
|
|
String message = getErrorMessageForWrongArgumentInSetter(algo->name(), parameter, p->type, argType);
|
2012-10-23 19:37:27 +02:00
|
|
|
CV_Error(CV_StsBadArg, message);
|
|
|
|
}
|
2012-04-30 16:33:52 +02:00
|
|
|
|
2012-01-24 21:14:07 +01:00
|
|
|
const Mat& val = *(const Mat*)value;
|
|
|
|
if( p->setter )
|
|
|
|
(algo->*f.set_mat)(val);
|
|
|
|
else
|
|
|
|
*(Mat*)((uchar*)algo + p->offset) = val;
|
|
|
|
}
|
2012-04-13 23:50:59 +02:00
|
|
|
else if( argType == Param::MAT_VECTOR )
|
|
|
|
{
|
2012-10-23 19:37:27 +02:00
|
|
|
if( p->type != Param::MAT_VECTOR )
|
|
|
|
{
|
2013-03-22 17:37:49 +01:00
|
|
|
String message = getErrorMessageForWrongArgumentInSetter(algo->name(), parameter, p->type, argType);
|
2012-10-23 19:37:27 +02:00
|
|
|
CV_Error(CV_StsBadArg, message);
|
|
|
|
}
|
2012-04-30 16:33:52 +02:00
|
|
|
|
2013-02-24 17:14:01 +01:00
|
|
|
const std::vector<Mat>& val = *(const std::vector<Mat>*)value;
|
2012-04-13 23:50:59 +02:00
|
|
|
if( p->setter )
|
|
|
|
(algo->*f.set_mat_vector)(val);
|
|
|
|
else
|
2013-02-24 17:14:01 +01:00
|
|
|
*(std::vector<Mat>*)((uchar*)algo + p->offset) = val;
|
2012-04-13 23:50:59 +02:00
|
|
|
}
|
2012-01-24 21:14:07 +01:00
|
|
|
else if( argType == Param::ALGORITHM )
|
|
|
|
{
|
2012-10-23 19:37:27 +02:00
|
|
|
if( p->type != Param::ALGORITHM )
|
|
|
|
{
|
2013-03-22 17:37:49 +01:00
|
|
|
String message = getErrorMessageForWrongArgumentInSetter(algo->name(), parameter, p->type, argType);
|
2012-10-23 19:37:27 +02:00
|
|
|
CV_Error(CV_StsBadArg, message);
|
|
|
|
}
|
2012-04-30 16:33:52 +02:00
|
|
|
|
2012-01-24 21:14:07 +01:00
|
|
|
const Ptr<Algorithm>& val = *(const Ptr<Algorithm>*)value;
|
|
|
|
if( p->setter )
|
|
|
|
(algo->*f.set_algo)(val);
|
|
|
|
else
|
|
|
|
*(Ptr<Algorithm>*)((uchar*)algo + p->offset) = val;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
CV_Error(CV_StsBadArg, "Unknown/unsupported parameter type");
|
|
|
|
}
|
2012-06-09 17:00:04 +02:00
|
|
|
|
|
|
|
void AlgorithmInfo::get(const Algorithm* algo, const char* parameter, int argType, void* value) const
|
2012-01-24 21:14:07 +01:00
|
|
|
{
|
2012-06-09 17:00:04 +02:00
|
|
|
const Param* p = findstr(data->params, parameter);
|
2012-01-24 21:14:07 +01:00
|
|
|
if( !p )
|
2012-06-09 17:00:04 +02:00
|
|
|
CV_Error_( CV_StsBadArg, ("No parameter '%s' is found", parameter ? parameter : "<NULL>") );
|
|
|
|
|
2012-01-24 21:14:07 +01:00
|
|
|
GetSetParam f;
|
|
|
|
f.get_int = p->getter;
|
2012-06-09 17:00:04 +02:00
|
|
|
|
2013-02-28 08:10:40 +01:00
|
|
|
if( argType == Param::INT || argType == Param::BOOLEAN || argType == Param::REAL
|
2013-02-04 17:25:18 +01:00
|
|
|
|| argType == Param::FLOAT || argType == Param::UNSIGNED_INT || argType == Param::UINT64 || argType == Param::UCHAR)
|
2012-01-24 21:14:07 +01:00
|
|
|
{
|
|
|
|
if( p->type == Param::INT )
|
|
|
|
{
|
2013-02-04 17:25:18 +01:00
|
|
|
if (!( argType == Param::INT || argType == Param::REAL || argType == Param::FLOAT || argType == Param::UNSIGNED_INT || argType == Param::UINT64 || argType == Param::UCHAR))
|
2012-10-23 19:37:27 +02:00
|
|
|
{
|
2013-03-22 17:37:49 +01:00
|
|
|
String message = getErrorMessageForWrongArgumentInGetter(algo->name(), parameter, p->type, argType);
|
2012-10-23 19:37:27 +02:00
|
|
|
CV_Error(CV_StsBadArg, message);
|
|
|
|
}
|
2012-01-24 21:14:07 +01:00
|
|
|
int val = p->getter ? (algo->*f.get_int)() : *(int*)((uchar*)algo + p->offset);
|
2012-06-09 17:00:04 +02:00
|
|
|
|
2012-01-24 21:14:07 +01:00
|
|
|
if( argType == Param::INT )
|
2013-02-25 12:38:59 +01:00
|
|
|
*(int*)value = (int)val;
|
2013-02-04 17:25:18 +01:00
|
|
|
else if ( argType == Param::REAL )
|
2013-02-25 12:38:59 +01:00
|
|
|
*(double*)value = (double)val;
|
2013-02-04 17:25:18 +01:00
|
|
|
else if ( argType == Param::FLOAT)
|
2013-02-25 12:38:59 +01:00
|
|
|
*(float*)value = (float)val;
|
2013-02-04 17:25:18 +01:00
|
|
|
else if ( argType == Param::UNSIGNED_INT )
|
2013-02-25 12:38:59 +01:00
|
|
|
*(unsigned int*)value = (unsigned int)val;
|
2013-02-04 17:25:18 +01:00
|
|
|
else if ( argType == Param::UINT64 )
|
2013-02-25 12:38:59 +01:00
|
|
|
*(uint64*)value = (uint64)val;
|
2013-02-04 17:25:18 +01:00
|
|
|
else if ( argType == Param::UCHAR)
|
2013-02-25 12:38:59 +01:00
|
|
|
*(uchar*)value = (uchar)val;
|
2012-01-24 21:14:07 +01:00
|
|
|
else
|
2013-02-04 17:25:18 +01:00
|
|
|
CV_Error(CV_StsBadArg, "Wrong argument type");
|
|
|
|
|
2012-01-24 21:14:07 +01:00
|
|
|
}
|
|
|
|
else if( p->type == Param::BOOLEAN )
|
|
|
|
{
|
2013-02-04 17:25:18 +01:00
|
|
|
if (!( argType == Param::INT || argType == Param::BOOLEAN || argType == Param::REAL || argType == Param::FLOAT || argType == Param::UNSIGNED_INT || argType == Param::UINT64 || argType == Param::UCHAR))
|
2012-10-23 19:37:27 +02:00
|
|
|
{
|
2013-03-22 17:37:49 +01:00
|
|
|
String message = getErrorMessageForWrongArgumentInGetter(algo->name(), parameter, p->type, argType);
|
2012-10-23 19:37:27 +02:00
|
|
|
CV_Error(CV_StsBadArg, message);
|
|
|
|
}
|
2012-01-24 21:14:07 +01:00
|
|
|
bool val = p->getter ? (algo->*f.get_bool)() : *(bool*)((uchar*)algo + p->offset);
|
2012-06-09 17:00:04 +02:00
|
|
|
|
2012-01-24 21:14:07 +01:00
|
|
|
if( argType == Param::INT )
|
|
|
|
*(int*)value = (int)val;
|
|
|
|
else if( argType == Param::BOOLEAN )
|
|
|
|
*(bool*)value = val;
|
2013-02-04 17:25:18 +01:00
|
|
|
else if ( argType == Param::REAL )
|
2012-01-24 21:14:07 +01:00
|
|
|
*(double*)value = (int)val;
|
2013-02-04 17:25:18 +01:00
|
|
|
else if ( argType == Param::FLOAT)
|
2013-02-25 12:38:59 +01:00
|
|
|
*(float*)value = (float)((int)val);
|
2013-02-04 17:25:18 +01:00
|
|
|
else if ( argType == Param::UNSIGNED_INT )
|
2013-02-25 12:38:59 +01:00
|
|
|
*(unsigned int*)value = (unsigned int)val;
|
2013-02-04 17:25:18 +01:00
|
|
|
else if ( argType == Param::UINT64 )
|
|
|
|
*(uint64*)value = (int)val;
|
|
|
|
else if ( argType == Param::UCHAR)
|
2013-02-25 12:38:59 +01:00
|
|
|
*(uchar*)value = (uchar)val;
|
2013-02-04 17:25:18 +01:00
|
|
|
else
|
|
|
|
CV_Error(CV_StsBadArg, "Wrong argument type");
|
2012-01-24 21:14:07 +01:00
|
|
|
}
|
2013-02-04 17:25:18 +01:00
|
|
|
else if( p->type == Param::REAL )
|
2012-01-24 21:14:07 +01:00
|
|
|
{
|
2013-02-04 17:25:18 +01:00
|
|
|
if(!( argType == Param::REAL || argType == Param::FLOAT))
|
2012-10-23 19:37:27 +02:00
|
|
|
{
|
2013-03-22 17:37:49 +01:00
|
|
|
String message = getErrorMessageForWrongArgumentInGetter(algo->name(), parameter, p->type, argType);
|
2012-10-23 19:37:27 +02:00
|
|
|
CV_Error(CV_StsBadArg, message);
|
|
|
|
}
|
2012-01-24 21:14:07 +01:00
|
|
|
double val = p->getter ? (algo->*f.get_double)() : *(double*)((uchar*)algo + p->offset);
|
2012-06-09 17:00:04 +02:00
|
|
|
|
2013-02-04 17:25:18 +01:00
|
|
|
if ( argType == Param::REAL )
|
|
|
|
*(double*)value = val;
|
|
|
|
else if ( argType == Param::FLOAT)
|
|
|
|
*(float*)value = (float)val;
|
|
|
|
else
|
|
|
|
CV_Error(CV_StsBadArg, "Wrong argument type");
|
|
|
|
}
|
|
|
|
else if( p->type == Param::FLOAT )
|
|
|
|
{
|
|
|
|
if(!( argType == Param::REAL || argType == Param::FLOAT))
|
|
|
|
{
|
2013-03-22 17:37:49 +01:00
|
|
|
String message = getErrorMessageForWrongArgumentInGetter(algo->name(), parameter, p->type, argType);
|
2013-02-04 17:25:18 +01:00
|
|
|
CV_Error(CV_StsBadArg, message);
|
|
|
|
}
|
|
|
|
float val = p->getter ? (algo->*f.get_float)() : *(float*)((uchar*)algo + p->offset);
|
|
|
|
|
|
|
|
if ( argType == Param::REAL )
|
|
|
|
*(double*)value = (double)val;
|
|
|
|
else if ( argType == Param::FLOAT)
|
|
|
|
*(float*)value = (float)val;
|
|
|
|
else
|
|
|
|
CV_Error(CV_StsBadArg, "Wrong argument type");
|
2012-01-24 21:14:07 +01:00
|
|
|
}
|
2013-02-04 17:25:18 +01:00
|
|
|
else if( p->type == Param::UNSIGNED_INT )
|
|
|
|
{
|
|
|
|
if (!( argType == Param::INT || argType == Param::REAL || argType == Param::FLOAT || argType == Param::UNSIGNED_INT || argType == Param::UINT64 || argType == Param::UCHAR))
|
|
|
|
{
|
2013-03-22 17:37:49 +01:00
|
|
|
String message = getErrorMessageForWrongArgumentInGetter(algo->name(), parameter, p->type, argType);
|
2013-02-04 17:25:18 +01:00
|
|
|
CV_Error(CV_StsBadArg, message);
|
|
|
|
}
|
|
|
|
unsigned int val = p->getter ? (algo->*f.get_uint)() : *(unsigned int*)((uchar*)algo + p->offset);
|
|
|
|
|
|
|
|
if( argType == Param::INT )
|
2013-02-25 12:38:59 +01:00
|
|
|
*(int*)value = (int)val;
|
2013-02-04 17:25:18 +01:00
|
|
|
else if ( argType == Param::REAL )
|
2013-02-25 12:38:59 +01:00
|
|
|
*(double*)value = (double)val;
|
2013-02-04 17:25:18 +01:00
|
|
|
else if ( argType == Param::FLOAT)
|
2013-02-25 12:38:59 +01:00
|
|
|
*(float*)value = (float)val;
|
2013-02-04 17:25:18 +01:00
|
|
|
else if ( argType == Param::UNSIGNED_INT )
|
2013-02-25 12:38:59 +01:00
|
|
|
*(unsigned int*)value = (unsigned int)val;
|
2013-02-04 17:25:18 +01:00
|
|
|
else if ( argType == Param::UINT64 )
|
2013-02-25 12:38:59 +01:00
|
|
|
*(uint64*)value = (uint64)val;
|
2013-02-04 17:25:18 +01:00
|
|
|
else if ( argType == Param::UCHAR)
|
2013-02-25 12:38:59 +01:00
|
|
|
*(uchar*)value = (uchar)val;
|
2013-02-04 17:25:18 +01:00
|
|
|
else
|
|
|
|
CV_Error(CV_StsBadArg, "Wrong argument type");
|
|
|
|
}
|
|
|
|
else if( p->type == Param::UINT64 )
|
|
|
|
{
|
|
|
|
if (!( argType == Param::INT || argType == Param::REAL || argType == Param::FLOAT || argType == Param::UNSIGNED_INT || argType == Param::UINT64 || argType == Param::UCHAR))
|
|
|
|
{
|
2013-03-22 17:37:49 +01:00
|
|
|
String message = getErrorMessageForWrongArgumentInGetter(algo->name(), parameter, p->type, argType);
|
2013-02-04 17:25:18 +01:00
|
|
|
CV_Error(CV_StsBadArg, message);
|
2013-02-28 08:10:40 +01:00
|
|
|
}
|
2013-02-04 17:25:18 +01:00
|
|
|
uint64 val = p->getter ? (algo->*f.get_uint64)() : *(uint64*)((uchar*)algo + p->offset);
|
|
|
|
|
|
|
|
if( argType == Param::INT )
|
2013-02-25 12:38:59 +01:00
|
|
|
*(int*)value = (int)val;
|
2013-02-04 17:25:18 +01:00
|
|
|
else if ( argType == Param::REAL )
|
2013-02-25 12:38:59 +01:00
|
|
|
*(double*)value = (double)val;
|
2013-02-04 17:25:18 +01:00
|
|
|
else if ( argType == Param::FLOAT)
|
2013-02-25 12:38:59 +01:00
|
|
|
*(float*)value = (float)val;
|
2013-02-04 17:25:18 +01:00
|
|
|
else if ( argType == Param::UNSIGNED_INT )
|
2013-02-25 12:38:59 +01:00
|
|
|
*(unsigned int*)value = (unsigned int)val;
|
2013-02-04 17:25:18 +01:00
|
|
|
else if ( argType == Param::UINT64 )
|
2013-02-25 12:38:59 +01:00
|
|
|
*(uint64*)value = (uint64)val;
|
2013-02-04 17:25:18 +01:00
|
|
|
else if ( argType == Param::UCHAR)
|
2013-02-25 12:38:59 +01:00
|
|
|
*(uchar*)value = (uchar)val;
|
2013-02-28 08:10:40 +01:00
|
|
|
else
|
2013-02-04 17:25:18 +01:00
|
|
|
CV_Error(CV_StsBadArg, "Wrong argument type");
|
|
|
|
}
|
|
|
|
else if( p->type == Param::UCHAR )
|
|
|
|
{
|
|
|
|
if (!( argType == Param::INT || argType == Param::REAL || argType == Param::FLOAT || argType == Param::UNSIGNED_INT || argType == Param::UINT64 || argType == Param::UCHAR))
|
|
|
|
{
|
2013-03-22 17:37:49 +01:00
|
|
|
String message = getErrorMessageForWrongArgumentInGetter(algo->name(), parameter, p->type, argType);
|
2013-02-04 17:25:18 +01:00
|
|
|
CV_Error(CV_StsBadArg, message);
|
|
|
|
}
|
|
|
|
uchar val = p->getter ? (algo->*f.get_uchar)() : *(uchar*)((uchar*)algo + p->offset);
|
|
|
|
|
|
|
|
if( argType == Param::INT )
|
|
|
|
*(int*)value = val;
|
|
|
|
else if ( argType == Param::REAL )
|
2012-01-24 21:14:07 +01:00
|
|
|
*(double*)value = val;
|
2013-02-04 17:25:18 +01:00
|
|
|
else if ( argType == Param::FLOAT)
|
|
|
|
*(float*)value = val;
|
|
|
|
else if ( argType == Param::UNSIGNED_INT )
|
|
|
|
*(unsigned int*)value = val;
|
|
|
|
else if ( argType == Param::UINT64 )
|
|
|
|
*(uint64*)value = val;
|
|
|
|
else if ( argType == Param::UCHAR)
|
|
|
|
*(uchar*)value = val;
|
|
|
|
else
|
|
|
|
CV_Error(CV_StsBadArg, "Wrong argument type");
|
|
|
|
|
2012-01-24 21:14:07 +01:00
|
|
|
}
|
2013-02-04 17:25:18 +01:00
|
|
|
else
|
|
|
|
CV_Error(CV_StsBadArg, "Unknown/unsupported parameter type");
|
2012-01-24 21:14:07 +01:00
|
|
|
}
|
|
|
|
else if( argType == Param::STRING )
|
|
|
|
{
|
2012-10-23 19:37:27 +02:00
|
|
|
if( p->type != Param::STRING )
|
|
|
|
{
|
2013-03-22 17:37:49 +01:00
|
|
|
String message = getErrorMessageForWrongArgumentInGetter(algo->name(), parameter, p->type, argType);
|
2012-10-23 19:37:27 +02:00
|
|
|
CV_Error(CV_StsBadArg, message);
|
|
|
|
}
|
2012-06-09 17:00:04 +02:00
|
|
|
|
2013-03-22 17:37:49 +01:00
|
|
|
*(String*)value = p->getter ? (algo->*f.get_string)() :
|
|
|
|
*(String*)((uchar*)algo + p->offset);
|
2012-01-24 21:14:07 +01:00
|
|
|
}
|
|
|
|
else if( argType == Param::MAT )
|
|
|
|
{
|
2012-10-23 19:37:27 +02:00
|
|
|
if( p->type != Param::MAT )
|
|
|
|
{
|
2013-03-22 17:37:49 +01:00
|
|
|
String message = getErrorMessageForWrongArgumentInGetter(algo->name(), parameter, p->type, argType);
|
2012-10-23 19:37:27 +02:00
|
|
|
CV_Error(CV_StsBadArg, message);
|
|
|
|
}
|
2012-06-09 17:00:04 +02:00
|
|
|
|
2012-01-24 21:14:07 +01:00
|
|
|
*(Mat*)value = p->getter ? (algo->*f.get_mat)() :
|
|
|
|
*(Mat*)((uchar*)algo + p->offset);
|
|
|
|
}
|
2012-04-13 23:50:59 +02:00
|
|
|
else if( argType == Param::MAT_VECTOR )
|
|
|
|
{
|
2012-10-23 19:37:27 +02:00
|
|
|
if( p->type != Param::MAT_VECTOR )
|
|
|
|
{
|
2013-03-22 17:37:49 +01:00
|
|
|
String message = getErrorMessageForWrongArgumentInGetter(algo->name(), parameter, p->type, argType);
|
2012-10-23 19:37:27 +02:00
|
|
|
CV_Error(CV_StsBadArg, message);
|
|
|
|
}
|
2012-06-09 17:00:04 +02:00
|
|
|
|
2013-02-24 17:14:01 +01:00
|
|
|
*(std::vector<Mat>*)value = p->getter ? (algo->*f.get_mat_vector)() :
|
|
|
|
*(std::vector<Mat>*)((uchar*)algo + p->offset);
|
2012-04-13 23:50:59 +02:00
|
|
|
}
|
2012-01-24 21:14:07 +01:00
|
|
|
else if( argType == Param::ALGORITHM )
|
|
|
|
{
|
2012-10-23 19:37:27 +02:00
|
|
|
if( p->type != Param::ALGORITHM )
|
|
|
|
{
|
2013-03-22 17:37:49 +01:00
|
|
|
String message = getErrorMessageForWrongArgumentInGetter(algo->name(), parameter, p->type, argType);
|
2012-10-23 19:37:27 +02:00
|
|
|
CV_Error(CV_StsBadArg, message);
|
|
|
|
}
|
2012-06-09 17:00:04 +02:00
|
|
|
|
2012-01-24 21:14:07 +01:00
|
|
|
*(Ptr<Algorithm>*)value = p->getter ? (algo->*f.get_algo)() :
|
|
|
|
*(Ptr<Algorithm>*)((uchar*)algo + p->offset);
|
|
|
|
}
|
|
|
|
else
|
2012-10-25 16:59:10 +02:00
|
|
|
{
|
2013-03-22 17:37:49 +01:00
|
|
|
String message = getErrorMessageForWrongArgumentInGetter(algo->name(), parameter, p->type, argType);
|
2012-10-25 16:59:10 +02:00
|
|
|
CV_Error(CV_StsBadArg, message);
|
|
|
|
}
|
2012-01-24 21:14:07 +01:00
|
|
|
}
|
|
|
|
|
2012-06-09 17:00:04 +02:00
|
|
|
|
|
|
|
int AlgorithmInfo::paramType(const char* parameter) const
|
2012-01-24 21:14:07 +01:00
|
|
|
{
|
2012-06-09 17:00:04 +02:00
|
|
|
const Param* p = findstr(data->params, parameter);
|
2012-01-24 21:14:07 +01:00
|
|
|
if( !p )
|
2012-06-09 17:00:04 +02:00
|
|
|
CV_Error_( CV_StsBadArg, ("No parameter '%s' is found", parameter ? parameter : "<NULL>") );
|
2012-01-24 21:14:07 +01:00
|
|
|
return p->type;
|
|
|
|
}
|
2012-06-09 17:00:04 +02:00
|
|
|
|
|
|
|
|
2013-03-22 17:37:49 +01:00
|
|
|
String AlgorithmInfo::paramHelp(const char* parameter) const
|
2012-01-24 21:14:07 +01:00
|
|
|
{
|
2012-06-09 17:00:04 +02:00
|
|
|
const Param* p = findstr(data->params, parameter);
|
2012-01-24 21:14:07 +01:00
|
|
|
if( !p )
|
2012-06-09 17:00:04 +02:00
|
|
|
CV_Error_( CV_StsBadArg, ("No parameter '%s' is found", parameter ? parameter : "<NULL>") );
|
2012-01-24 21:14:07 +01:00
|
|
|
return p->help;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-22 17:37:49 +01:00
|
|
|
void AlgorithmInfo::getParams(std::vector<String>& names) const
|
2012-01-24 21:14:07 +01:00
|
|
|
{
|
|
|
|
data->params.get_keys(names);
|
|
|
|
}
|
2012-06-09 17:00:04 +02:00
|
|
|
|
|
|
|
|
|
|
|
void AlgorithmInfo::addParam_(Algorithm& algo, const char* parameter, int argType,
|
|
|
|
void* value, bool readOnly,
|
2012-01-24 21:14:07 +01:00
|
|
|
Algorithm::Getter getter, Algorithm::Setter setter,
|
2013-03-22 17:37:49 +01:00
|
|
|
const String& help)
|
2012-01-24 21:14:07 +01:00
|
|
|
{
|
|
|
|
CV_Assert( argType == Param::INT || argType == Param::BOOLEAN ||
|
|
|
|
argType == Param::REAL || argType == Param::STRING ||
|
2012-04-13 23:50:59 +02:00
|
|
|
argType == Param::MAT || argType == Param::MAT_VECTOR ||
|
2013-02-28 08:10:40 +01:00
|
|
|
argType == Param::ALGORITHM
|
2013-02-04 17:25:18 +01:00
|
|
|
|| argType == Param::FLOAT || argType == Param::UNSIGNED_INT || argType == Param::UINT64
|
|
|
|
|| argType == Param::UCHAR);
|
2013-03-22 17:37:49 +01:00
|
|
|
data->params.add(String(parameter), Param(argType, readOnly,
|
2012-03-17 10:50:47 +01:00
|
|
|
(int)((size_t)value - (size_t)(void*)&algo),
|
2012-01-24 21:14:07 +01:00
|
|
|
getter, setter, help));
|
|
|
|
}
|
2012-06-09 17:00:04 +02:00
|
|
|
|
|
|
|
|
|
|
|
void AlgorithmInfo::addParam(Algorithm& algo, const char* parameter,
|
|
|
|
int& value, bool readOnly,
|
2012-02-15 22:10:11 +01:00
|
|
|
int (Algorithm::*getter)(),
|
|
|
|
void (Algorithm::*setter)(int),
|
2013-03-22 17:37:49 +01:00
|
|
|
const String& help)
|
2012-02-15 22:10:11 +01:00
|
|
|
{
|
2012-06-09 17:00:04 +02:00
|
|
|
addParam_(algo, parameter, ParamType<int>::type, &value, readOnly,
|
2012-02-15 22:10:11 +01:00
|
|
|
(Algorithm::Getter)getter, (Algorithm::Setter)setter, help);
|
|
|
|
}
|
|
|
|
|
2012-06-09 17:00:04 +02:00
|
|
|
void AlgorithmInfo::addParam(Algorithm& algo, const char* parameter,
|
|
|
|
bool& value, bool readOnly,
|
2012-03-15 15:36:01 +01:00
|
|
|
int (Algorithm::*getter)(),
|
|
|
|
void (Algorithm::*setter)(int),
|
2013-03-22 17:37:49 +01:00
|
|
|
const String& help)
|
2012-03-15 15:36:01 +01:00
|
|
|
{
|
2012-06-09 17:00:04 +02:00
|
|
|
addParam_(algo, parameter, ParamType<bool>::type, &value, readOnly,
|
2012-03-15 15:36:01 +01:00
|
|
|
(Algorithm::Getter)getter, (Algorithm::Setter)setter, help);
|
|
|
|
}
|
2012-06-09 17:00:04 +02:00
|
|
|
|
|
|
|
void AlgorithmInfo::addParam(Algorithm& algo, const char* parameter,
|
|
|
|
double& value, bool readOnly,
|
2012-02-15 22:10:11 +01:00
|
|
|
double (Algorithm::*getter)(),
|
|
|
|
void (Algorithm::*setter)(double),
|
2013-03-22 17:37:49 +01:00
|
|
|
const String& help)
|
2012-02-15 22:10:11 +01:00
|
|
|
{
|
2012-06-09 17:00:04 +02:00
|
|
|
addParam_(algo, parameter, ParamType<double>::type, &value, readOnly,
|
2012-02-15 22:10:11 +01:00
|
|
|
(Algorithm::Getter)getter, (Algorithm::Setter)setter, help);
|
|
|
|
}
|
|
|
|
|
2012-06-09 17:00:04 +02:00
|
|
|
void AlgorithmInfo::addParam(Algorithm& algo, const char* parameter,
|
2013-03-22 17:37:49 +01:00
|
|
|
String& value, bool readOnly,
|
|
|
|
String (Algorithm::*getter)(),
|
|
|
|
void (Algorithm::*setter)(const String&),
|
|
|
|
const String& help)
|
2012-02-15 22:10:11 +01:00
|
|
|
{
|
2013-03-22 17:37:49 +01:00
|
|
|
addParam_(algo, parameter, ParamType<String>::type, &value, readOnly,
|
2012-02-15 22:10:11 +01:00
|
|
|
(Algorithm::Getter)getter, (Algorithm::Setter)setter, help);
|
|
|
|
}
|
|
|
|
|
2012-06-09 17:00:04 +02:00
|
|
|
void AlgorithmInfo::addParam(Algorithm& algo, const char* parameter,
|
|
|
|
Mat& value, bool readOnly,
|
2012-02-15 22:10:11 +01:00
|
|
|
Mat (Algorithm::*getter)(),
|
|
|
|
void (Algorithm::*setter)(const Mat&),
|
2013-03-22 17:37:49 +01:00
|
|
|
const String& help)
|
2012-02-15 22:10:11 +01:00
|
|
|
{
|
2012-06-09 17:00:04 +02:00
|
|
|
addParam_(algo, parameter, ParamType<Mat>::type, &value, readOnly,
|
2012-02-15 22:10:11 +01:00
|
|
|
(Algorithm::Getter)getter, (Algorithm::Setter)setter, help);
|
|
|
|
}
|
2012-04-13 23:50:59 +02:00
|
|
|
|
2012-06-09 17:00:04 +02:00
|
|
|
void AlgorithmInfo::addParam(Algorithm& algo, const char* parameter,
|
2013-02-24 17:14:01 +01:00
|
|
|
std::vector<Mat>& value, bool readOnly,
|
|
|
|
std::vector<Mat> (Algorithm::*getter)(),
|
|
|
|
void (Algorithm::*setter)(const std::vector<Mat>&),
|
2013-03-22 17:37:49 +01:00
|
|
|
const String& help)
|
2012-04-13 23:50:59 +02:00
|
|
|
{
|
2013-02-24 17:14:01 +01:00
|
|
|
addParam_(algo, parameter, ParamType<std::vector<Mat> >::type, &value, readOnly,
|
2012-04-13 23:50:59 +02:00
|
|
|
(Algorithm::Getter)getter, (Algorithm::Setter)setter, help);
|
2012-06-09 17:00:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void AlgorithmInfo::addParam(Algorithm& algo, const char* parameter,
|
|
|
|
Ptr<Algorithm>& value, bool readOnly,
|
2012-02-15 22:10:11 +01:00
|
|
|
Ptr<Algorithm> (Algorithm::*getter)(),
|
|
|
|
void (Algorithm::*setter)(const Ptr<Algorithm>&),
|
2013-03-22 17:37:49 +01:00
|
|
|
const String& help)
|
2012-02-15 22:10:11 +01:00
|
|
|
{
|
2012-06-09 17:00:04 +02:00
|
|
|
addParam_(algo, parameter, ParamType<Algorithm>::type, &value, readOnly,
|
2012-02-15 22:10:11 +01:00
|
|
|
(Algorithm::Getter)getter, (Algorithm::Setter)setter, help);
|
2012-06-09 17:00:04 +02:00
|
|
|
}
|
2012-01-24 21:14:07 +01:00
|
|
|
|
2013-02-04 17:25:18 +01:00
|
|
|
void AlgorithmInfo::addParam(Algorithm& algo, const char* parameter,
|
|
|
|
float& value, bool readOnly,
|
|
|
|
float (Algorithm::*getter)(),
|
|
|
|
void (Algorithm::*setter)(float),
|
2013-03-22 17:37:49 +01:00
|
|
|
const String& help)
|
2013-02-04 17:25:18 +01:00
|
|
|
{
|
|
|
|
addParam_(algo, parameter, ParamType<float>::type, &value, readOnly,
|
|
|
|
(Algorithm::Getter)getter, (Algorithm::Setter)setter, help);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AlgorithmInfo::addParam(Algorithm& algo, const char* parameter,
|
|
|
|
unsigned int& value, bool readOnly,
|
|
|
|
unsigned int (Algorithm::*getter)(),
|
|
|
|
void (Algorithm::*setter)(unsigned int),
|
2013-03-22 17:37:49 +01:00
|
|
|
const String& help)
|
2013-02-04 17:25:18 +01:00
|
|
|
{
|
|
|
|
addParam_(algo, parameter, ParamType<unsigned int>::type, &value, readOnly,
|
|
|
|
(Algorithm::Getter)getter, (Algorithm::Setter)setter, help);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AlgorithmInfo::addParam(Algorithm& algo, const char* parameter,
|
|
|
|
uint64& value, bool readOnly,
|
|
|
|
uint64 (Algorithm::*getter)(),
|
|
|
|
void (Algorithm::*setter)(uint64),
|
2013-03-22 17:37:49 +01:00
|
|
|
const String& help)
|
2013-02-04 17:25:18 +01:00
|
|
|
{
|
|
|
|
addParam_(algo, parameter, ParamType<uint64>::type, &value, readOnly,
|
|
|
|
(Algorithm::Getter)getter, (Algorithm::Setter)setter, help);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AlgorithmInfo::addParam(Algorithm& algo, const char* parameter,
|
|
|
|
uchar& value, bool readOnly,
|
|
|
|
uchar (Algorithm::*getter)(),
|
|
|
|
void (Algorithm::*setter)(uchar),
|
2013-03-22 17:37:49 +01:00
|
|
|
const String& help)
|
2013-02-04 17:25:18 +01:00
|
|
|
{
|
|
|
|
addParam_(algo, parameter, ParamType<uchar>::type, &value, readOnly,
|
|
|
|
(Algorithm::Getter)getter, (Algorithm::Setter)setter, help);
|
|
|
|
}
|
|
|
|
|
2012-01-24 21:14:07 +01:00
|
|
|
}
|
2012-06-09 17:00:04 +02:00
|
|
|
|
2012-01-24 21:14:07 +01:00
|
|
|
/* End of file. */
|