def __init__(self, data_path): """ Create dataset instance. Empty directories (for EXIF, matches, etc) will be created if they don't exist already. :param data_path: Path to directory containing dataset """ self.data_path = data_path # Load configuration. config_file = os.path.join(self.data_path, 'config.yaml') if os.path.isfile(config_file): with open(config_file) as fin: self.config = yaml.load(fin) else: self.config = {} # Load list of images. image_list_file = os.path.join(self.data_path, 'image_list.txt') if os.path.isfile(image_list_file): with open(image_list_file) as fin: lines = fin.read().splitlines() self.set_image_list(lines) else: self.set_image_path(os.path.join(self.data_path, 'images')) # Create output folders. for p in [ self.__exif_path(), self.__feature_path(), self.__matches_path() ]: io.mkdir_p(p)
def save_epipolar(self, im1, im2, R, t, X=[], inliers=[]): io.mkdir_p(self.__epipolar_path()) np.savez(self.__epipolar_file(im1, im2), R=R, t=t, X=X, inliers=inliers)
def __init__(self, data_path): """ Create dataset instance. Empty directories (for EXIF, matches, etc) will be created if they don't exist already. :param data_path: Path to directory containing dataset """ self.data_path = data_path # Load configuration. config_file = os.path.join(self.data_path, 'config.yaml') if os.path.isfile(config_file): with open(config_file) as fin: self.config = yaml.load(fin) else: self.config = {} # Load list of images. image_list_file = os.path.join(self.data_path, 'image_list.txt') if os.path.isfile(image_list_file): with open(image_list_file) as fin: lines = fin.read().splitlines() self.set_image_list(lines) else: self.set_image_path(os.path.join(self.data_path, 'images')) # Create output folders. for p in [self.__exif_path(), self.__feature_path(), self.__matches_path()]: io.mkdir_p(p)
def import_video_with_gpx(video_file, gpx_file, output_path, dx, dt=None, start_time=None, visual=False, image_description=None): points = geotag_from_gpx.get_lat_lon_time(gpx_file) orientation = video_orientation(video_file) if start_time: video_start_time = dateutil.parser.parse(start_time) else: try: exifdate = Popen(['exiftool', '-CreateDate', '-b', video_file], stdout=PIPE).stdout.read() video_start_time = datetime.datetime.strptime(exifdate,'%Y:%m:%d %H:%M:%S') except: print 'Video recording timestamp not found. Using first GPS point time.' video_start_time = points[0][0] try: duration = Popen(['exiftool', '-MediaDuration', '-b', video_file], stdout=PIPE).stdout.read() video_duration = float(duration) video_end_time = video_start_time + datetime.timedelta(seconds=video_duration) except: print 'Video end time not found. Using last GPS point time.' video_end_time = points[-1][0] print 'GPS track starts at:', points[0][0] print 'Video starts at:', video_start_time # Extract video frames. io.mkdir_p(output_path) key_points = geotag_from_gpx.sample_gpx(points, dx, dt) cap = cv2.VideoCapture(video_file) image_files = [] for p in key_points: dt = (p[0] - video_start_time).total_seconds() if dt > 0: CAP_PROP_POS_MSEC = cv2.CAP_PROP_POS_MSEC if context.OPENCV3 else cv2.cv.CV_CAP_PROP_POS_MSEC cap.set(CAP_PROP_POS_MSEC, int(dt * 1000)) ret, frame = cap.read() if ret: print 'Grabbing frame for time', p[0] filepath = os.path.join(output_path, p[0].strftime("%Y_%m_%d_%H_%M_%S_%f")[:-3] + '.jpg') cv2.imwrite(filepath, frame) geotag_from_gpx.add_exif_using_timestamp(filepath, points, timestamp=p[0], orientation=orientation) # Display the resulting frame if visual: # Display the resulting frame max_display_size = 800 resize_ratio = float(max_display_size) / max(frame.shape[0], frame.shape[1]) frame = cv2.resize(frame, dsize=(0, 0), fx=resize_ratio, fy=resize_ratio) cv2.imshow('frame', frame) if cv2.waitKey(1) & 0xFF == 27: break image_files.append(filepath) # When everything done, release the capture cap.release() if visual: cv2.destroyAllWindows() return image_files
def import_video_with_gpx(video_file, gpx_file, output_path, dx, dt=None, start_time=None, visual=False, image_description=None): points = geotag_from_gpx.get_lat_lon_time(gpx_file) orientation = video_orientation(video_file) if start_time: video_start_time = dateutil.parser.parse(start_time) else: try: exifdate = Popen(['exiftool', '-CreateDate', '-b', video_file], stdout=PIPE).stdout.read() video_start_time = datetime.datetime.strptime( exifdate, '%Y:%m:%d %H:%M:%S') except: print 'Video recording timestamp not found. Using first GPS point time.' video_start_time = points[0][0] try: duration = Popen(['exiftool', '-MediaDuration', '-b', video_file], stdout=PIPE).stdout.read() video_duration = float(duration) video_end_time = video_start_time + datetime.timedelta( seconds=video_duration) except: print 'Video end time not found. Using last GPS point time.' video_end_time = points[-1][0] print 'GPS track starts at:', points[0][0] print 'Video starts at:', video_start_time # Extract video frames. io.mkdir_p(output_path) key_points = geotag_from_gpx.sample_gpx(points, dx, dt) cap = cv2.VideoCapture(video_file) image_files = [] for p in key_points: dt = (p[0] - video_start_time).total_seconds() if dt > 0: CAP_PROP_POS_MSEC = cv2.CAP_PROP_POS_MSEC if context.OPENCV3 else cv2.cv.CV_CAP_PROP_POS_MSEC cap.set(CAP_PROP_POS_MSEC, int(dt * 1000)) ret, frame = cap.read() if ret: print 'Grabbing frame for time', p[0] filepath = os.path.join( output_path, p[0].strftime("%Y_%m_%d_%H_%M_%S_%f")[:-3] + '.jpg') cv2.imwrite(filepath, frame) geotag_from_gpx.add_exif_using_timestamp( filepath, points, timestamp=p[0], orientation=orientation) # Display the resulting frame if visual: # Display the resulting frame max_display_size = 800 resize_ratio = float(max_display_size) / max( frame.shape[0], frame.shape[1]) frame = cv2.resize(frame, dsize=(0, 0), fx=resize_ratio, fy=resize_ratio) cv2.imshow('frame', frame) if cv2.waitKey(1) & 0xFF == 27: break image_files.append(filepath) # When everything done, release the capture cap.release() if visual: cv2.destroyAllWindows() return image_files
def save_report(self, report_str, path): """Save report string to a file.""" filepath = os.path.join(self._report_path(), path) io.mkdir_p(os.path.dirname(filepath)) with io.open_wt(filepath) as fout: return fout.write(report_str)
def save_matches(self, image, matches): io.mkdir_p(self._matches_path()) with gzip.open(self._matches_file(image), 'wb') as fout: pickle.dump(matches, fout)
def _save_features(self, filepath, points, descriptors, colors=None): io.mkdir_p(self._feature_path()) features.save_features(filepath, points, descriptors, colors, self.config)