Feature Detection using OpenCV [c++ code]
Introduction
<To Be Written>
CODE
#include <iostream> #include <opencv2/opencv.hpp> using namespace std; using namespace cv; int main() { // First declaring three image containers - // image contains input image, // gray_image contains the grayscale converted input image // and keypoint_image contains final image with keypoints drawn on it. Mat image, gray_image, keypoint_image; // This is vector will contain the keypoint values vector<KeyPoint> keypoints; // Read the image in color format image = imread("manu.png",CV_LOAD_IMAGE_COLOR); // Declare Window to display the image namedWindow("Image", CV_WINDOW_AUTOSIZE); // Transform image from BGR format ro grayscale and cvtColor(image, gray_image, CV_BGR2GRAY); // Create a feature detector using FAST algorithm // You can also use - // "STAR" β StarFeatureDetector // "SIFT" β SIFT (nonfree module) // "SURF" β SURF (nonfree module) // "ORB" β ORB // "BRISK" β BRISK // "MSER" β MSER // "GFTT" β GoodFeaturesToTrackDetector // "HARRIS" β GoodFeaturesToTrackDetector with Harris detector enabled // "Dense" β DenseFeatureDetector // "SimpleBlob" β SimpleBlobDetector // Just replace the "FAST" string in the input of create() function by // the desired algorithms string defined above. Ptr<FeatureDetector> feature_detector = FeatureDetector::create("STAR"); // Detect keypoints in the gray_image and store them in keypoints. feature_detector->detect(gray_image, keypoints); // Display the number of keypoints detected cout << "Number of keypoints detected = " << keypoints.size() << endl; // Draw keypoints on the keypoint_image drawKeypoints(image, keypoints, keypoint_image, Scalar::all(-1), DrawMatchesFlags::DEFAULT); // Display the image imshow("Image",keypoint_image); // Wait until, user generates a keypoint event. waitKey(0); // return return 0; }
RESULTS
Feature Detection using FAST algorithm. Circles represent key points.
Also, when we use STAR algorithm, we get this result -
For a detailed comparison, among-st these algorithms, click here.















