Commit 65d01574 authored by Vladislav Samsonov's avatar Vladislav Samsonov

Some improvements

parent 25b2958e
......@@ -47,6 +47,123 @@ namespace cv
{
namespace optflow
{
/*
class PCAFlowBasis
{
public:
Size size;
PCAFlowBasis( Size basisSize = Size( 0, 0 ) ) : size( basisSize ) {}
virtual ~PCAFlowBasis(){};
virtual int getNumberOfComponents() const = 0;
virtual void getBasisAtPoint( const Point2f &p, const Size &maxSize, float *outX, float *outY ) const = 0;
virtual Point2f reduceAtPoint( const Point2f &p, const Size &maxSize, const float *w1, const float *w2 ) const = 0;
};*/
/*
* Orthogonal basis from Discrete Cosine Transform.
* Can be used without any learning or assumptions about flow structure for general purpose.
* Gives low quality estimation.
*/
/*class PCAFlowGeneralBasis : public PCAFlowBasis
{
public:
PCAFlowGeneralBasis( Size basisSize = Size( 18, 14 ) ) : PCAFlowBasis( basisSize ) {}
int getNumberOfComponents() const { return size.area(); }
void getBasisAtPoint( const Point2f &p, const Size &maxSize, float *outX, float *outY ) const
{
for ( int n1 = 0; n1 < size.width; ++n1 )
for ( int n2 = 0; n2 < size.height; ++n2 )
outX[n1 * size.height + n2] =
cosf( ( n1 * M_PI / maxSize.width ) * ( p.x + 0.5 ) ) * cosf( ( n2 * M_PI / maxSize.height ) * ( p.y + 0.5 )
);
memcpy( outY, outX, getNumberOfComponents() * sizeof( *outY ) );
}
Point2f reduceAtPoint( const Point2f &p, const Size &maxSize, const float *w1, const float *w2 ) const
{
Point2f res( 0, 0 );
for ( int n1 = 0; n1 < size.width; ++n1 )
for ( int n2 = 0; n2 < size.height; ++n2 )
{
const float c =
cosf( ( n1 * M_PI / maxSize.width ) * ( p.x + 0.5 ) ) * cosf( ( n2 * M_PI / maxSize.height ) * ( p.y + 0.5 )
);
res.x += c * w1[n1 * size.height + n2];
res.y += c * w2[n1 * size.height + n2];
}
return res;
}
};*/
/*
class PCAFlowLearnedBasis : public PCAFlowBasis
{
private:
float *basisData;
unsigned numberOfComponents;
public:
PCAFlowLearnedBasis( const char *filename )
{
basisData = 0;
FILE *f = fopen( filename, "r" );
CV_Assert( f );
numberOfComponents = 0;
CV_Assert( fread( &numberOfComponents, sizeof( numberOfComponents ), 1, f ) == 1 );
CV_Assert( fread( &size.height, sizeof( size.height ), 1, f ) == 1 );
CV_Assert( fread( &size.width, sizeof( size.width ), 1, f ) == 1 );
CV_Assert( ( numberOfComponents > 0 ) && ( numberOfComponents % 2 == 0 ) );
basisData = new float[size.width * size.height * numberOfComponents];
CV_Assert( fread( basisData, size.width * size.height * sizeof( *basisData ), numberOfComponents, f ) ==
numberOfComponents );
fclose( f );
numberOfComponents /= 2;
}
~PCAFlowLearnedBasis()
{
if ( basisData )
delete[] basisData;
}
int getNumberOfComponents() const { return numberOfComponents; }
void getBasisAtPoint( const Point2f &p, const Size &maxSize, float *outX, float *outY ) const
{
const size_t chunk = size.width * size.height;
size_t offset = size_t( p.y * float(size.height) / maxSize.height ) * size.width + size_t( p.x * float(size.width) /
maxSize.width );
for ( unsigned i = 0; i < numberOfComponents; ++i )
outX[i] = basisData[i * chunk + offset];
offset += numberOfComponents * chunk;
for ( unsigned i = 0; i < numberOfComponents; ++i )
outY[i] = basisData[i * chunk + offset];
}
Point2f reduceAtPoint( const Point2f &p, const Size &maxSize, const float *w1, const float *w2 ) const
{
Point2f res( 0, 0 );
const size_t chunk = size.width * size.height;
const size_t offset = size_t( p.y * float(size.height) / maxSize.height ) * size.width + size_t( p.x *
float(size.width) / maxSize.width );
for ( unsigned i = 0; i < numberOfComponents; ++i )
{
const float c = basisData[i * chunk + offset];
res.x += c * w1[i];
res.y += c * w2[i];
}
return res;
}
};*/
class OpticalFlowPCAFlow : public DenseOpticalFlow
{
......@@ -57,8 +174,8 @@ protected:
const float occlusionsThreshold;
public:
OpticalFlowPCAFlow( Size _basisSize = Size( 18, 14 ), float _sparseRate = 0.02, float _retainedCornersFraction = 1.0,
float _occlusionsThreshold = 0.00002 );
OpticalFlowPCAFlow( const Size _basisSize = Size( 18, 14 ), float _sparseRate = 0.02,
float _retainedCornersFraction = 1.0, float _occlusionsThreshold = 0.00002 );
void calc( InputArray I0, InputArray I1, InputOutputArray flow );
void collectGarbage();
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment