Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

changed zoomout method, added matches parameters

  • Loading branch information...
commit b27ca39a167fe608c3b7d4741390b892913d124a 1 parent 7abb18a
@abhinavgupta authored
View
4 CMakeLists.txt
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 2.3)
-project( zoomout)
+project(SIFT_Descriptor)
find_package (OpenCV REQUIRED)
-add_executable (SIFT_Descriptor SIFT_Descriptor.cpp zoomout.cpp)
+add_executable (SIFT_Descriptor SIFT_Descriptor.cpp)
target_link_libraries ( SIFT_Descriptor ${OpenCV_LIBS} )
View
6 README
@@ -35,12 +35,12 @@ This should make the required files and the executable as well
RUNNING THE CODE:
-./SIFT_descriptor <Object image> <Scene Image> <resize parameter in power of two> <threshold multiplier for min distance>
+./SIFT_descriptor <Object image> <Scene Image> <resize parameter in power of two> <number of matches to be considered>
img1 : Object Image (This will be the zoomed in version)
img2 : Scene Image (This will be the Map version, scaled out as compared to the object image)
-resize parameter : This parameter is to give a power index to scale down the image. An input k will scale down by 2^k (In an UAV, this parameter will be a function of height of the UAV)
-Threshold multipler for min distance: Depending on the number of "good matches" recived, this parameter will give an appropriate multipler to filter out the best possible matches. Heuristically can be made a function of the resize parameter and consequently the height.
+resize parameter : This parameter will scale the image. and float value k will change the image size k times. In most cases k < 0 (In an UAV, this parameter will be a function of height of the UAV)
+number of matches to be considered : This parameter defines the number of matches to be used for the purpose of homography calculations.
AUTHORS:
View
49 SIFT_Descriptor.cpp
@@ -1,9 +1,8 @@
-
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <iostream>
-#include <assert.h>
+#include <algorithm>
#include "opencv2/core/core.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/nonfree/features2d.hpp"
@@ -11,18 +10,17 @@
#include "opencv2/calib3d/calib3d.hpp"
#include "opencv2/nonfree/features2d.hpp"
#include "opencv2/imgproc/imgproc.hpp"
-#include "utils.hpp"
-
-#define ASSERT(condition, message) \
- if (! (condition)) { \
- std::cerr << "\nAssertion `" #condition "` failed " \
- << "\nLine : " << __LINE__ << "\n" << message << std::endl; \
- std::exit(EXIT_FAILURE); \
- } \
using namespace cv;
+//Sorting Comparison Function - Added by Ritesh
+bool myobject (DMatch i,DMatch j)
+{
+ return (i.distance<j.distance);
+}
+
+
void readme(); //README function for showing usage
@@ -45,7 +43,10 @@ int main (int argc, char** argv)
return -1;
}
- img_object = zoomout(img_object_temp, atoi(argv[3]));
+ float size = atof(argv[3]);
+
+ resize(img_object_temp, img_object, Size(), size, size, INTER_AREA);
+
std::vector<KeyPoint> keypoints_object, keypoints_scene; //Initializing data structures for keypoints & descriptors
Mat descriptors_object, descriptors_scene;
@@ -78,21 +79,24 @@ int main (int argc, char** argv)
printf ("-- Min Distance : %f \n", min_dist);
std::vector<DMatch> good_matches;
-
- for(int i = 0; i < descriptors_object.rows; i++)
- {
- if (matches[i].distance < atoi(argv[4])*min_dist) //Classifying good matches from generic matches by defining a threshold
+
+ std::sort(matches.begin(),matches.end(),myobject);
+
+ int number_of_matches = atoi(argv[4]);
+
+ if(number_of_matches > matches.size())
{
- good_matches.push_back(matches[i]);
- }
+ number_of_matches = matches.size();
+ }
+
+ for(int i = 0; i < atoi(argv[4]) ; i++)
+ {
+ good_matches.push_back(matches[i]);
}
- std::cout<<good_matches.size()<<std::endl;
- ASSERT(good_matches.size() >= 4 , "Not enough good matches were detected!"); // Checking whether good matches were found
-
Mat img_matches;
- drawMatches (img_object, keypoints_object, img_scene, keypoints_scene, good_matches, img_matches, Scalar::all(-1), Scalar::all(-1), vector<char>(), DrawMatchesFlags::NOT_DRAW_SINGLE_POINTS);
+ drawMatches (img_object, keypoints_object, img_scene, keypoints_scene, good_matches, img_matches, Scalar::all(-1), Scalar::all(-1), vector<char>(), DrawMatchesFlags::DRAW_RICH_KEYPOINTS);
std::vector<Point2f> obj;
std::vector<Point2f> scene;
@@ -130,4 +134,5 @@ int main (int argc, char** argv)
* @function readme
*/
void readme()
- { std::cout << " Usage: ./SIFT_descriptor <object_image> <scene_image> <resize parameter in power of two> <threshold multiplier for min distance> \n FOR FURTHER INFO CHECK README \n" << std::endl; }
+ { std::cout << " Usage: ./SIFT_descriptor <object_image> <scene_image> <resize parameter> <number of matches to be used (integer)> \n FOR FURTHER INFO CHECK README \n" << std::endl; }
+
View
6 utils.hpp
@@ -1,6 +0,0 @@
-#ifndef UTILS_HPP
-#define UTILS_HPP
-
-cv::Mat zoomout( cv::Mat src, int iterations );
-
-#endif
View
32 zoomout.cpp
@@ -1,32 +0,0 @@
-#include "opencv2/imgproc/imgproc.hpp"
-#include "opencv2/highgui/highgui.hpp"
-#include <math.h>
-#include <stdlib.h>
-#include <stdio.h>
-
-using namespace cv;
-
-/**
- * @function main
- */
-Mat zoomout( Mat src, int iterations )
-{
-
-
-
-
- Mat dst = src;
-
-
- for( int i = 0; i<iterations; i++)
- {
- pyrDown( src, dst, Size( src.cols/2, src.rows/2 ) );
- src = dst;
- }
-
-
-
-
- return dst;
-}
-
Please sign in to comment.
Something went wrong with that request. Please try again.