fixed canny test; fixed mhi-global test & implementation (hopefully, for the last time); added sse 4.1 & 4.2 support (not working in Xcode for some reason); moved splineInterpolation to color.cpp; fixed a few bugs in documentation
This commit is contained in:
@@ -3206,41 +3206,7 @@ partition( const vector<_Tp>& _vec, vector<int>& labels,
|
||||
return nclasses;
|
||||
}
|
||||
|
||||
// computes cubic spline coefficients for a function: (xi=i, yi=f[i]), i=0..n
|
||||
template<typename _Tp> static void splineBuild(const _Tp* f, int n, _Tp* tab)
|
||||
{
|
||||
_Tp cn = 0;
|
||||
int i;
|
||||
tab[0] = tab[1] = (_Tp)0;
|
||||
|
||||
for(i = 1; i < n-1; i++)
|
||||
{
|
||||
_Tp t = 3*(f[i+1] - 2*f[i] + f[i-1]);
|
||||
_Tp l = 1/(4 - tab[(i-1)*4]);
|
||||
tab[i*4] = l; tab[i*4+1] = (t - tab[(i-1)*4+1])*l;
|
||||
}
|
||||
|
||||
for(i = n-1; i >= 0; i--)
|
||||
{
|
||||
_Tp c = tab[i*4+1] - tab[i*4]*cn;
|
||||
_Tp b = f[i+1] - f[i] - (cn + c*2)*(_Tp)0.3333333333333333;
|
||||
_Tp d = (cn - c)*(_Tp)0.3333333333333333;
|
||||
tab[i*4] = f[i]; tab[i*4+1] = b;
|
||||
tab[i*4+2] = c; tab[i*4+3] = d;
|
||||
cn = c;
|
||||
}
|
||||
}
|
||||
|
||||
// interpolates value of a function at x, 0 <= x <= n using a cubic spline.
|
||||
template<typename _Tp> static inline _Tp splineInterpolate(_Tp x, const _Tp* tab, int n)
|
||||
{
|
||||
int ix = cvFloor(x);
|
||||
ix = std::min(std::max(ix, 0), n-1);
|
||||
x -= ix;
|
||||
tab += ix*4;
|
||||
return ((tab[3]*x + tab[2])*x + tab[1])*x + tab[0];
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// bridge C++ => C Seq API
|
||||
|
||||
@@ -94,6 +94,42 @@
|
||||
|
||||
namespace cv
|
||||
{
|
||||
|
||||
// computes cubic spline coefficients for a function: (xi=i, yi=f[i]), i=0..n
|
||||
template<typename _Tp> static void splineBuild(const _Tp* f, int n, _Tp* tab)
|
||||
{
|
||||
_Tp cn = 0;
|
||||
int i;
|
||||
tab[0] = tab[1] = (_Tp)0;
|
||||
|
||||
for(i = 1; i < n-1; i++)
|
||||
{
|
||||
_Tp t = 3*(f[i+1] - 2*f[i] + f[i-1]);
|
||||
_Tp l = 1/(4 - tab[(i-1)*4]);
|
||||
tab[i*4] = l; tab[i*4+1] = (t - tab[(i-1)*4+1])*l;
|
||||
}
|
||||
|
||||
for(i = n-1; i >= 0; i--)
|
||||
{
|
||||
_Tp c = tab[i*4+1] - tab[i*4]*cn;
|
||||
_Tp b = f[i+1] - f[i] - (cn + c*2)*(_Tp)0.3333333333333333;
|
||||
_Tp d = (cn - c)*(_Tp)0.3333333333333333;
|
||||
tab[i*4] = f[i]; tab[i*4+1] = b;
|
||||
tab[i*4+2] = c; tab[i*4+3] = d;
|
||||
cn = c;
|
||||
}
|
||||
}
|
||||
|
||||
// interpolates value of a function at x, 0 <= x <= n using a cubic spline.
|
||||
template<typename _Tp> static inline _Tp splineInterpolate(_Tp x, const _Tp* tab, int n)
|
||||
{
|
||||
int ix = cvFloor(x);
|
||||
ix = std::min(std::max(ix, 0), n-1);
|
||||
x -= ix;
|
||||
tab += ix*4;
|
||||
return ((tab[3]*x + tab[2])*x + tab[1])*x + tab[0];
|
||||
}
|
||||
|
||||
|
||||
template<typename _Tp> struct ColorChannel
|
||||
{
|
||||
|
||||
@@ -242,8 +242,8 @@ cvCalcGlobalOrientation( const void* orientation, const void* maskimg, const voi
|
||||
float _ranges[] = { 0, 360 };
|
||||
float* ranges = _ranges;
|
||||
int base_orient;
|
||||
double shift_orient = 0, shift_weight = 0, fbase_orient;
|
||||
double a, b;
|
||||
float shift_orient = 0, shift_weight = 0;
|
||||
float a, b, fbase_orient;
|
||||
float delbound;
|
||||
CvMat mhi_row, mask_row, orient_row;
|
||||
int x, y, mhi_rows, mhi_cols;
|
||||
@@ -271,15 +271,14 @@ cvCalcGlobalOrientation( const void* orientation, const void* maskimg, const voi
|
||||
|
||||
// find the maximum index (the dominant orientation)
|
||||
cvGetMinMaxHistValue( hist, 0, 0, 0, &base_orient );
|
||||
base_orient = cvRound(base_orient*360./hist_size);
|
||||
fbase_orient = base_orient*360.f/hist_size;
|
||||
|
||||
// override timestamp with the maximum value in MHI
|
||||
cvMinMaxLoc( mhi, 0, &curr_mhi_timestamp, 0, 0, mask );
|
||||
|
||||
// find the shift relative to the dominant orientation as weighted sum of relative angles
|
||||
a = 254. / 255. / mhi_duration;
|
||||
b = 1. - curr_mhi_timestamp * a;
|
||||
fbase_orient = base_orient;
|
||||
a = (float)(254. / 255. / mhi_duration);
|
||||
b = (float)(1. - curr_mhi_timestamp * a);
|
||||
delbound = (float)(curr_mhi_timestamp - mhi_duration);
|
||||
mhi_rows = mhi->rows;
|
||||
mhi_cols = mhi->cols;
|
||||
@@ -319,13 +318,13 @@ cvCalcGlobalOrientation( const void* orientation, const void* maskimg, const voi
|
||||
-> (rel_angle = orient - base_orient) in -360..360.
|
||||
rel_angle is translated to -180..180
|
||||
*/
|
||||
double weight = mhi_row.data.fl[x] * a + b;
|
||||
int rel_angle = cvRound( orient_row.data.fl[x] - fbase_orient );
|
||||
float weight = mhi_row.data.fl[x] * a + b;
|
||||
float rel_angle = orient_row.data.fl[x] - fbase_orient;
|
||||
|
||||
rel_angle += (rel_angle < -180 ? 360 : 0);
|
||||
rel_angle += (rel_angle > 180 ? -360 : 0);
|
||||
|
||||
if( abs(rel_angle) < 45 )
|
||||
if( fabs(rel_angle) < 45 )
|
||||
{
|
||||
shift_orient += weight * rel_angle;
|
||||
shift_weight += weight;
|
||||
@@ -337,11 +336,11 @@ cvCalcGlobalOrientation( const void* orientation, const void* maskimg, const voi
|
||||
if( shift_weight == 0 )
|
||||
shift_weight = 0.01;
|
||||
|
||||
base_orient = base_orient + cvRound( shift_orient / shift_weight );
|
||||
base_orient -= (base_orient < 360 ? 0 : 360);
|
||||
base_orient += (base_orient >= 0 ? 0 : 360);
|
||||
fbase_orient += shift_orient / shift_weight;
|
||||
fbase_orient -= (fbase_orient < 360 ? 0 : 360);
|
||||
fbase_orient += (fbase_orient >= 0 ? 0 : 360);
|
||||
|
||||
return base_orient;
|
||||
return fbase_orient;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user