forked from mogvision/FFD
-
Notifications
You must be signed in to change notification settings - Fork 0
/
match_pairs.py
83 lines (65 loc) · 2.52 KB
/
match_pairs.py
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
import os
import sys
import time
import cv2
from threading import Thread
from os.path import isfile, join
import numpy as np
from tempfile import TemporaryFile
from os import listdir
import string
import argparse
import subprocess
import time
from util.util import Matching_FFD_keypoints, readkp
if __name__ == '__main__':
curr_dir = os.getcwd()
parser = argparse.ArgumentParser(description='Feature Detection by FFD')
parser.add_argument(
'--NUM_show_matches', type=int, default=100,
help='Number of matches shown in the output')
parser.add_argument(
'--input_pairs', type=str, default='image',
help='Path to the images')
parser.add_argument(
'--max_keypoints', type=int, default=10000,
help='Maximum number of keypoints detected by FFD'
' (\'-1\' keeps all keypoints)')
parser.add_argument(
'--num_level', type=int, default=3,
help='Number of decomposition levels')
parser.add_argument(
'--contrast_threshold', type=float, default=0.05,
help='FFD\'s contrast threshold')
parser.add_argument(
'--curvature_ratio', type=float, default=10.,
help='FFD\'s curvature ratio')
parser.add_argument(
'--time_cost', type=int, default=0,
help='Report running time over 25 runs'
' (\'-1\' doesn\' report time')
opt = parser.parse_args()
print(opt)
KPTS_FFD = []
IMGs = []
image_formats = [".jpg", ".png", ".ppm", ".pgm"]
for image_name in os.listdir(opt.input_pairs):
ext = os.path.splitext(image_name)[1]
if ext.lower() in image_formats:
image_dir = os.path.join(curr_dir, opt.input_pairs, image_name)
store_dir = os.path.join(curr_dir, opt.input_pairs)
IMGs.append(image_dir)
process = subprocess.Popen('./FFD '+ str(os.path.join(curr_dir, opt.input_pairs, image_name)) + ' ' \
+ str(store_dir) + ' ' \
+ str(opt.num_level) + ' ' \
+ str(opt.max_keypoints) + ' ' \
+ str(opt.contrast_threshold) + ' ' \
+ str(opt.curvature_ratio) + ' '\
+ str(opt.time_cost),
shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
stdout, stderr = process.communicate()
keypoints, num_kp = readkp(os.path.join(store_dir, 'FFD_'+image_name+'.txt'))
KPTS_FFD.append(keypoints)
Matching_FFD_keypoints(IMGs, KPTS_FFD, opt.NUM_show_matches)