Skip to content

Instantly share code, notes, and snippets.

@Fiona-J-W
Created March 25, 2014 22:41
Show Gist options
  • Select an option

  • Save Fiona-J-W/9773076 to your computer and use it in GitHub Desktop.

Select an option

Save Fiona-J-W/9773076 to your computer and use it in GitHub Desktop.
CVVisual showImage + filter + matches
#include <iostream>
#include <string>
#include <vector>
#include <tuple>
#include <utility>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/features2d/features2d.hpp>
#include <opencv2/show_image.hpp>
#include <opencv2/filter.hpp>
#include <opencv2/dmatch.hpp>
#include <opencv2/final_show.hpp>
int main(int argc, char** argv) {
cvv::FinalShowCaller final_show_caller;
std::vector<cv::Mat> original_images;
for (int i=1; i<argc; ++i) {
auto orig = cv::imread(argv[i]);
cv::Mat gray_img;
cv::cvtColor(orig, gray_img, CV_BGR2GRAY);
cvv::showImage(gray_img, CVVISUAL_LOCATION, argv[i]);
original_images.emplace_back(std::move(gray_img));
}
std::vector<std::tuple<cv::Mat, std::vector<cv::KeyPoint>, cv::Mat>> filtered_images;
cv::ORB detector(500);
auto elem = cv::getStructuringElement(cv::MORPH_RECT, cv::Size(2, 2), cv::Point(1, 1));
for (const auto& orig: original_images) {
cv::Mat filtered;
cv::morphologyEx(orig, filtered, cv::MORPH_GRADIENT, elem);
cvv::debugFilter(orig, filtered, CVVISUAL_LOCATION, "morphologyEx");
std::vector<cv::KeyPoint> matches;
cv::Mat descriptors;
detector(filtered, cv::noArray(), matches, descriptors);
filtered_images.emplace_back(std::move(filtered), std::move(matches),
std::move(descriptors));
}
cv::BFMatcher matcher(cv::NORM_HAMMING);
for (std::size_t i = 1; i < filtered_images.size(); ++i) {
std::vector<cv::DMatch> matches;
matcher.match(std::get<2>(filtered_images.at(i-1)), std::get<2>(filtered_images.at(i)),
matches);
auto& mat1 = std::get<0>(filtered_images.at(i-1));
auto& mat2 = std::get<0>(filtered_images.at(i));
auto& keypoints1 = std::get<1>(filtered_images.at(i-1));
auto& keypoints2 = std::get<1>(filtered_images.at(i));
cvv::debugDMatch(mat1,keypoints1, mat2, keypoints2, matches, CVVISUAL_LOCATION);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment