forked from JosephP91/obstacle-avoidance
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsift.py
30 lines (26 loc) · 1.16 KB
/
sift.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
import cv2
from time import time
from base import FeatureExtractorThread
from utils import save_image, debug
class SIFTThread(FeatureExtractorThread):
def __init__(self, image_path, name, config):
super(SIFTThread, self).__init__(image_path, name)
self.results = None
self.config = config
def run(self):
sift = cv2.SIFT(self.config.get('points'), self.config.get('levels'))
start_time = time()
keypoints, descriptors = sift.detectAndCompute(self.image, None)
debug("SIFT time: {} seconds.".format(time() - start_time))
self.results = {'img': self.image, 'ext': self.extension, 'kp': keypoints, 'desc': descriptors}
image = cv2.drawKeypoints(self.image, keypoints)
save_image(image, self.name, self.extension)
def join(self, timeout=None):
"""
Override del metodo join, che effettua dapprima il joining del thread e poi ritorna i risultati
della computazione precedente.
:param timeout: eventuale timeout di connessione.
:return: i risultati della computazione.
"""
super(SIFTThread, self).join(timeout)
return self.results