lot's of changes; nonfree & photo modules added; SIFT & SURF -> nonfree module; Inpainting -> photo; refactored features2d (ORB is still failing tests), optimized brute-force matcher and made it non-template.
This commit is contained in:
@@ -77,11 +77,11 @@ void DescriptorExtractor::compute( const vector<Mat>& imageCollection, vector<ve
|
||||
compute( imageCollection[i], pointCollection[i], descCollection[i] );
|
||||
}
|
||||
|
||||
void DescriptorExtractor::read( const FileNode& )
|
||||
/*void DescriptorExtractor::read( const FileNode& )
|
||||
{}
|
||||
|
||||
void DescriptorExtractor::write( FileStorage& ) const
|
||||
{}
|
||||
{}*/
|
||||
|
||||
bool DescriptorExtractor::empty() const
|
||||
{
|
||||
@@ -96,184 +96,16 @@ void DescriptorExtractor::removeBorderKeypoints( vector<KeyPoint>& keypoints,
|
||||
|
||||
Ptr<DescriptorExtractor> DescriptorExtractor::create(const string& descriptorExtractorType)
|
||||
{
|
||||
DescriptorExtractor* de = 0;
|
||||
|
||||
size_t pos = 0;
|
||||
if (!descriptorExtractorType.compare("SIFT"))
|
||||
if( descriptorExtractorType.find("Opponent") == 0)
|
||||
{
|
||||
de = new SiftDescriptorExtractor();
|
||||
size_t pos = string("Opponent").size();
|
||||
return DescriptorExtractor::create(descriptorExtractorType.substr(pos));
|
||||
}
|
||||
else if (!descriptorExtractorType.compare("SURF"))
|
||||
{
|
||||
de = new SurfDescriptorExtractor();
|
||||
}
|
||||
else if (!descriptorExtractorType.compare("ORB"))
|
||||
{
|
||||
de = new OrbDescriptorExtractor();
|
||||
}
|
||||
else if (!descriptorExtractorType.compare("BRIEF"))
|
||||
{
|
||||
de = new BriefDescriptorExtractor();
|
||||
}
|
||||
else if ( (pos=descriptorExtractorType.find("Opponent")) == 0)
|
||||
{
|
||||
pos += string("Opponent").size();
|
||||
de = new OpponentColorDescriptorExtractor( DescriptorExtractor::create(descriptorExtractorType.substr(pos)) );
|
||||
}
|
||||
return de;
|
||||
|
||||
return Algorithm::create<DescriptorExtractor>("Feature2D." + descriptorExtractorType);
|
||||
}
|
||||
|
||||
/****************************************************************************************\
|
||||
* SiftDescriptorExtractor *
|
||||
\****************************************************************************************/
|
||||
SiftDescriptorExtractor::SiftDescriptorExtractor(const SIFT::DescriptorParams& descriptorParams,
|
||||
const SIFT::CommonParams& commonParams)
|
||||
: sift( descriptorParams.magnification, descriptorParams.isNormalize, descriptorParams.recalculateAngles,
|
||||
commonParams.nOctaves, commonParams.nOctaveLayers, commonParams.firstOctave, commonParams.angleMode )
|
||||
{}
|
||||
|
||||
SiftDescriptorExtractor::SiftDescriptorExtractor( double magnification, bool isNormalize, bool recalculateAngles,
|
||||
int nOctaves, int nOctaveLayers, int firstOctave, int angleMode )
|
||||
: sift( magnification, isNormalize, recalculateAngles, nOctaves, nOctaveLayers, firstOctave, angleMode )
|
||||
{}
|
||||
|
||||
void SiftDescriptorExtractor::computeImpl( const Mat& image,
|
||||
vector<KeyPoint>& keypoints,
|
||||
Mat& descriptors) const
|
||||
{
|
||||
bool useProvidedKeypoints = true;
|
||||
Mat grayImage = image;
|
||||
if( image.type() != CV_8U ) cvtColor( image, grayImage, CV_BGR2GRAY );
|
||||
|
||||
sift(grayImage, Mat(), keypoints, descriptors, useProvidedKeypoints);
|
||||
}
|
||||
|
||||
void SiftDescriptorExtractor::read (const FileNode &fn)
|
||||
{
|
||||
double magnification = fn["magnification"];
|
||||
bool isNormalize = (int)fn["isNormalize"] != 0;
|
||||
bool recalculateAngles = (int)fn["recalculateAngles"] != 0;
|
||||
int nOctaves = fn["nOctaves"];
|
||||
int nOctaveLayers = fn["nOctaveLayers"];
|
||||
int firstOctave = fn["firstOctave"];
|
||||
int angleMode = fn["angleMode"];
|
||||
|
||||
sift = SIFT( magnification, isNormalize, recalculateAngles, nOctaves, nOctaveLayers, firstOctave, angleMode );
|
||||
}
|
||||
|
||||
void SiftDescriptorExtractor::write (FileStorage &fs) const
|
||||
{
|
||||
// fs << "algorithm" << getAlgorithmName ();
|
||||
|
||||
SIFT::CommonParams commParams = sift.getCommonParams ();
|
||||
SIFT::DescriptorParams descriptorParams = sift.getDescriptorParams ();
|
||||
fs << "magnification" << descriptorParams.magnification;
|
||||
fs << "isNormalize" << descriptorParams.isNormalize;
|
||||
fs << "recalculateAngles" << descriptorParams.recalculateAngles;
|
||||
fs << "nOctaves" << commParams.nOctaves;
|
||||
fs << "nOctaveLayers" << commParams.nOctaveLayers;
|
||||
fs << "firstOctave" << commParams.firstOctave;
|
||||
fs << "angleMode" << commParams.angleMode;
|
||||
}
|
||||
|
||||
int SiftDescriptorExtractor::descriptorSize() const
|
||||
{
|
||||
return sift.descriptorSize();
|
||||
}
|
||||
|
||||
int SiftDescriptorExtractor::descriptorType() const
|
||||
{
|
||||
return CV_32FC1;
|
||||
}
|
||||
|
||||
/****************************************************************************************\
|
||||
* SurfDescriptorExtractor *
|
||||
\****************************************************************************************/
|
||||
SurfDescriptorExtractor::SurfDescriptorExtractor( int nOctaves,
|
||||
int nOctaveLayers, bool extended, bool upright )
|
||||
: surf( 0.0, nOctaves, nOctaveLayers, extended, upright )
|
||||
{}
|
||||
|
||||
void SurfDescriptorExtractor::computeImpl( const Mat& image,
|
||||
vector<KeyPoint>& keypoints,
|
||||
Mat& descriptors) const
|
||||
{
|
||||
// Compute descriptors for given keypoints
|
||||
vector<float> _descriptors;
|
||||
Mat mask;
|
||||
bool useProvidedKeypoints = true;
|
||||
Mat grayImage = image;
|
||||
if( image.type() != CV_8U ) cvtColor( image, grayImage, CV_BGR2GRAY );
|
||||
|
||||
surf(grayImage, mask, keypoints, _descriptors, useProvidedKeypoints);
|
||||
|
||||
descriptors.create((int)keypoints.size(), (int)surf.descriptorSize(), CV_32FC1);
|
||||
assert( (int)_descriptors.size() == descriptors.rows * descriptors.cols );
|
||||
std::copy(_descriptors.begin(), _descriptors.end(), descriptors.begin<float>());
|
||||
}
|
||||
|
||||
void SurfDescriptorExtractor::read( const FileNode &fn )
|
||||
{
|
||||
int nOctaves = fn["nOctaves"];
|
||||
int nOctaveLayers = fn["nOctaveLayers"];
|
||||
bool extended = (int)fn["extended"] != 0;
|
||||
bool upright = (int)fn["upright"] != 0;
|
||||
|
||||
surf = SURF( 0.0, nOctaves, nOctaveLayers, extended, upright );
|
||||
}
|
||||
|
||||
void SurfDescriptorExtractor::write( FileStorage &fs ) const
|
||||
{
|
||||
// fs << "algorithm" << getAlgorithmName ();
|
||||
|
||||
fs << "nOctaves" << surf.nOctaves;
|
||||
fs << "nOctaveLayers" << surf.nOctaveLayers;
|
||||
fs << "extended" << surf.extended;
|
||||
fs << "upright" << surf.upright;
|
||||
}
|
||||
|
||||
int SurfDescriptorExtractor::descriptorSize() const
|
||||
{
|
||||
return surf.descriptorSize();
|
||||
}
|
||||
|
||||
int SurfDescriptorExtractor::descriptorType() const
|
||||
{
|
||||
return CV_32FC1;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
/** Default constructor */
|
||||
OrbDescriptorExtractor::OrbDescriptorExtractor(ORB::CommonParams params)
|
||||
{
|
||||
orb_ = ORB(0, params);
|
||||
}
|
||||
void OrbDescriptorExtractor::computeImpl(const cv::Mat& image, std::vector<cv::KeyPoint>& keypoints,
|
||||
cv::Mat& descriptors) const
|
||||
{
|
||||
cv::Mat empty_mask;
|
||||
orb_(image, empty_mask, keypoints, descriptors, true);
|
||||
}
|
||||
void OrbDescriptorExtractor::read(const cv::FileNode& fn)
|
||||
{
|
||||
orb_.read(fn);
|
||||
}
|
||||
void OrbDescriptorExtractor::write(cv::FileStorage& fs) const
|
||||
{
|
||||
orb_.write(fs);
|
||||
}
|
||||
int OrbDescriptorExtractor::descriptorSize() const
|
||||
{
|
||||
return orb_.descriptorSize();
|
||||
}
|
||||
int OrbDescriptorExtractor::descriptorType() const
|
||||
{
|
||||
return CV_8UC1;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/****************************************************************************************\
|
||||
* OpponentColorDescriptorExtractor *
|
||||
|
||||
Reference in New Issue
Block a user