Exemplo n.º 1
0
    def export(self, reconstruction, graph, data):
        exporter = csfm.OpenMVSExporter()
        for camera in reconstruction.cameras.values():
            if camera.projection_type == 'perspective':
                w, h = camera.width, camera.height
                K = np.array([
                    [camera.focal, 0, (w - 1.0) / 2 / max(w, h)],
                    [0, camera.focal, (h - 1.0) / 2 / max(w, h)],
                    [0, 0, 1],
                ])
                exporter.add_camera(str(camera.id), K)

        for shot in reconstruction.shots.values():
            if shot.camera.projection_type == 'perspective':
                image_path = data._undistorted_image_file(shot.id)
                exporter.add_shot(str(os.path.abspath(image_path)),
                                  str(shot.id), str(shot.camera.id),
                                  shot.pose.get_rotation_matrix(),
                                  shot.pose.get_origin())

        for point in reconstruction.points.values():
            shots = graph[point.id].keys()
            coordinates = np.array(point.coordinates, dtype=np.float64)
            exporter.add_point(coordinates, shots)

        opensfm_io.mkdir_p(data.data_path + '/openmvs')
        exporter.export(data.data_path + '/openmvs/scene.mvs')
Exemplo n.º 2
0
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.
    opensfm_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
Exemplo n.º 3
0
 def __save_features(self, filepath, image, points, descriptors, colors=None):
     opensfm_io.mkdir_p(self.__feature_path())
     feature_type = self.config.get('feature_type')
     if ((feature_type == 'AKAZE' and self.config.get('akaze_descriptor') in ['MLDB_UPRIGHT', 'MLDB']) or
         (feature_type == 'HAHOG' and self.config.get('hahog_normalize_to_uchar', False))):
         feature_data_type = np.uint8
     else:
         feature_data_type = np.float32
     np.savez_compressed(filepath,
              points=points.astype(np.float32),
              descriptors=descriptors.astype(feature_data_type),
              colors=colors)
Exemplo n.º 4
0
 def save_raw_depthmap(self, image, depth, plane, score):
     opensfm_io.mkdir_p(self._depthmap_path())
     filepath = self._depthmap_file(image, 'raw.npz')
     np.savez_compressed(filepath, depth=depth, plane=plane, score=score)
Exemplo n.º 5
0
 def save_undistorted_image(self, image, array):
     opensfm_io.mkdir_p(self._undistorted_image_path())
     cv2.imwrite(self._undistorted_image_file(image), array[:, :, ::-1])
Exemplo n.º 6
0
 def save_matches(self, image, matches):
     opensfm_io.mkdir_p(self.__matches_path())
     with gzip.open(self.__matches_file(image), 'wb') as fout:
         pickle.dump(matches, fout)
Exemplo n.º 7
0
 def save_exif(self, image, data):
     opensfm_io.mkdir_p(self.__exif_path())
     with open(self.__exif_file(image), 'w') as fout:
         opensfm_io.json_dump(data, fout)