This is a C++ implementation of SIFT, a feature detection algorithm.
stb_image and stb_image_write for loading and saving images. (included in this repo)
Find keypoints, match features in two images and save the result:
#include <vector>
#include "image.hpp"
#include "sift.hpp"
int main()
{
Image img("./../imgs/book_rotated.jpg");
Image img2("./../imgs/book_in_scene.jpg");
img = rgb_to_grayscale(img);
img2 = rgb_to_grayscale(img2);
std::vector<sift::Keypoint> kps1 = sift::find_keypoints_and_descriptors(img);
std::vector<sift::Keypoint> kps2 = sift::find_keypoints_and_descriptors(img2);
std::vector<std::pair<int, int>> matches = sift::find_keypoint_matches(kps1, kps2);
Image book_matches = sift::draw_matches(img, img2, kps1, kps2, matches);
book_matches.save("book_matches.jpg");
return 0;
}
$ mkdir build/ && cd build && cmake .. && make
The executables will be in sift-cpp/bin/.
Find image keypoints, draw them and save the result:
$ cd bin/ && ./find_keypoints ../imgs/book_rotated.jpg
Input images can be .jpg or .png. Result image is saved as result.jpg
Find keypoints in two images and match them, draw matches and save the result:
$ cd bin/ && ./match_features ../imgs/book_rotated.jpg ../imgs/book_in_scene.jpg
Result image is saved as result.jpg