-
Notifications
You must be signed in to change notification settings - Fork 0
/
feature_methods_compare.cxx
90 lines (69 loc) · 2.33 KB
/
feature_methods_compare.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/nonfree/features2d.hpp> //
#include <opencv2/nonfree/nonfree.hpp>
#include <string>
#include <iostream>
#include <dirent.h>
#include <ctime>
using namespace cv;
using namespace std;
#define IMG_NUM 50;
#define IMG_DIR "./imgs-precision-size/"
void extract_faeatures(std::vector<Mat> imgs, string method);
bool has_suffix(const std::string &str, const std::string &suffix);
int main(int argc, const char *argv[]){
if(argc != 2){
cout << "usage:compare <method>\n" ;
exit(-1);
}
string method = string(argv[1]);
//We just want to compare the speed of image feature extraction,
// so read all iamges to memory first.(FIXME)
vector<Mat> imgs;
DIR *dir;
struct dirent *ent;
if((dir = opendir(IMG_DIR)) != NULL){
while((ent = readdir(dir)) != NULL){
string name = (string)(ent->d_name);
// jpg , jpeg imags
if(has_suffix(name, "g")){
Mat input = imread(IMG_DIR + name, 0);// load as grayscale
imgs.push_back(input);
}
}
}else{
cout << "cannot open the directory!\n";
exit(-1);
}
cout << "Img dataset size :" << imgs.size() << endl;
// We Need To measure the elapsed time
clock_t begin = clock();
extract_faeatures(imgs, method);
clock_t end = clock();
double elapsed_secs = double(end - begin) / CLOCKS_PER_SEC;
cout << "Time Costs : " << elapsed_secs << endl;
// show the keypoints on an image
// Mat output;
// drawKeypoints(input, keypoints, output);
// imshow("show keypoints",output);
// waitKey(0);
return 0;
}
void extract_faeatures(std::vector<Mat> imgs, string method){
// Get detector
initModule_nonfree();
Ptr<FeatureDetector> detector;
detector = FeatureDetector::create(method);
for(std::vector<Mat>::size_type i=0; i != imgs.size(); i++){
Mat input = imgs[i];
vector<KeyPoint> keypoints;
detector->detect(input, keypoints);
cout << "Image #KeyPoints : " << keypoints.size() << endl;
}
}
bool has_suffix(const std::string &str, const std::string &suffix)
{
return str.size() >= suffix.size() &&
str.compare(str.size() - suffix.size(), suffix.size(), suffix) == 0;
}