标签:des io ar os sp for strong on cti
这篇教程其实是上一篇的总结 ,利用 features2d 和 calib3d 模块来发掘场景中的物体 ~~
1, Create a new console project. Read two input images.
Mat img1 = imread(argv[1], CV_LOAD_IMAGE_GRAYSCALE); Mat img2 = imread(argv[2], CV_LOAD_IMAGE_GRAYSCALE);
2, Detect keypoints in both images.
// detecting keypoints FastFeatureDetector detector(15); vector<KeyPoint> keypoints1; detector.detect(img1, keypoints1); ... // do the same for the second image
3, Compute descriptors for each of the keypoints.
// computing descriptors SurfDescriptorExtractor extractor; Mat descriptors1; extractor.compute(img1, keypoints1, descriptors1); ... // process keypoints from the second image as well
4,Now, find the closest matches between descriptors from the first image to the second:
// matching descriptors BruteForceMatcher<L2<float> > matcher; vector<DMatch> matches; matcher.match(descriptors1, descriptors2, matches);
5, Visualize the results:
// drawing the results namedWindow("matches", 1); Mat img_matches; drawMatches(img1, keypoints1, img2, keypoints2, matches, img_matches); imshow("matches", img_matches); waitKey(0);
6,Find the homography transformation between two sets of points:
vector<Point2f> points1, points2; // fill the arrays with the points .... Mat H = findHomography(Mat(points1), Mat(points2), CV_RANSAC, ransacReprojThreshold);
7,Create a set of inlier matches and draw them. Use perspectiveTransform function to map points with homography:
Mat points1Projected; perspectiveTransform(Mat(points1), points1Projected, H);
8,Use drawMatches for drawing inliers.
OpenCV Tutorials —— Detection of planar objects
标签:des io ar os sp for strong on cti
原文地址:http://www.cnblogs.com/sprint1989/p/4125583.html