added tests for some detectors; made features2d object create functions as static classes methods; fixed OpponentColorDescriptorExtractor, BriefDescriptorExtractor (on rgb); renamed DynamicDetector
This commit is contained in:
@@ -41,14 +41,16 @@
|
||||
//M*/
|
||||
|
||||
#include "precomp.hpp"
|
||||
namespace cv {
|
||||
DynamicDetector::DynamicDetector(int min_features,
|
||||
int max_features, int max_iters, const Ptr<AdjusterAdapter>& a) :
|
||||
escape_iters_(max_iters), min_features_(min_features), max_features_(
|
||||
max_features), adjuster_(a) {
|
||||
}
|
||||
void DynamicDetector::detectImpl(const cv::Mat& image, std::vector<
|
||||
cv::KeyPoint>& keypoints, const cv::Mat& mask) const {
|
||||
namespace cv
|
||||
{
|
||||
|
||||
DynamicAdaptedFeatureDetector::DynamicAdaptedFeatureDetector(const Ptr<AdjusterAdapter>& a,
|
||||
int min_features, int max_features, int max_iters ) :
|
||||
escape_iters_(max_iters), min_features_(min_features), max_features_(max_features), adjuster_(a)
|
||||
{}
|
||||
|
||||
void DynamicAdaptedFeatureDetector::detectImpl(const Mat& image, vector<KeyPoint>& keypoints, const Mat& mask) const
|
||||
{
|
||||
//for oscillation testing
|
||||
bool down = false;
|
||||
bool up = false;
|
||||
@@ -62,88 +64,131 @@ void DynamicDetector::detectImpl(const cv::Mat& image, std::vector<
|
||||
//break if the desired number hasn't been reached.
|
||||
int iter_count = escape_iters_;
|
||||
|
||||
do {
|
||||
do
|
||||
{
|
||||
keypoints.clear();
|
||||
|
||||
//the adjuster takes care of calling the detector with updated parameters
|
||||
adjuster.detect(image, keypoints,mask);
|
||||
|
||||
if (int(keypoints.size()) < min_features_) {
|
||||
if (int(keypoints.size()) < min_features_)
|
||||
{
|
||||
down = true;
|
||||
adjuster.tooFew(min_features_, keypoints.size());
|
||||
} else if (int(keypoints.size()) > max_features_) {
|
||||
}
|
||||
else if (int(keypoints.size()) > max_features_)
|
||||
{
|
||||
up = true;
|
||||
adjuster.tooMany(max_features_, keypoints.size());
|
||||
} else
|
||||
}
|
||||
else
|
||||
thresh_good = true;
|
||||
} while (--iter_count >= 0 && !(down && up) && !thresh_good
|
||||
&& adjuster.good());
|
||||
}
|
||||
while (--iter_count >= 0 && !(down && up) && !thresh_good && adjuster.good());
|
||||
}
|
||||
|
||||
FastAdjuster::FastAdjuster(int init_thresh, bool nonmax) :
|
||||
thresh_(init_thresh), nonmax_(nonmax) {
|
||||
}
|
||||
void FastAdjuster::detectImpl(const cv::Mat& image,
|
||||
std::vector<cv::KeyPoint>& keypoints, const cv::Mat& mask) const {
|
||||
thresh_(init_thresh), nonmax_(nonmax)
|
||||
{}
|
||||
|
||||
void FastAdjuster::detectImpl(const Mat& image, vector<KeyPoint>& keypoints, const Mat& mask) const
|
||||
{
|
||||
FastFeatureDetector(thresh_, nonmax_).detect(image, keypoints, mask);
|
||||
}
|
||||
void FastAdjuster::tooFew(int min, int n_detected) {
|
||||
|
||||
void FastAdjuster::tooFew(int min, int n_detected)
|
||||
{
|
||||
//fast is easy to adjust
|
||||
thresh_--;
|
||||
}
|
||||
void FastAdjuster::tooMany(int max, int n_detected) {
|
||||
|
||||
void FastAdjuster::tooMany(int max, int n_detected)
|
||||
{
|
||||
//fast is easy to adjust
|
||||
thresh_++;
|
||||
}
|
||||
|
||||
//return whether or not the threshhold is beyond
|
||||
//a useful point
|
||||
bool FastAdjuster::good() const {
|
||||
bool FastAdjuster::good() const
|
||||
{
|
||||
return (thresh_ > 1) && (thresh_ < 200);
|
||||
}
|
||||
|
||||
StarAdjuster::StarAdjuster(double initial_thresh) :
|
||||
thresh_(initial_thresh) {
|
||||
}
|
||||
void StarAdjuster::detectImpl(const cv::Mat& image,
|
||||
std::vector<cv::KeyPoint>& keypoints, const cv::Mat& mask) const {
|
||||
thresh_(initial_thresh)
|
||||
{}
|
||||
|
||||
void StarAdjuster::detectImpl(const Mat& image, vector<KeyPoint>& keypoints, const Mat& mask) const
|
||||
{
|
||||
StarFeatureDetector detector_tmp(16, thresh_, 10, 8, 3);
|
||||
detector_tmp.detect(image, keypoints, mask);
|
||||
}
|
||||
void StarAdjuster::tooFew(int min, int n_detected) {
|
||||
|
||||
void StarAdjuster::tooFew(int min, int n_detected)
|
||||
{
|
||||
thresh_ *= 0.9;
|
||||
if (thresh_ < 1.1)
|
||||
thresh_ = 1.1;
|
||||
}
|
||||
void StarAdjuster::tooMany(int max, int n_detected) {
|
||||
|
||||
void StarAdjuster::tooMany(int max, int n_detected)
|
||||
{
|
||||
thresh_ *= 1.1;
|
||||
}
|
||||
|
||||
bool StarAdjuster::good() const {
|
||||
bool StarAdjuster::good() const
|
||||
{
|
||||
return (thresh_ > 2) && (thresh_ < 200);
|
||||
}
|
||||
|
||||
SurfAdjuster::SurfAdjuster() :
|
||||
thresh_(400.0) {
|
||||
}
|
||||
void SurfAdjuster::detectImpl(const cv::Mat& image,
|
||||
std::vector<cv::KeyPoint>& keypoints, const cv::Mat& mask) const {
|
||||
thresh_(400.0)
|
||||
{}
|
||||
|
||||
void SurfAdjuster::detectImpl(const Mat& image, vector<KeyPoint>& keypoints, const cv::Mat& mask) const
|
||||
{
|
||||
SurfFeatureDetector detector_tmp(thresh_);
|
||||
detector_tmp.detect(image, keypoints, mask);
|
||||
}
|
||||
void SurfAdjuster::tooFew(int min, int n_detected) {
|
||||
|
||||
void SurfAdjuster::tooFew(int min, int n_detected)
|
||||
{
|
||||
thresh_ *= 0.9;
|
||||
if (thresh_ < 1.1)
|
||||
thresh_ = 1.1;
|
||||
}
|
||||
void SurfAdjuster::tooMany(int max, int n_detected) {
|
||||
|
||||
void SurfAdjuster::tooMany(int max, int n_detected)
|
||||
{
|
||||
thresh_ *= 1.1;
|
||||
}
|
||||
|
||||
//return whether or not the threshhold is beyond
|
||||
//a useful point
|
||||
bool SurfAdjuster::good() const {
|
||||
bool SurfAdjuster::good() const
|
||||
{
|
||||
return (thresh_ > 2) && (thresh_ < 1000);
|
||||
}
|
||||
|
||||
Ptr<AdjusterAdapter> AdjusterAdapter::create( const string& detectorType )
|
||||
{
|
||||
Ptr<AdjusterAdapter> adapter;
|
||||
|
||||
if( !detectorType.compare( "FAST" ) )
|
||||
{
|
||||
adapter = new FastAdjuster();
|
||||
}
|
||||
else if( !detectorType.compare( "STAR" ) )
|
||||
{
|
||||
adapter = new StarAdjuster();
|
||||
}
|
||||
else if( !detectorType.compare( "SURF" ) )
|
||||
{
|
||||
adapter = new SurfAdjuster();
|
||||
}
|
||||
|
||||
return adapter;
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user