tags: OpenCV learning notes
This article is the next article to write down, focusing on the output of the introduction point, other places do not have too much
#include "opencv2/opencv.hpp"
#include <opencv2/nonfree/nonfree.hpp>//SIFT
#include <opencv2/legacy/legacy.hpp>// bFMATCH violence matching
#include <vector>
#include<iostream>
using namespace std;
using namespace cv;
void main()
{
Mat srcImg1 = imread("D:\\0.jpg");
Mat srcImg2 = imread("D:\\1.jpg");
resize(srcImg1,srcImg1,Size(srcImg1.cols*3,srcImg1.rows*3));
resize(srcImg2,srcImg2,Size(srcImg2.cols/3,srcImg2.rows/3));
/ / Define SIFT feature detection class object
SiftFeatureDetector siftDetector(1000);
/ / Define KeyPoint variables
vector<KeyPoint>keyPoints1;
vector<KeyPoint>keyPoints2;
// Feature point detection
siftDetector.detect(srcImg1, keyPoints1);
siftDetector.detect(srcImg2, keyPoints2);
// Draw feature points (key points)
Mat feature_pic1, feature_pic2;
drawKeypoints(srcImg1, keyPoints1, feature_pic1, Scalar::all(-1));
drawKeypoints(srcImg2, keyPoints2, feature_pic2, Scalar::all(-1));
// Show original map
imshow("src1", srcImg1);
imshow("src2", srcImg2);
//show result
imshow("feature1", feature_pic1);
imshow("feature2", feature_pic2);
/ / Calculate Feature Point Descriptor / Feature Vector Extract
SiftDescriptorExtractor descriptor;
Mat description1;
descriptor.compute(srcImg1, keyPoints1, description1);
Mat description2;
descriptor.compute(srcImg2, keyPoints2, description2);
cout<<description1.cols<<endl;
cout<<description1.rows<<endl;
/ / Matching BFMATCH violence
BruteForceMatcher<L1<float>>matcher; // Instantiate violence matching
vector<DMatch>matches; / / Define match result variables
matcher.match(description1, description2, matches); // Implement the match between the descriptor
// Match results filter
nth_element(matches.begin(), matches.begin()+0, matches.end()); / / Extract the previous X best match result
matches.erase(matches.begin()+1, matches.end()); // Remove the rest of the result
int index1,index2;
for(size_t i=0;i<matches.size();i++)/ / Here is the output of the screened coordinate pair
{
index1=matches.at(i).queryIdx;// This is an attribute of accessing the feature picture. Specifically, I don't understand the source code.
index2=matches.at(i).trainIdx;// This is an attribute that access to the image to be matched
cout<<"This is a :"<<keyPoints2.at(index2).pt<<endl;/ / I am here to output the coordinates of the characteristic picture, KeyPoints2 is a collection after the feature vector extraction
cout<<"This is a :"<<keyPoints2.at(index2).pt.x<<endl// Here is the x point to output the characteristic image to be matched
cout<<"This is a :"<<keyPoints2.at(index2).pt.y<<endl/ / Here is the Y point of outputting the characteristic image to be matched
}
Mat result;
drawMatches(srcImg1, keyPoints1, srcImg2, keyPoints2, matches, result, Scalar(0, 255, 0), Scalar::all(-1));// Match feature point green, single feature point color random
imshow("Match_Result", result);
waitKey(0);
}
Make a small arrangement of the image processing of OpenCV recently, and intend to organize some records of video processing in the next issue. 1. Use OpenCV to perform Harris, SIFT feature points, an...
Comparison of SIFT and SURF features Compare items SIFT SURF Scale space extreme value detection Use Gaussian filters to find local extrema based on Gaussian difference (DOG) images of different scale...
SIFT feature extraction and matching step ① Use SiftFeatureDetector's detect method to detect features and store them in a vector (you can use drawKeypoints to identify them in the figure) ② Use SiftD...
It ’s time to feel another one, and I ’ll do research immediately. Gossip less, start operation. The monkey who is most familiar with computer vision is probably the SIFT algorithm of LOWE...
The steps of SIFT are as follows:...
From step one, we have obtained the feature point vector set of the picture. Now let’s look at feature point matching. One application of feature point matching is object recognition. For exampl...
Feature detection belongs to opencv_contrib library, When compiling OpenCV, additional modules are included to use it, and how to compile it will not be explained here. 1. Create a detector First read...
Overview Previous articleSURF and SIFT operators realize feature point detectionSimply talk about the use of SIFT and SURF operators to detect feature points. On the basis of detection, SIFT and SURF ...
Original address: code show as below: ...