In the previous article, "OpenCV feature2d learning--surf and SIFT operators to achieve feature point detection", the use of SIFT and surf operators for feature point detection, here is trying to use fast operator for feature point detection.
Fast's full name is:Features from Accelerated Segment test, the main feature values are fast, much faster than other known feature point detection algorithms, and can be used in real-time scenarios for computer vision applications. At present , its high computational efficiency (computational performance) and high repeatability (highrepeatability) have become the most popular feature point detection method in computer vision field. The disadvantage is that when the noise in the picture is more, the robustness of fast operator is not good and the effect of the algorithm depends on a threshold threshold, besides, fast operator does not produce multi-scale feature and has no direction information, so it loses rotation invariance.
The detailed principles and procedures for fast feature point detection can be found in the fast operator series of fast feature point detection and image processing feature invariant (IV.). Related papers:
[1] Edward Rosten and Tom Drummond, "machine learning for high speed corner detection" in 9th European Conferenceon Compute R Vision, vol. 1, 2006, pp. 430–443.
[2] Edward Rosten, Reid Porter, and Tomdrummond, "Faster and better:a machine learning approach to corner detection" in IE EE Trans. Pattern Analysis and Machine Intelligence, vol., vol, pp.105-119.
I, using fast function for feature detection
The FAST/FASTX function in OpenCV is used for fast feature point detection. The function prototypes are as follows:
C + +: void FAST (Inputarray image, vector<keypoint>& keypoints, int threshold, BOOL nonmaxsuppression=true) C + +: void Fastx (Inputarray image, vector<keypoint>& keypoints, int threshold, bool nonmaxsuppression, int type)
Parameters:
image– Enter a grayscale image.
keypoints– the detected feature points.
threshold– The threshold value of the pixel value of the center pixel and the pixel value around the pixel.
nonmaxsuppression– Whether maximum suppression is applied to feature points.
type– pixels Three types of neighborhood circles: Fastfeaturedetector::type_9_16,fastfeaturedetector::type_7_12, Fastfeaturedetector::type_5_8.
The basic use examples of functions are as follows:
/*** @ Overview: Feature point detection using fast * @ Classes and Functions: Fast function, Fastfeaturedetector class * @author: holybin*/#include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> #include <opencv2/imgproc/imgproc.hpp> #include <opencv2/ Features2d/features2d.hpp>using namespace CV; Using namespace Std;int main (int argc, char** argv) {Mat img = imread ("box_in_scene.png");vector<keypoint> KeyPoint S FAST (IMG, keypoints, 20); --Draw the feature point Mat img_keypoints; Drawkeypoints (IMG, keypoints, img_keypoints, Scalar::all ( -1), Drawmatchesflags::D efault); --Display feature point imshow ("Keypoints", img_keypoints), Imwrite ("Fast_detection_result.png", img_keypoints); Waitkey (0); return 0; }
Run results
II. Using Fastfeaturedetector for fast feature point detection
Fastfeaturedetector inherits from the virtual base class Featuredetector of 2D image feature detection and is designed for fast feature detection, similar to the following classes:
The class definition for Fastfeaturedetector is as follows:
Class Fastfeaturedetector:public Featuredetector{public:fastfeaturedetector (int threshold=1, BOOL NonmaxSuppression =true, type=fastfeaturedetector::type_9_16);//You can see that Fastfeaturedetector's constructor defaults to 1 for non-maximum suppression and 16 for circumferential pixels. Virtual void Read (const filenode& FN); virtual void write (filestorage& fs) const;//Note that the Detect function is defined in the virtual base class Featur In the Edetector. Protected: ... };
The specific use examples of the Fastfeaturedetector class are as follows:
/*** @ Overview: Feature point detection using fast * @ Classes and Functions: Fast function, Fastfeaturedetector class * @author: holybin*/#include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> #include <opencv2/imgproc/imgproc.hpp> #include <opencv2/ Features2d/features2d.hpp>using namespace CV; Using namespace Std;int main (int argc, char** argv) {Mat img = imread ("box_in_scene.png");vector<keypoint> KeyPoint S Fastfeaturedetector fast; Fast.detect (img,keypoints);//--draw feature points mat img_keypoints; Drawkeypoints (IMG, keypoints, img_keypoints, Scalar::all ( -1), Drawmatchesflags::D efault); --Display feature point imshow ("Keypoints", img_keypoints), Imwrite ("Fast_detection_result.png", img_keypoints); Waitkey (0); return 0; }
Run results
It is noted here that the effect of the two methods is different , the reason, when using the Detect function for feature point detection, The actual invocation of the Detectimpl function in Featuredetector's various derived classes (here is the Fastfeaturedetector class), refer to the Detect function source code (location \opencv2.4.0\modules\ Features2d\src\detectors.cpp):
void Featuredetector::d etect (const mat& image, vector<keypoint>& keypoints, const mat& mask) const{
keypoints.clear (); if (Image.empty ()) return; Cv_assert (Mask.empty () | | (Mask.type () = = Cv_8uc1 && mask.size () = = Image.size ())); Detectimpl (image, keypoints, mask);//The function that actually calls the derived class}
The source code for the Detectimpl function in the derived class Fastfeaturedetector is as follows (location \opencv2.4.0\modules\features2d\src\fast.cpp):
void Fastfeaturedetector::d etectimpl (const mat& image, vector<keypoint>& keypoints, const mat& mask) const{ Mat grayimage = image; if (Image.type ()! = cv_8u) Cvtcolor (image, Grayimage, cv_bgr2gray); Fast (Grayimage, keypoints, Threshold, nonmaxsuppression);//Call fast function Keypointsfilter::runbypixelsmask ( Keypoints, mask);}
You can see that the Detectimpl function called the fast function to do the feature point detection, and then called the Runbypixelsmask function to do some other processing, because all the incoming parameters are consistent, and it can be concluded that these operations make the final test result different. But I do not know the specific operation, if the great God know the hope.
Detection of Feature2d Learning--fast feature points in OpenCV