Features.cpp
Go to the documentation of this file.
00001 #include <pano_core/Features.h>
00002 #include <pano_core/feature_utils.h>
00003 #include <opencv2/core/core.hpp>
00004 #include <opencv2/highgui/highgui.hpp>
00005 
00006 using namespace cv;
00007 namespace pano
00008 {
00009 
00010 Features::Features()
00011 {
00012 }
00013 
00014 void Features::detect(const cv::FeatureDetector& detect, const cv::Mat& img)
00015 {
00016   detect.detect(img, kpts_);
00017  // KeyPointsToPoints(kpts_, pts_);
00018 }
00019 
00020 void Features::extract(const cv::DescriptorExtractor& extract, const cv::Mat& img)
00021 {
00022   extract.compute(img, kpts_, descriptors_);
00023   KeyPointsToPoints(kpts_, pts_);
00024   //  matcher_->add(vector<Mat>(1,descriptors_));
00025   //  matcher_->train();
00026 }
00027 
00028 void Features::match(const Features& features, const cv::Mat& mask, std::vector<cv::DMatch>& matches) const
00029 {
00030 
00031   if (!descriptors_.empty() && !features.descriptors_.empty())
00032   {
00033     matcher_->match(features.descriptors_, descriptors_, matches, mask);
00034   }
00035 }
00036 
00037 void Features::serialize(cv::FileStorage& fs) const
00038 {
00039   fs << "{";
00040   cvWriteComment(*fs, "Features class", 0);
00041   //  cv::write(fs,"keypoints",kpts_);
00042   fs << "}";
00043 }
00044 void Features::deserialize(const cv::FileNode& fn)
00045 {
00046   read(fn["keypoints"], kpts_);
00047 
00048 }
00049 void drawMatchesRelative(const Features& train, const Features& query, const std::vector<cv::DMatch>& matches,
00050                          Mat& img, const vector<unsigned char>& mask)
00051 {
00052   for (int i = 0; i < (int)matches.size(); i++)
00053   {
00054     if (mask.empty() || mask[i])
00055     {
00056       Point2f pt_new = query.pts()[matches[i].queryIdx];
00057       Point2f pt_old = train.pts()[matches[i].trainIdx];
00058       Point2f dist = pt_new - pt_old;
00059 
00060       cv::line(img, pt_new, pt_old, Scalar(125, 255, 125), 1);
00061       cv::circle(img, pt_new, 2, Scalar(255, 0, 125), 1);
00062 
00063     }
00064   }
00065 }
00066 }


pano_core
Author(s): Ethan Rublee
autogenerated on Mon Oct 6 2014 08:04:38