merged all the latest changes from 2.4 to trunk
This commit is contained in:
@@ -149,17 +149,21 @@ struct CV_EXPORTS AlgorithmInfoData
|
||||
};
|
||||
|
||||
|
||||
static sorted_vector<string, Algorithm::Constructor> alglist;
|
||||
static sorted_vector<string, Algorithm::Constructor>& alglist()
|
||||
{
|
||||
static sorted_vector<string, Algorithm::Constructor> alglist_var;
|
||||
return alglist_var;
|
||||
}
|
||||
|
||||
void Algorithm::getList(vector<string>& algorithms)
|
||||
{
|
||||
alglist.get_keys(algorithms);
|
||||
alglist().get_keys(algorithms);
|
||||
}
|
||||
|
||||
Ptr<Algorithm> Algorithm::_create(const string& name)
|
||||
{
|
||||
Algorithm::Constructor c = 0;
|
||||
if( !alglist.find(name, c) )
|
||||
if( !alglist().find(name, c) )
|
||||
return Ptr<Algorithm>();
|
||||
return c();
|
||||
}
|
||||
@@ -202,6 +206,11 @@ void Algorithm::set(const string& name, const Mat& value)
|
||||
info()->set(this, name.c_str(), ParamType<Mat>::type, &value);
|
||||
}
|
||||
|
||||
void Algorithm::set(const string& name, const vector<Mat>& value)
|
||||
{
|
||||
info()->set(this, name.c_str(), ParamType<vector<Mat> >::type, &value);
|
||||
}
|
||||
|
||||
void Algorithm::set(const string& name, const Ptr<Algorithm>& value)
|
||||
{
|
||||
info()->set(this, name.c_str(), ParamType<Algorithm>::type, &value);
|
||||
@@ -232,6 +241,11 @@ void Algorithm::set(const char* name, const Mat& value)
|
||||
info()->set(this, name, ParamType<Mat>::type, &value);
|
||||
}
|
||||
|
||||
void Algorithm::set(const char* name, const vector<Mat>& value)
|
||||
{
|
||||
info()->set(this, name, ParamType<vector<Mat> >::type, &value);
|
||||
}
|
||||
|
||||
void Algorithm::set(const char* name, const Ptr<Algorithm>& value)
|
||||
{
|
||||
info()->set(this, name, ParamType<Algorithm>::type, &value);
|
||||
@@ -272,7 +286,7 @@ AlgorithmInfo::AlgorithmInfo(const string& _name, Algorithm::Constructor create)
|
||||
{
|
||||
data = new AlgorithmInfoData;
|
||||
data->_name = _name;
|
||||
alglist.add(_name, create);
|
||||
alglist().add(_name, create);
|
||||
}
|
||||
|
||||
AlgorithmInfo::~AlgorithmInfo()
|
||||
@@ -298,6 +312,8 @@ void AlgorithmInfo::write(const Algorithm* algo, FileStorage& fs) const
|
||||
cv::write(fs, pname, algo->get<string>(pname));
|
||||
else if( p.type == Param::MAT )
|
||||
cv::write(fs, pname, algo->get<Mat>(pname));
|
||||
else if( p.type == Param::MAT_VECTOR )
|
||||
cv::write(fs, pname, algo->get<vector<Mat> >(pname));
|
||||
else if( p.type == Param::ALGORITHM )
|
||||
{
|
||||
WriteStructContext ws(fs, pname, CV_NODE_MAP);
|
||||
@@ -317,7 +333,7 @@ void AlgorithmInfo::read(Algorithm* algo, const FileNode& fn) const
|
||||
{
|
||||
const Param& p = data->params.vec[i].second;
|
||||
const string& pname = data->params.vec[i].first;
|
||||
FileNode n = fn[pname];
|
||||
const FileNode n = fn[pname];
|
||||
if( n.empty() )
|
||||
continue;
|
||||
if( p.type == Param::INT )
|
||||
@@ -331,9 +347,15 @@ void AlgorithmInfo::read(Algorithm* algo, const FileNode& fn) const
|
||||
else if( p.type == Param::MAT )
|
||||
{
|
||||
Mat m;
|
||||
cv::read(fn, m);
|
||||
cv::read(n, m);
|
||||
algo->set(pname, m);
|
||||
}
|
||||
else if( p.type == Param::MAT_VECTOR )
|
||||
{
|
||||
vector<Mat> mv;
|
||||
cv::read(n, mv);
|
||||
algo->set(pname, mv);
|
||||
}
|
||||
else if( p.type == Param::ALGORITHM )
|
||||
{
|
||||
Ptr<Algorithm> nestedAlgo = Algorithm::_create((string)n["name"]);
|
||||
@@ -358,6 +380,7 @@ union GetSetParam
|
||||
double (Algorithm::*get_double)() const;
|
||||
string (Algorithm::*get_string)() const;
|
||||
Mat (Algorithm::*get_mat)() const;
|
||||
vector<Mat> (Algorithm::*get_mat_vector)() const;
|
||||
Ptr<Algorithm> (Algorithm::*get_algo)() const;
|
||||
|
||||
void (Algorithm::*set_int)(int);
|
||||
@@ -365,6 +388,7 @@ union GetSetParam
|
||||
void (Algorithm::*set_double)(double);
|
||||
void (Algorithm::*set_string)(const string&);
|
||||
void (Algorithm::*set_mat)(const Mat&);
|
||||
void (Algorithm::*set_mat_vector)(const vector<Mat>&);
|
||||
void (Algorithm::*set_algo)(const Ptr<Algorithm>&);
|
||||
};
|
||||
|
||||
@@ -436,6 +460,16 @@ void AlgorithmInfo::set(Algorithm* algo, const char* name, int argType, const vo
|
||||
else
|
||||
*(Mat*)((uchar*)algo + p->offset) = val;
|
||||
}
|
||||
else if( argType == Param::MAT_VECTOR )
|
||||
{
|
||||
CV_Assert( p->type == Param::MAT_VECTOR );
|
||||
|
||||
const vector<Mat>& val = *(const vector<Mat>*)value;
|
||||
if( p->setter )
|
||||
(algo->*f.set_mat_vector)(val);
|
||||
else
|
||||
*(vector<Mat>*)((uchar*)algo + p->offset) = val;
|
||||
}
|
||||
else if( argType == Param::ALGORITHM )
|
||||
{
|
||||
CV_Assert( p->type == Param::ALGORITHM );
|
||||
@@ -505,6 +539,13 @@ void AlgorithmInfo::get(const Algorithm* algo, const char* name, int argType, vo
|
||||
*(Mat*)value = p->getter ? (algo->*f.get_mat)() :
|
||||
*(Mat*)((uchar*)algo + p->offset);
|
||||
}
|
||||
else if( argType == Param::MAT_VECTOR )
|
||||
{
|
||||
CV_Assert( p->type == Param::MAT_VECTOR );
|
||||
|
||||
*(vector<Mat>*)value = p->getter ? (algo->*f.get_mat_vector)() :
|
||||
*(vector<Mat>*)((uchar*)algo + p->offset);
|
||||
}
|
||||
else if( argType == Param::ALGORITHM )
|
||||
{
|
||||
CV_Assert( p->type == Param::ALGORITHM );
|
||||
@@ -548,7 +589,8 @@ void AlgorithmInfo::addParam_(Algorithm& algo, const char* name, int argType,
|
||||
{
|
||||
CV_Assert( argType == Param::INT || argType == Param::BOOLEAN ||
|
||||
argType == Param::REAL || argType == Param::STRING ||
|
||||
argType == Param::MAT || argType == Param::ALGORITHM );
|
||||
argType == Param::MAT || argType == Param::MAT_VECTOR ||
|
||||
argType == Param::ALGORITHM );
|
||||
data->params.add(string(name), Param(argType, readOnly,
|
||||
(int)((size_t)value - (size_t)(void*)&algo),
|
||||
getter, setter, help));
|
||||
@@ -604,6 +646,16 @@ void AlgorithmInfo::addParam(Algorithm& algo, const char* name,
|
||||
addParam_(algo, name, ParamType<Mat>::type, &value, readOnly,
|
||||
(Algorithm::Getter)getter, (Algorithm::Setter)setter, help);
|
||||
}
|
||||
|
||||
void AlgorithmInfo::addParam(Algorithm& algo, const char* name,
|
||||
vector<Mat>& value, bool readOnly,
|
||||
vector<Mat> (Algorithm::*getter)(),
|
||||
void (Algorithm::*setter)(const vector<Mat>&),
|
||||
const string& help)
|
||||
{
|
||||
addParam_(algo, name, ParamType<vector<Mat> >::type, &value, readOnly,
|
||||
(Algorithm::Getter)getter, (Algorithm::Setter)setter, help);
|
||||
}
|
||||
|
||||
void AlgorithmInfo::addParam(Algorithm& algo, const char* name,
|
||||
Ptr<Algorithm>& value, bool readOnly,
|
||||
|
@@ -47,6 +47,7 @@ namespace cv
|
||||
// On Win64 optimized versions of DFT and DCT fail the tests (fixed in VS2010)
|
||||
#if defined _MSC_VER && !defined CV_ICC && defined _M_X64 && _MSC_VER < 1600
|
||||
#pragma optimize("", off)
|
||||
#pragma warning( disable : 4748 )
|
||||
#endif
|
||||
|
||||
/****************************************************************************************\
|
||||
|
@@ -2032,8 +2032,9 @@ template<> struct mat_type_assotiations<CV_32S>
|
||||
static const type max_allowable = INT_MAX;
|
||||
};
|
||||
|
||||
// inclusive maxVal !!!
|
||||
template<int depth>
|
||||
bool chackIntegerRang(cv::Mat src, Point& bad_pt, int minVal, int maxVal, double& bad_value)
|
||||
bool checkIntegerRange(cv::Mat src, Point& bad_pt, int minVal, int maxVal, double& bad_value)
|
||||
{
|
||||
typedef mat_type_assotiations<depth> type_ass;
|
||||
|
||||
@@ -2041,7 +2042,7 @@ bool chackIntegerRang(cv::Mat src, Point& bad_pt, int minVal, int maxVal, double
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if (minVal >= type_ass::max_allowable || maxVal <= type_ass::min_allowable || maxVal <= minVal)
|
||||
else if (minVal > type_ass::max_allowable || maxVal < type_ass::min_allowable || maxVal < minVal)
|
||||
{
|
||||
bad_pt = cv::Point(0,0);
|
||||
return false;
|
||||
@@ -2051,7 +2052,7 @@ bool chackIntegerRang(cv::Mat src, Point& bad_pt, int minVal, int maxVal, double
|
||||
for (int j = 0; j < as_one_channel.rows; ++j)
|
||||
for (int i = 0; i < as_one_channel.cols; ++i)
|
||||
{
|
||||
if (as_one_channel.at<typename type_ass::type>(j ,i) <= minVal || as_one_channel.at<typename type_ass::type>(j ,i) >= maxVal)
|
||||
if (as_one_channel.at<typename type_ass::type>(j ,i) < minVal || as_one_channel.at<typename type_ass::type>(j ,i) > maxVal)
|
||||
{
|
||||
bad_pt.y = j ;
|
||||
bad_pt.x = i % src.channels();
|
||||
@@ -2064,15 +2065,15 @@ bool chackIntegerRang(cv::Mat src, Point& bad_pt, int minVal, int maxVal, double
|
||||
return true;
|
||||
}
|
||||
|
||||
typedef bool (*check_pange_function)(cv::Mat src, Point& bad_pt, int minVal, int maxVal, double& bad_value);
|
||||
typedef bool (*check_range_function)(cv::Mat src, Point& bad_pt, int minVal, int maxVal, double& bad_value);
|
||||
|
||||
check_pange_function check_range_functions[] =
|
||||
check_range_function check_range_functions[] =
|
||||
{
|
||||
&chackIntegerRang<CV_8U>,
|
||||
&chackIntegerRang<CV_8S>,
|
||||
&chackIntegerRang<CV_16U>,
|
||||
&chackIntegerRang<CV_16S>,
|
||||
&chackIntegerRang<CV_32S>
|
||||
&checkIntegerRange<CV_8U>,
|
||||
&checkIntegerRange<CV_8S>,
|
||||
&checkIntegerRange<CV_16U>,
|
||||
&checkIntegerRange<CV_16S>,
|
||||
&checkIntegerRange<CV_32S>
|
||||
};
|
||||
|
||||
bool checkRange(InputArray _src, bool quiet, Point* pt, double minVal, double maxVal)
|
||||
@@ -2102,8 +2103,9 @@ bool checkRange(InputArray _src, bool quiet, Point* pt, double minVal, double ma
|
||||
|
||||
if (depth < CV_32F)
|
||||
{
|
||||
int minVali = cvFloor(minVal);
|
||||
int maxVali = cvCeil(maxVal);
|
||||
// see "Bug #1784"
|
||||
int minVali = minVal<(-INT_MAX - 1) ? (-INT_MAX - 1) : cvFloor(minVal);
|
||||
int maxVali = maxVal>INT_MAX ? INT_MAX : cvCeil(maxVal) - 1; // checkIntegerRang() use inclusive maxVal
|
||||
|
||||
(check_range_functions[depth])(src, badPt, minVali, maxVali, badValue);
|
||||
}
|
||||
@@ -2487,7 +2489,7 @@ double cv::solvePoly( InputArray _coeffs0, OutputArray _roots0, int maxIters )
|
||||
for( i = 0; i < n; i++ )
|
||||
{
|
||||
p = roots[i];
|
||||
C num = coeffs[n], denom = 1;
|
||||
C num = coeffs[n], denom = coeffs[n];
|
||||
for( j = 0; j < n; j++ )
|
||||
{
|
||||
num = num*p + coeffs[n-j-1];
|
||||
|
@@ -2098,7 +2098,7 @@ void cv::calcCovarMatrix( const Mat* data, int nsamples, Mat& covar, Mat& _mean,
|
||||
{
|
||||
CV_Assert( data && nsamples > 0 );
|
||||
Size size = data[0].size();
|
||||
int sz = size.width*size.height, esz = (int)data[0].elemSize();
|
||||
int sz = size.width * size.height, esz = (int)data[0].elemSize();
|
||||
int type = data[0].type();
|
||||
Mat mean;
|
||||
ctype = std::max(std::max(CV_MAT_DEPTH(ctype >= 0 ? ctype : type), _mean.depth()), CV_32F);
|
||||
@@ -2116,6 +2116,7 @@ void cv::calcCovarMatrix( const Mat* data, int nsamples, Mat& covar, Mat& _mean,
|
||||
}
|
||||
|
||||
Mat _data(nsamples, sz, type);
|
||||
|
||||
for( int i = 0; i < nsamples; i++ )
|
||||
{
|
||||
CV_Assert( data[i].size() == size && data[i].type() == type );
|
||||
@@ -2135,6 +2136,55 @@ void cv::calcCovarMatrix( const Mat* data, int nsamples, Mat& covar, Mat& _mean,
|
||||
|
||||
void cv::calcCovarMatrix( InputArray _data, OutputArray _covar, InputOutputArray _mean, int flags, int ctype )
|
||||
{
|
||||
if(_data.kind() == _InputArray::STD_VECTOR_MAT)
|
||||
{
|
||||
std::vector<cv::Mat> src;
|
||||
_data.getMatVector(src);
|
||||
|
||||
CV_Assert( src.size() > 0 );
|
||||
|
||||
Size size = src[0].size();
|
||||
int type = src[0].type();
|
||||
|
||||
ctype = std::max(std::max(CV_MAT_DEPTH(ctype >= 0 ? ctype : type), _mean.depth()), CV_32F);
|
||||
|
||||
Mat _data(static_cast<int>(src.size()), size.area(), type);
|
||||
|
||||
int i = 0;
|
||||
for(vector<cv::Mat>::iterator each = src.begin(); each != src.end(); each++, i++ )
|
||||
{
|
||||
CV_Assert( (*each).size() == size && (*each).type() == type );
|
||||
Mat dataRow(size.height, size.width, type, _data.ptr(i));
|
||||
(*each).copyTo(dataRow);
|
||||
}
|
||||
|
||||
Mat mean;
|
||||
if( (flags & CV_COVAR_USE_AVG) != 0 )
|
||||
{
|
||||
CV_Assert( _mean.size() == size );
|
||||
|
||||
if( mean.type() != ctype )
|
||||
{
|
||||
mean = _mean.getMat();
|
||||
_mean.create(mean.size(), ctype);
|
||||
Mat tmp = _mean.getMat();
|
||||
mean.convertTo(tmp, ctype);
|
||||
mean = tmp;
|
||||
}
|
||||
|
||||
mean = _mean.getMat().reshape(1, 1);
|
||||
}
|
||||
|
||||
calcCovarMatrix( _data, _covar, mean, (flags & ~(CV_COVAR_ROWS|CV_COVAR_COLS)) | CV_COVAR_ROWS, ctype );
|
||||
|
||||
if( (flags & CV_COVAR_USE_AVG) == 0 )
|
||||
{
|
||||
mean = mean.reshape(1, size.height);
|
||||
mean.copyTo(_mean);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
Mat data = _data.getMat(), mean;
|
||||
CV_Assert( ((flags & CV_COVAR_ROWS) != 0) ^ ((flags & CV_COVAR_COLS) != 0) );
|
||||
bool takeRows = (flags & CV_COVAR_ROWS) != 0;
|
||||
|
@@ -262,10 +262,9 @@ void Mat::deallocate()
|
||||
}
|
||||
|
||||
|
||||
Mat::Mat(const Mat& m, const Range& rowRange, const Range& colRange)
|
||||
: flags(0), dims(0), rows(0), cols(0), data(0), refcount(0),
|
||||
datastart(0), dataend(0), datalimit(0), allocator(0), size(&rows)
|
||||
Mat::Mat(const Mat& m, const Range& rowRange, const Range& colRange) : size(&rows)
|
||||
{
|
||||
initEmpty();
|
||||
CV_Assert( m.dims >= 2 );
|
||||
if( m.dims > 2 )
|
||||
{
|
||||
@@ -336,21 +335,19 @@ Mat::Mat(const Mat& m, const Rect& roi)
|
||||
}
|
||||
|
||||
|
||||
Mat::Mat(int _dims, const int* _sizes, int _type, void* _data, const size_t* _steps)
|
||||
: flags(MAGIC_VAL|CV_MAT_TYPE(_type)), dims(0),
|
||||
rows(0), cols(0), data((uchar*)_data), refcount(0),
|
||||
datastart((uchar*)_data), dataend((uchar*)_data), datalimit((uchar*)_data),
|
||||
allocator(0), size(&rows)
|
||||
Mat::Mat(int _dims, const int* _sizes, int _type, void* _data, const size_t* _steps) : size(&rows)
|
||||
{
|
||||
initEmpty();
|
||||
flags |= CV_MAT_TYPE(_type);
|
||||
data = datastart = (uchar*)_data;
|
||||
setSize(*this, _dims, _sizes, _steps, true);
|
||||
finalizeHdr(*this);
|
||||
}
|
||||
|
||||
|
||||
Mat::Mat(const Mat& m, const Range* ranges)
|
||||
: flags(m.flags), dims(0), rows(0), cols(0), data(0), refcount(0),
|
||||
datastart(0), dataend(0), datalimit(0), allocator(0), size(&rows)
|
||||
Mat::Mat(const Mat& m, const Range* ranges) : size(&rows)
|
||||
{
|
||||
initEmpty();
|
||||
int i, d = m.dims;
|
||||
|
||||
CV_Assert(ranges);
|
||||
@@ -374,12 +371,13 @@ Mat::Mat(const Mat& m, const Range* ranges)
|
||||
}
|
||||
|
||||
|
||||
Mat::Mat(const CvMatND* m, bool copyData)
|
||||
: flags(MAGIC_VAL|CV_MAT_TYPE(m->type)), dims(0), rows(0), cols(0),
|
||||
data((uchar*)m->data.ptr), refcount(0),
|
||||
datastart((uchar*)m->data.ptr), allocator(0),
|
||||
size(&rows)
|
||||
Mat::Mat(const CvMatND* m, bool copyData) : size(&rows)
|
||||
{
|
||||
initEmpty();
|
||||
if( !m )
|
||||
return;
|
||||
data = datastart = m->data.ptr;
|
||||
flags |= CV_MAT_TYPE(m->type);
|
||||
int _sizes[CV_MAX_DIM];
|
||||
size_t _steps[CV_MAX_DIM];
|
||||
|
||||
@@ -434,12 +432,45 @@ Mat Mat::diag(int d) const
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Mat::Mat(const IplImage* img, bool copyData)
|
||||
: flags(MAGIC_VAL), dims(2), rows(0), cols(0),
|
||||
data(0), refcount(0), datastart(0), dataend(0), allocator(0), size(&rows)
|
||||
Mat::Mat(const CvMat* m, bool copyData) : size(&rows)
|
||||
{
|
||||
initEmpty();
|
||||
|
||||
if( !m )
|
||||
return;
|
||||
|
||||
if( !copyData )
|
||||
{
|
||||
flags = MAGIC_VAL + (m->type & (CV_MAT_TYPE_MASK|CV_MAT_CONT_FLAG));
|
||||
dims = 2;
|
||||
rows = m->rows;
|
||||
cols = m->cols;
|
||||
data = datastart = m->data.ptr;
|
||||
size_t esz = CV_ELEM_SIZE(m->type), minstep = cols*esz, _step = m->step;
|
||||
if( _step == 0 )
|
||||
_step = minstep;
|
||||
datalimit = datastart + _step*rows;
|
||||
dataend = datalimit - _step + minstep;
|
||||
step[0] = _step; step[1] = esz;
|
||||
}
|
||||
else
|
||||
{
|
||||
data = datastart = dataend = 0;
|
||||
Mat(m->rows, m->cols, m->type, m->data.ptr, m->step).copyTo(*this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Mat::Mat(const IplImage* img, bool copyData) : size(&rows)
|
||||
{
|
||||
initEmpty();
|
||||
|
||||
if( !img )
|
||||
return;
|
||||
|
||||
dims = 2;
|
||||
CV_DbgAssert(CV_IS_IMAGE(img) && img->imageData != 0);
|
||||
|
||||
int depth = IPL2CV_DEPTH(img->depth);
|
||||
@@ -2428,8 +2459,9 @@ double cv::kmeans( InputArray _data, int K,
|
||||
{
|
||||
const int SPP_TRIALS = 3;
|
||||
Mat data = _data.getMat();
|
||||
int N = data.rows > 1 ? data.rows : data.cols;
|
||||
int dims = (data.rows > 1 ? data.cols : 1)*data.channels();
|
||||
bool isrow = data.rows == 1 && data.channels() > 1;
|
||||
int N = !isrow ? data.rows : data.cols;
|
||||
int dims = (!isrow ? data.cols : 1)*data.channels();
|
||||
int type = data.depth();
|
||||
|
||||
attempts = std::max(attempts, 1);
|
||||
@@ -2458,7 +2490,7 @@ double cv::kmeans( InputArray _data, int K,
|
||||
}
|
||||
int* labels = _labels.ptr<int>();
|
||||
|
||||
Mat centers(K, dims, type), old_centers(K, dims, type);
|
||||
Mat centers(K, dims, type), old_centers(K, dims, type), temp(1, dims, type);
|
||||
vector<int> counters(K);
|
||||
vector<Vec2f> _box(dims);
|
||||
Vec2f* box = &_box[0];
|
||||
@@ -2502,7 +2534,7 @@ double cv::kmeans( InputArray _data, int K,
|
||||
for( a = 0; a < attempts; a++ )
|
||||
{
|
||||
double max_center_shift = DBL_MAX;
|
||||
for( iter = 0; iter < criteria.maxCount && max_center_shift > criteria.epsilon; iter++ )
|
||||
for( iter = 0;; )
|
||||
{
|
||||
swap(centers, old_centers);
|
||||
|
||||
@@ -2579,13 +2611,17 @@ double cv::kmeans( InputArray _data, int K,
|
||||
int farthest_i = -1;
|
||||
float* new_center = centers.ptr<float>(k);
|
||||
float* old_center = centers.ptr<float>(max_k);
|
||||
float* _old_center = temp.ptr<float>(); // normalized
|
||||
float scale = 1.f/counters[max_k];
|
||||
for( j = 0; j < dims; j++ )
|
||||
_old_center[j] = old_center[j]*scale;
|
||||
|
||||
for( i = 0; i < N; i++ )
|
||||
{
|
||||
if( labels[i] != max_k )
|
||||
continue;
|
||||
sample = data.ptr<float>(i);
|
||||
double dist = normL2Sqr_(sample, old_center, dims);
|
||||
double dist = normL2Sqr_(sample, _old_center, dims);
|
||||
|
||||
if( max_dist <= dist )
|
||||
{
|
||||
@@ -2596,6 +2632,7 @@ double cv::kmeans( InputArray _data, int K,
|
||||
|
||||
counters[max_k]--;
|
||||
counters[k]++;
|
||||
labels[farthest_i] = k;
|
||||
sample = data.ptr<float>(farthest_i);
|
||||
|
||||
for( j = 0; j < dims; j++ )
|
||||
@@ -2627,6 +2664,9 @@ double cv::kmeans( InputArray _data, int K,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( ++iter == MAX(criteria.maxCount, 2) || max_center_shift <= criteria.epsilon )
|
||||
break;
|
||||
|
||||
// assign labels
|
||||
compactness = 0;
|
||||
|
@@ -2987,9 +2987,6 @@ cvWriteRawData( CvFileStorage* fs, const void* _data, int len, const char* dt )
|
||||
|
||||
CV_CHECK_OUTPUT_FILE_STORAGE( fs );
|
||||
|
||||
if( !data0 )
|
||||
CV_Error( CV_StsNullPtr, "Null data pointer" );
|
||||
|
||||
if( len < 0 )
|
||||
CV_Error( CV_StsOutOfRange, "Negative number of elements" );
|
||||
|
||||
@@ -2997,6 +2994,9 @@ cvWriteRawData( CvFileStorage* fs, const void* _data, int len, const char* dt )
|
||||
|
||||
if( !len )
|
||||
return;
|
||||
|
||||
if( !data0 )
|
||||
CV_Error( CV_StsNullPtr, "Null data pointer" );
|
||||
|
||||
if( fmt_pair_count == 1 )
|
||||
{
|
||||
@@ -3457,6 +3457,8 @@ icvReadMat( CvFileStorage* fs, CvFileNode* node )
|
||||
mat = cvCreateMat( rows, cols, elem_type );
|
||||
cvReadRawData( fs, data, mat->data.ptr, dt );
|
||||
}
|
||||
else if( rows == 0 && cols == 0 )
|
||||
mat = cvCreateMatHeader( 0, 1, elem_type );
|
||||
else
|
||||
mat = cvCreateMatHeader( rows, cols, elem_type );
|
||||
|
||||
@@ -5195,7 +5197,7 @@ FileNodeIterator::FileNodeIterator()
|
||||
FileNodeIterator::FileNodeIterator(const CvFileStorage* _fs,
|
||||
const CvFileNode* _node, size_t _ofs)
|
||||
{
|
||||
if( _fs && _node )
|
||||
if( _fs && _node && CV_NODE_TYPE(_node->tag) != CV_NODE_NONE )
|
||||
{
|
||||
int node_type = _node->tag & FileNode::TYPE_MASK;
|
||||
fs = _fs;
|
||||
@@ -5358,7 +5360,7 @@ void write( FileStorage& fs, const string& name, const SparseMat& value )
|
||||
Ptr<CvSparseMat> mat = (CvSparseMat*)value;
|
||||
cvWrite( *fs, name.size() ? name.c_str() : 0, mat );
|
||||
}
|
||||
|
||||
|
||||
|
||||
WriteStructContext::WriteStructContext(FileStorage& _fs, const string& name,
|
||||
int flags, const string& typeName) : fs(&_fs)
|
||||
|
@@ -1605,25 +1605,20 @@ struct BatchDistInvoker
|
||||
// we handle both CV_32S and CV_32F cases with a single branch
|
||||
int* distptr = (int*)dist->ptr(i);
|
||||
|
||||
int k, k0, k0_, j;
|
||||
for( k0 = 0; k0 < K; k0++ )
|
||||
if( nidxptr[k0] < 0 )
|
||||
break;
|
||||
k0_ = std::max(k0, 1);
|
||||
int j, k;
|
||||
|
||||
for( j = 0; j < src2->rows; j++ )
|
||||
{
|
||||
int d = bufptr[j];
|
||||
if( d < distptr[k0_-1] )
|
||||
if( d < distptr[K-1] )
|
||||
{
|
||||
for( k = std::min(k0-1, K-2); k >= 0 && distptr[k] > d; k-- )
|
||||
for( k = K-2; k >= 0 && distptr[k] > d; k-- )
|
||||
{
|
||||
nidxptr[k+1] = nidxptr[k];
|
||||
distptr[k+1] = distptr[k];
|
||||
}
|
||||
nidxptr[k+1] = j + update;
|
||||
distptr[k+1] = d;
|
||||
k0_ = k0 = std::min(k0 + 1, K);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -374,6 +374,46 @@ int getThreadNum(void)
|
||||
#endif
|
||||
}
|
||||
|
||||
#if ANDROID
|
||||
static inline int getNumberOfCPUsImpl()
|
||||
{
|
||||
FILE* cpuPossible = fopen("/sys/devices/system/cpu/possible", "r");
|
||||
if(!cpuPossible)
|
||||
return 1;
|
||||
|
||||
char buf[2000]; //big enough for 1000 CPUs in worst possible configuration
|
||||
char* pbuf = fgets(buf, sizeof(buf), cpuPossible);
|
||||
fclose(cpuPossible);
|
||||
if(!pbuf)
|
||||
return 1;
|
||||
|
||||
//parse string of form "0-1,3,5-7,10,13-15"
|
||||
int cpusAvailable = 0;
|
||||
|
||||
while(*pbuf)
|
||||
{
|
||||
const char* pos = pbuf;
|
||||
bool range = false;
|
||||
while(*pbuf && *pbuf != ',')
|
||||
{
|
||||
if(*pbuf == '-') range = true;
|
||||
++pbuf;
|
||||
}
|
||||
if(*pbuf) *pbuf++ = 0;
|
||||
if(!range)
|
||||
++cpusAvailable;
|
||||
else
|
||||
{
|
||||
int rstart = 0, rend = 0;
|
||||
sscanf(pos, "%d-%d", &rstart, &rend);
|
||||
cpusAvailable += rend - rstart + 1;
|
||||
}
|
||||
|
||||
}
|
||||
return cpusAvailable ? cpusAvailable : 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
int getNumberOfCPUs(void)
|
||||
{
|
||||
#if defined WIN32 || defined _WIN32
|
||||
@@ -381,6 +421,10 @@ int getNumberOfCPUs(void)
|
||||
GetSystemInfo( &sysinfo );
|
||||
|
||||
return (int)sysinfo.dwNumberOfProcessors;
|
||||
#elif ANDROID
|
||||
static int ncpus = getNumberOfCPUsImpl();
|
||||
printf("CPUS= %d\n", ncpus);
|
||||
return ncpus;
|
||||
#elif defined __linux__
|
||||
return (int)sysconf( _SC_NPROCESSORS_ONLN );
|
||||
#elif defined __APPLE__
|
||||
@@ -410,6 +454,14 @@ int getNumberOfCPUs(void)
|
||||
#endif
|
||||
}
|
||||
|
||||
const std::string& getBuildInformation()
|
||||
{
|
||||
static std::string build_info =
|
||||
#include "version_string.inc"
|
||||
;
|
||||
return build_info;
|
||||
}
|
||||
|
||||
string format( const char* fmt, ... )
|
||||
{
|
||||
char buf[1 << 16];
|
||||
|
Reference in New Issue
Block a user