Fix BRISK detector&descriptor using proper AGAST.
This commit is contained in:
7667
modules/features2d/src/agast.cpp
Normal file
7667
modules/features2d/src/agast.cpp
Normal file
File diff suppressed because it is too large
Load Diff
9375
modules/features2d/src/agast_score.cpp
Normal file
9375
modules/features2d/src/agast_score.cpp
Normal file
File diff suppressed because it is too large
Load Diff
62
modules/features2d/src/agast_score.hpp
Normal file
62
modules/features2d/src/agast_score.hpp
Normal file
@@ -0,0 +1,62 @@
|
||||
/* This is AGAST and OAST, an optimal and accelerated corner detector
|
||||
based on the accelerated segment tests
|
||||
Below is the original copyright and the references */
|
||||
|
||||
/*
|
||||
Copyright (C) 2010 Elmar Mair
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
|
||||
*Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
|
||||
*Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
*Neither the name of the University of Cambridge nor the names of
|
||||
its contributors may be used to endorse or promote products derived
|
||||
from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/*
|
||||
The references are:
|
||||
* Adaptive and Generic Corner Detection Based on the Accelerated Segment Test,
|
||||
Elmar Mair and Gregory D. Hager and Darius Burschka
|
||||
and Michael Suppa and Gerhard Hirzinger ECCV 2010
|
||||
URL: http://www6.in.tum.de/Main/ResearchAgast
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __OPENCV_FEATURES_2D_AGAST_HPP__
|
||||
#define __OPENCV_FEATURES_2D_AGAST_HPP__
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
#include "precomp.hpp"
|
||||
namespace cv
|
||||
{
|
||||
|
||||
void makeAgastOffsets(int pixel[16], int row_stride, int type);
|
||||
|
||||
template<int type>
|
||||
int agast_cornerScore(const uchar* ptr, const int pixel[], int threshold);
|
||||
|
||||
}
|
||||
#endif
|
||||
#endif
|
@@ -46,7 +46,7 @@
|
||||
#include <fstream>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "fast_score.hpp"
|
||||
#include "agast_score.hpp"
|
||||
|
||||
namespace cv
|
||||
{
|
||||
@@ -157,7 +157,7 @@ public:
|
||||
// derive a layer
|
||||
BriskLayer(const BriskLayer& layer, int mode);
|
||||
|
||||
// Fast/Agast without non-max suppression
|
||||
// Agast without non-max suppression
|
||||
void
|
||||
getAgastPoints(int threshold, std::vector<cv::KeyPoint>& keypoints);
|
||||
|
||||
@@ -204,13 +204,13 @@ private:
|
||||
value(const cv::Mat& mat, float xf, float yf, float scale) const;
|
||||
// the image
|
||||
cv::Mat img_;
|
||||
// its Fast scores
|
||||
// its Agast scores
|
||||
cv::Mat_<uchar> scores_;
|
||||
// coordinate transformation
|
||||
float scale_;
|
||||
float offset_;
|
||||
// agast
|
||||
cv::Ptr<cv::FastFeatureDetector> fast_9_16_;
|
||||
cv::Ptr<cv::AgastFeatureDetector> oast_9_16_;
|
||||
int pixel_5_8_[25];
|
||||
int pixel_9_16_[25];
|
||||
};
|
||||
@@ -618,8 +618,6 @@ BRISK_Impl::detectAndCompute( InputArray _image, InputArray _mask, std::vector<K
|
||||
OutputArray _descriptors, bool useProvidedKeypoints)
|
||||
{
|
||||
bool doOrientation=true;
|
||||
if (useProvidedKeypoints)
|
||||
doOrientation = false;
|
||||
|
||||
// If the user specified cv::noArray(), this will yield false. Otherwise it will return true.
|
||||
bool doDescriptors = _descriptors.needed();
|
||||
@@ -733,8 +731,12 @@ BRISK_Impl::computeDescriptorsAndOrOrientation(InputArray _image, InputArray _ma
|
||||
direction1 += tmp1;
|
||||
}
|
||||
kp.angle = (float)(atan2((float) direction1, (float) direction0) / CV_PI * 180.0);
|
||||
if (kp.angle < 0)
|
||||
kp.angle += 360.f;
|
||||
|
||||
if (!doDescriptors)
|
||||
{
|
||||
if (kp.angle < 0)
|
||||
kp.angle += 360.f;
|
||||
}
|
||||
}
|
||||
|
||||
if (!doDescriptors)
|
||||
@@ -755,6 +757,9 @@ BRISK_Impl::computeDescriptorsAndOrOrientation(InputArray _image, InputArray _ma
|
||||
theta -= n_rot_;
|
||||
}
|
||||
|
||||
if (kp.angle < 0)
|
||||
kp.angle += 360.f;
|
||||
|
||||
// now also extract the stuff for the actual direction:
|
||||
// let us compute the smoothed values
|
||||
int shifter = 0;
|
||||
@@ -867,7 +872,7 @@ BriskScaleSpace::getKeypoints(const int threshold_, std::vector<cv::KeyPoint>& k
|
||||
std::vector<std::vector<cv::KeyPoint> > agastPoints;
|
||||
agastPoints.resize(layers_);
|
||||
|
||||
// go through the octaves and intra layers and calculate fast corner scores:
|
||||
// go through the octaves and intra layers and calculate agast corner scores:
|
||||
for (int i = 0; i < layers_; i++)
|
||||
{
|
||||
// call OAST16_9 without nms
|
||||
@@ -2067,9 +2072,9 @@ BriskLayer::BriskLayer(const cv::Mat& img_in, float scale_in, float offset_in)
|
||||
scale_ = scale_in;
|
||||
offset_ = offset_in;
|
||||
// create an agast detector
|
||||
fast_9_16_ = FastFeatureDetector::create(1, true, FastFeatureDetector::TYPE_9_16);
|
||||
makeOffsets(pixel_5_8_, (int)img_.step, 8);
|
||||
makeOffsets(pixel_9_16_, (int)img_.step, 16);
|
||||
oast_9_16_ = AgastFeatureDetector::create(1, false, AgastFeatureDetector::OAST_9_16);
|
||||
makeAgastOffsets(pixel_5_8_, (int)img_.step, AgastFeatureDetector::AGAST_5_8);
|
||||
makeAgastOffsets(pixel_9_16_, (int)img_.step, AgastFeatureDetector::OAST_9_16);
|
||||
}
|
||||
// derive a layer
|
||||
BriskLayer::BriskLayer(const BriskLayer& layer, int mode)
|
||||
@@ -2089,18 +2094,18 @@ BriskLayer::BriskLayer(const BriskLayer& layer, int mode)
|
||||
offset_ = 0.5f * scale_ - 0.5f;
|
||||
}
|
||||
scores_ = cv::Mat::zeros(img_.rows, img_.cols, CV_8U);
|
||||
fast_9_16_ = FastFeatureDetector::create(1, false, FastFeatureDetector::TYPE_9_16);
|
||||
makeOffsets(pixel_5_8_, (int)img_.step, 8);
|
||||
makeOffsets(pixel_9_16_, (int)img_.step, 16);
|
||||
oast_9_16_ = AgastFeatureDetector::create(1, false, AgastFeatureDetector::OAST_9_16);
|
||||
makeAgastOffsets(pixel_5_8_, (int)img_.step, AgastFeatureDetector::AGAST_5_8);
|
||||
makeAgastOffsets(pixel_9_16_, (int)img_.step, AgastFeatureDetector::OAST_9_16);
|
||||
}
|
||||
|
||||
// Fast/Agast
|
||||
// Agast
|
||||
// wraps the agast class
|
||||
void
|
||||
BriskLayer::getAgastPoints(int threshold, std::vector<KeyPoint>& keypoints)
|
||||
{
|
||||
fast_9_16_->setThreshold(threshold);
|
||||
fast_9_16_->detect(img_, keypoints);
|
||||
oast_9_16_->setThreshold(threshold);
|
||||
oast_9_16_->detect(img_, keypoints);
|
||||
|
||||
// also write scores
|
||||
const size_t num = keypoints.size();
|
||||
@@ -2121,7 +2126,7 @@ BriskLayer::getAgastScore(int x, int y, int threshold) const
|
||||
{
|
||||
return score;
|
||||
}
|
||||
score = (uchar)cornerScore<16>(&img_.at<uchar>(y, x), pixel_9_16_, threshold - 1);
|
||||
score = (uchar)agast_cornerScore<AgastFeatureDetector::OAST_9_16>(&img_.at<uchar>(y, x), pixel_9_16_, threshold - 1);
|
||||
if (score < threshold)
|
||||
score = 0;
|
||||
return score;
|
||||
@@ -2134,7 +2139,7 @@ BriskLayer::getAgastScore_5_8(int x, int y, int threshold) const
|
||||
return 0;
|
||||
if (x >= img_.cols - 2 || y >= img_.rows - 2)
|
||||
return 0;
|
||||
int score = cornerScore<8>(&img_.at<uchar>(y, x), pixel_5_8_, threshold - 1);
|
||||
int score = agast_cornerScore<AgastFeatureDetector::AGAST_5_8>(&img_.at<uchar>(y, x), pixel_5_8_, threshold - 1);
|
||||
if (score < threshold)
|
||||
score = 0;
|
||||
return score;
|
||||
|
Reference in New Issue
Block a user