예제 #1
0
def gpx_from_blackvue(bv_video):
    bv_data = []

    if os.path.isdir(bv_video):
        video_files = uploader.get_video_file_list(bv_video)
        for video in video_files:
            try:
                bv_data += get_points_from_bv(video)
            except Exception as e:
                print(
                    "Warning, could not extract gps from video {} due to {}, video will be skipped..."
                    .format(video, e))

        dirname = os.path.dirname(bv_video)
        basename = os.path.basename(bv_video)
        gpx_path = os.path.join(dirname, basename + '.gpx')
    else:
        try:
            bv_data = get_points_from_bv(bv_video)
        except Exception as e:
            print(
                "Warning, could not extract gps from video {} due to {}, video will be skipped..."
                .format(bv_video, e))
        basename, extension = os.path.splitext(bv_video)
        gpx_path = basename + '.gpx'

    bv_data.sort(key=lambda x: x[0])

    write_gpx(gpx_path, bv_data)

    return gpx_path
예제 #2
0
def sample_video(video_import_path,
                 import_path,
                 video_sample_interval=2.0,
                 video_start_time=None,
                 video_duration_ratio=1.0,
                 verbose=False,
                 skip_subfolders=False):

    if import_path and not os.path.isdir(import_path):
        print("Error, import directory " + import_path +
              " does not exist, exiting...")  # ERROR LOG
        sys.exit(1)

    # sanity check
    if not os.path.isdir(video_import_path) and not os.path.isfile(
            video_import_path):
        print("Error, video path " + video_import_path +
              " does not exist, exiting...")
        sys.exit(1)

    # Adjust the import path
    video_sampling_path = "mapillary_sampled_video_frames"
    video_dirname = video_import_path if os.path.isdir(
        video_import_path) else os.path.dirname(video_import_path)
    import_path = os.path.join(
        os.path.abspath(import_path),
        video_sampling_path) if import_path else os.path.join(
            os.path.abspath(video_dirname), video_sampling_path)

    video_list = uploader.get_video_file_list(
        video_import_path, skip_subfolders) if os.path.isdir(
            video_import_path) else [video_import_path]

    for video in tqdm(video_list, desc="Extracting video frames"):

        per_video_import_path = os.path.join(
            import_path, ".".join(os.path.basename(video).split(".")[:-1]))
        if not os.path.isdir(per_video_import_path):
            os.makedirs(per_video_import_path)

        print("Video sampling path set to {}".format(per_video_import_path))
        # check video logs
        video_upload = processing.video_upload(video_import_path,
                                               per_video_import_path, verbose)
        if video_upload:
            print(
                "Video {} has already been uploaded, contact support@mapillary for help with reuploading it if neccessary."
                .format(video))

        extract_frames(video, per_video_import_path, video_sample_interval,
                       video_start_time, video_duration_ratio, verbose)

    processing.create_and_log_video_process(video_import_path, import_path)
예제 #3
0
def sample_video(video_file,
                 import_path,
                 video_sample_interval=2.0,
                 video_start_time=None,
                 video_duration_ratio=1.0,
                 verbose=False):

    if import_path and not os.path.isdir(import_path):
        print("Error, import directory " + import_path +
              " does not exist, exiting...")
        sys.exit(1)

    # command specific checks
    video_file = os.path.abspath(video_file) if (
        os.path.isfile(video_file) or os.path.isdir(video_file)) else None
    if not video_file:
        print("Error, video path " + video_file + " does not exist, exiting...")
        sys.exit(1)

    # set sampling path
    video_sampling_path = processing.sampled_video_frames_rootpath(video_file)
    import_path = os.path.join(os.path.abspath(import_path), video_sampling_path) if import_path else os.path.join(
        os.path.dirname(video_file), video_sampling_path)
    print("Video sampling path set to {}".format(import_path))

    # check video logs
    video_upload = processing.video_upload(video_file, import_path, verbose)

    if video_upload:
        return

    if os.path.isdir(video_file):

        video_list = uploader.get_video_file_list(video_file)
        for video in video_list:
            extract_frames(video,
                           import_path,
                           video_sample_interval,
                           video_start_time,
                           video_duration_ratio,
                           verbose)
    else:
        # single video file
        extract_frames(video_file,
                       import_path,
                       video_sample_interval,
                       video_start_time,
                       video_duration_ratio,
                       verbose)

    processing.create_and_log_video_process(video_file, import_path)
예제 #4
0
def sample_video(video_import_path,
                 import_path,
                 video_sample_interval=2.0,
                 video_start_time=None,
                 video_duration_ratio=1.0,
                 verbose=False,
                 skip_subfolders=False):

    if import_path and not os.path.isdir(import_path):
        print("Error, import directory " + import_path +
              " does not exist, exiting...")  # ERROR LOG
        sys.exit(1)

    # sanity check
    if not os.path.isdir(video_import_path) and not os.path.isfile(video_import_path):
        print("Error, video path " + video_import_path +
              " does not exist, exiting...")
        sys.exit(1)

    # Adjust the import path
    video_sampling_path = "mapillary_sampled_video_frames"
    video_dirname = video_import_path if os.path.isdir(
        video_import_path) else os.path.dirname(video_import_path)
    import_path = os.path.join(os.path.abspath(import_path), video_sampling_path) if import_path else os.path.join(
        os.path.abspath(video_dirname), video_sampling_path)

    video_list = uploader.get_video_file_list(video_import_path, skip_subfolders) if os.path.isdir(
        video_import_path) else [video_import_path]

    for video in tqdm(video_list, desc="Extracting video frames"):

        per_video_import_path = os.path.join(
            import_path, ".".join(os.path.basename(video).split(".")[:-1]))
        if not os.path.isdir(per_video_import_path):
            os.makedirs(per_video_import_path)

        print("Video sampling path set to {}".format(per_video_import_path))
        # check video logs
        video_upload = processing.video_upload(
            video_import_path, per_video_import_path, verbose)
        if video_upload:
            print("Video {} has already been uploaded, contact support@mapillary for help with reuploading it if neccessary.".format(video))

        extract_frames(video,
                       per_video_import_path,
                       video_sample_interval,
                       video_start_time,
                       video_duration_ratio,
                       verbose)

    processing.create_and_log_video_process(video_import_path, import_path)
예제 #5
0
def geotag_from_blackvue_video(process_file_list,
                               import_path,
                               geotag_source_path,
                               offset_time,
                               offset_angle,
                               local_time,
                               sub_second_interval,
                               use_gps_start_time=False,
                               verbose=False):

    # for each video, create gpx trace and geotag the corresponding video
    # frames
    blackvue_videos = uploader.get_video_file_list(geotag_source_path)
    for blackvue_video in blackvue_videos:
        blackvue_video_filename = os.path.basename(blackvue_video).replace(
            ".mp4", "").replace(".MP4", "")
        try:
            [gpx_path, is_stationary_video] = gpx_from_blackvue(
                blackvue_video, use_nmea_stream_timestamp=False)
            if not gpx_path or not os.path.isfile(gpx_path):
                raise Exception
        except Exception as e:
            print_error("Error, failed extracting data from blackvue geotag source path {} due to {}, exiting...".format(
                blackvue_video, e))
        if is_stationary_video:
            print_error("Warning: Skipping stationary video")
            continue
        process_file_sublist = [x for x in process_file_list if os.path.join(
            blackvue_video_filename, blackvue_video_filename + "_") in x]

        if not len(process_file_sublist):
            print_error("Error, no video frames extracted for video file {} in import_path {}".format(
                blackvue_video, import_path))
            create_and_log_process_in_list(process_file_sublist,
                                           "geotag_process"
                                           "failed",
                                           verbose)
            continue

        geotag_from_gps_trace(process_file_sublist,
                              "gpx",
                              gpx_path,
                              offset_time,
                              offset_angle,
                              local_time,
                              sub_second_interval,
                              use_gps_start_time,
                              verbose)
예제 #6
0
def geotag_from_blackvue_video(process_file_list,
                               import_path,
                               geotag_source_path,
                               offset_time,
                               offset_angle,
                               local_time,
                               sub_second_interval,
                               use_gps_start_time=False,
                               verbose=False):

    # for each video, create gpx trace and geotag the corresponding video
    # frames
    blackvue_videos = uploader.get_video_file_list(geotag_source_path)
    for blackvue_video in blackvue_videos:
        blackvue_video_filename = os.path.basename(blackvue_video).replace(
            ".mp4", "").replace(".MP4", "")
        try:
            [gpx_path, is_stationary_video] = gpx_from_blackvue(
                blackvue_video, use_nmea_stream_timestamp=False)
            if not gpx_path or not os.path.isfile(gpx_path):
                raise Exception
        except Exception as e:
            print_error("Error, failed extracting data from blackvue geotag source path {} due to {}, exiting...".format(
                blackvue_video, e))
        if is_stationary_video:
            print_error("Warning: Skipping stationary video")
            continue
        process_file_sublist = [x for x in process_file_list if os.path.join(
            blackvue_video_filename, blackvue_video_filename + "_") in x]

        if not len(process_file_sublist):
            print_error("Error, no video frames extracted for video file {} in import_path {}".format(
                blackvue_video, import_path))
            create_and_log_process_in_list(process_file_sublist,
                                           "geotag_process"
                                           "failed",
                                           verbose)
            continue

        geotag_from_gps_trace(process_file_sublist,
                              "gpx",
                              gpx_path,
                              offset_time,
                              offset_angle,
                              local_time,
                              sub_second_interval,
                              use_gps_start_time,
                              verbose)
예제 #7
0
def geotag_from_gopro_video(process_file_list,
                            import_path,
                            geotag_source_path,
                            offset_time,
                            offset_angle,
                            local_time,
                            sub_second_interval,
                            use_gps_start_time=False,
                            verbose=False):

    # for each video, create gpx trace and geotag the corresponding video
    # frames
    gopro_videos = uploader.get_video_file_list(geotag_source_path)
    for gopro_video in gopro_videos:
        gopro_video_filename = os.path.basename(gopro_video).replace(
            ".mp4", "").replace(".MP4", "")
        try:
            gpx_path = gpx_from_gopro(gopro_video)
            if not gpx_path or not os.path.isfile(gpx_path):
                raise Exception
        except Exception as e:
            print_error("Error, failed extracting data from gopro geotag source path {} due to {}, exiting...".format(
                gopro_video, e))
            sys.exit(1)

        process_file_sublist = [x for x in process_file_list if os.path.join(
            gopro_video_filename, gopro_video_filename + "_") in x]

        if not len(process_file_sublist):
            print_error("Error, no video frames extracted for video file {} in import_path {}".format(
                gopro_video, import_path))
            create_and_log_process_in_list(process_file_sublist,
                                           "geotag_process"
                                           "failed",
                                           verbose)
            continue

        geotag_from_gps_trace(process_file_sublist,
                              "gpx",
                              gpx_path,
                              offset_time,
                              offset_angle,
                              local_time,
                              sub_second_interval,
                              use_gps_start_time,
                              verbose)
예제 #8
0
def sample_video(video_import_path,
                 import_path,
                 video_sample_interval=2.0,
                 video_start_time=None,
                 video_duration_ratio=1.0,
                 verbose=False):

    if import_path and not os.path.isdir(import_path):
        print("Error, import directory " + import_path +
              " does not exist, exiting...")
        sys.exit(1)

    # command specific checks
    video_import_path = os.path.abspath(video_import_path) if os.path.isdir(
        video_import_path) else None
    if not video_import_path:
        print(
            "Error, video import path " + video_import_path +
            " does not exist or is not a directory, please provide a path to a directory with the video(s) you wish to import, exiting..."
        )
        sys.exit(1)

    # set sampling path
    video_sampling_path = "mapillary_sampled_video_frames"
    import_path = os.path.join(
        os.path.abspath(import_path),
        video_sampling_path) if import_path else os.path.join(
            os.path.abspath(video_import_path), video_sampling_path)
    print("Video sampling path set to {}".format(import_path))

    # check video logs
    video_upload = processing.video_upload(video_import_path, import_path,
                                           verbose)

    if video_upload:
        return

    video_list = uploader.get_video_file_list(video_import_path)
    for video in tqdm(video_list, desc="Extracting video frames"):
        extract_frames(video, import_path, video_sample_interval,
                       video_start_time, video_duration_ratio, verbose)

    processing.create_and_log_video_process(video_import_path, import_path)
def gpx_from_blackvue(bv_video):
    bv_data = []

    if os.path.isdir(bv_video):
        video_files = uploader.get_video_file_list(bv_video)
        for video in video_files:
            bv_data += get_points_from_bv(video)

        dirname = os.path.dirname(bv_video)
        gpx_path = os.path.join(dirname, 'path.gpx')
    else:
        bv_data = get_points_from_bv(bv_video)
        basename, extension = os.path.splitext(bv_video)
        gpx_path = basename + '.gpx'

    bv_data.sort(key=lambda x: x[0])

    write_gpx(gpx_path, bv_data)

    return gpx_path