コード例 #1
0
ファイル: exifedit.py プロジェクト: mapicam/mapicam
def create_mapillary_description(filename,
                                 username,
                                 email,
                                 upload_hash,
                                 sequence_uuid,
                                 interpolated_heading=None,
                                 orientation=1,
                                 verbose=False):
    '''
    Check that image file has the required EXIF fields.

    Incompatible files will be ignored server side.
    '''
    # read exif
    exif = EXIF(filename)

    if not verify_exif(filename):
        return False

    # write the mapillary tag
    mapillary_description = {}
    mapillary_description["MAPLongitude"], mapillary_description[
        "MAPLatitude"] = exif.extract_lon_lat()
    #required date format: 2015_01_14_09_37_01_000
    mapillary_description["MAPCaptureTime"] = datetime.datetime.strftime(
        exif.extract_capture_time(), "%Y_%m_%d_%H_%M_%S_%f")[:-3]
    mapillary_description["MAPOrientation"] = exif.extract_orientation()
    heading = exif.extract_direction()
    if heading is None:
        heading = 0.0
    heading = normalize_bearing(
        interpolated_heading
    ) if interpolated_heading is not None else normalize_bearing(heading)
    mapillary_description["MAPCompassHeading"] = {
        "TrueHeading": heading,
        "MagneticHeading": heading
    }
    mapillary_description["MAPSettingsUploadHash"] = upload_hash
    mapillary_description["MAPSettingsEmail"] = email
    mapillary_description["MAPSettingsUsername"] = username
    settings_upload_hash = hashlib.sha256(
        "%s%s%s" %
        (upload_hash, email, base64.b64encode(filename))).hexdigest()
    mapillary_description['MAPSettingsUploadHash'] = settings_upload_hash
    mapillary_description['MAPPhotoUUID'] = str(uuid.uuid4())
    mapillary_description['MAPSequenceUUID'] = str(sequence_uuid)
    mapillary_description['MAPDeviceModel'] = exif.extract_model()
    mapillary_description['MAPDeviceMake'] = exif.extract_make()

    # write to file
    json_desc = json.dumps(mapillary_description)
    if verbose:
        print "tag: {0}".format(json_desc)
    metadata = ExifEdit(filename)
    metadata.add_image_description(json_desc)
    metadata.add_orientation(orientation)
    metadata.add_direction(heading)
    metadata.write()
コード例 #2
0
ファイル: sequence.py プロジェクト: chrmorais/mapillary_tools
 def get_file_list(self, filepath, check_exif=True):
     '''
     Get the list of JPEGs in the folder (nested folders)
     '''
     if filepath.lower().endswith(".jpg"):
         # single file
         file_list = [filepath]
     else:
         file_list = []
         for root, sub_folders, files in os.walk(self.filepath):
             if not self._is_skip(root):
                 file_list += [os.path.join(root, filename) for filename in files
                                 if (filename.lower().endswith(".jpg")) and (verify_exif(os.path.join(root, filename)) or not check_exif)]
     return file_list
コード例 #3
0
ファイル: exifedit.py プロジェクト: Caboosey/mapillary_tools
def create_mapillary_description(filename, username, email,
                                 upload_hash, sequence_uuid,
                                 interpolated_heading=None,
                                 orientation=1,
                                 verbose=False):
    '''
    Check that image file has the required EXIF fields.

    Incompatible files will be ignored server side.
    '''
    # read exif
    exif = EXIF(filename)

    if not verify_exif(filename):
        return False

    # write the mapillary tag
    mapillary_description = {}
    mapillary_description["MAPLongitude"], mapillary_description["MAPLatitude"] = exif.extract_lon_lat()
    #required date format: 2015_01_14_09_37_01_000
    mapillary_description["MAPCaptureTime"] = datetime.datetime.strftime(exif.extract_capture_time(), "%Y_%m_%d_%H_%M_%S_%f")[:-3]
    mapillary_description["MAPOrientation"] = exif.extract_orientation()
    heading = exif.extract_direction()
    if heading is None:
        heading = 0.0
    heading = normalize_bearing(interpolated_heading) if interpolated_heading is not None else normalize_bearing(heading)
    mapillary_description["MAPCompassHeading"] = {"TrueHeading": heading, "MagneticHeading": heading}
    mapillary_description["MAPSettingsUploadHash"] = upload_hash
    mapillary_description["MAPSettingsEmail"] = email
    mapillary_description["MAPSettingsUsername"] = username
    settings_upload_hash = hashlib.sha256("%s%s%s" % (upload_hash, email, base64.b64encode(filename))).hexdigest()
    mapillary_description['MAPSettingsUploadHash'] = settings_upload_hash
    mapillary_description['MAPPhotoUUID'] = str(uuid.uuid4())
    mapillary_description['MAPSequenceUUID'] = str(sequence_uuid)
    mapillary_description['MAPDeviceModel'] = exif.extract_model()
    mapillary_description['MAPDeviceMake'] = exif.extract_make()

    # write to file
    json_desc = json.dumps(mapillary_description)
    if verbose:
        print "tag: {0}".format(json_desc)
    metadata = ExifEdit(filename)
    metadata.add_image_description(json_desc)
    metadata.add_orientation(orientation)
    metadata.add_direction(heading)
    metadata.write()
コード例 #4
0
 def get_file_list(self, filepath, check_exif=True):
     '''
     Get the list of JPEGs in the folder (nested folders)
     '''
     if filepath.lower().endswith(".jpg"):
         # single file
         file_list = [filepath]
     else:
         file_list = []
         for root, sub_folders, files in os.walk(self.filepath):
             if not self._is_skip(root):
                 image_files = [
                     os.path.join(root, filename) for filename in files
                     if (filename.lower().endswith(".jpg"))
                 ]
                 if check_exif:
                     image_files = [
                         f for f in image_files if verify_exif(f)
                     ]
                 file_list += image_files
     return file_list
コード例 #5
0
    if len(s.file_list) == 0:
        print("No images in the folder or all images have all ready been uploaded to Mapillary")
        print(
            'Note: If upload fails mid-sequence due to connection failure or similar, you should manually push the images to the server at http://www.mapillary.com/map/upload/im/ and pressing "push to Mapillary".'
        )
        sys.exit()

    print("Uploading sequence {0}.".format(sequence_id))
    # check mapillary tag and required exif
    file_list = []
    for filepath in s.file_list:
        mapillary_tag_exists = EXIF(filepath).mapillary_tag_exists()
        if mapillary_tag_exists:
            print("File {} contains Mapillary EXIF tags, use upload.py instead.".format(filepath))

        required_exif_exist = verify_exif(filepath)
        if not required_exif_exist:
            print("File {} missing required exif".format(filepath))

        if required_exif_exist and (not mapillary_tag_exists):
            file_list.append(filepath)

    # upload valid files
    upload_file_list(file_list, params)

    # ask user if finalize upload to check that everything went fine
    print(
        "===\nFinalizing upload will submit all successful uploads and ignore all failed.\nIf all files were marked as successful, everything is fine, just press 'y'."
    )
    finalize_upload(params)
コード例 #6
0
                             skip_folders=['duplicates', 'success'],
                             skip_subfolders=True)

                # interpolate compass direction if missing
                directions = s.interpolate_direction()

                # Add a sequence uuid per sub-folder
                if len(s.file_list) > 0:
                    sequence_uuid = uuid.uuid4()
                    print("  sequence uuid: {}".format(sequence_uuid))

                file_list = []
                for i, filename in enumerate(s.file_list):
                    if is_image(filename):
                        filepath = os.path.join(filename)
                        if verify_exif(filepath):
                            if not retry_upload:
                                # skip creating new sequence id for failed images
                                create_mapillary_description(
                                    filepath, MAPILLARY_USERNAME,
                                    MAPILLARY_EMAIL, upload_token,
                                    sequence_uuid, directions[filepath])
                            file_list.append(filepath)
                        else:
                            missing_groups.append(filepath)
                    else:
                        print "   Ignoring {0}".format(
                            os.path.join(root, filename))
                    lib.io.progress(i, len(s.file_list),
                                    'Adding Mapillary tags')
                count = len(file_list)
コード例 #7
0
def create_mapillary_description(filename,
                                 username,
                                 email,
                                 userkey,
                                 upload_hash,
                                 sequence_uuid,
                                 interpolated_heading=None,
                                 offset_angle=0.0,
                                 timestamp=None,
                                 orientation=None,
                                 project="",
                                 secret_hash=None,
                                 external_properties=None,
                                 verbose=False,
                                 make="",
                                 model=""):
    '''
    Check that image file has the required EXIF fields.

    Incompatible files will be ignored server side.
    '''
    # read exif
    exif = EXIF(filename)

    if not verify_exif(filename):
        return False

    if orientation is None:
        orientation = exif.extract_orientation()

    # write the mapillary tag
    mapillary_description = {}

    # lat, lon of the image, takes precedence over EXIF GPS values
    mapillary_description["MAPLongitude"], mapillary_description[
        "MAPLatitude"] = exif.extract_lon_lat()

    # altitude of the image, takes precedence over EXIF GPS values, assumed 0
    # if missing
    mapillary_description["MAPAltitude"] = exif.extract_altitude()

    # capture time: required date format: 2015_01_14_09_37_01_000, TZ MUST be
    # UTC
    if timestamp is None:
        timestamp = exif.extract_capture_time()

    # The capture time of the image in UTC. Will take precedence over any
    # other time tags in the EXIF
    mapillary_description["MAPCaptureTime"] = datetime.datetime.strftime(
        timestamp, "%Y_%m_%d_%H_%M_%S_%f")[:-3]

    # EXIF orientation of the image
    mapillary_description["MAPOrientation"] = orientation
    heading = exif.extract_direction()

    if heading is None:
        heading = 0.0
    heading = normalize_bearing(
        interpolated_heading + offset_angle
    ) if interpolated_heading is not None else normalize_bearing(heading +
                                                                 offset_angle)

    # bearing of the image
    mapillary_description["MAPCompassHeading"] = {
        "TrueHeading": heading,
        "MagneticHeading": heading
    }

    # authentication
    assert (email is not None or userkey is not None)
    if email is not None:
        mapillary_description["MAPSettingsEmail"] = email
    if username is not None:
        mapillary_description["MAPSettingsUsername"] = username

    # use this if available, and omit MAPSettingsUsername and MAPSettingsEmail
    # for privacy reasons
    if userkey is not None:
        mapillary_description["MAPSettingsUserKey"] = userkey
    if upload_hash is not None:
        settings_upload_hash = hashlib.sha256(
            "%s%s%s" %
            (upload_hash, email, base64.b64encode(filename))).hexdigest()
        # this is not checked in the backend right now, will likely be changed to have user_key instead of email as part
        # of the hash
        mapillary_description['MAPSettingsUploadHash'] = settings_upload_hash

    # a unique photo ID to check for duplicates in the backend in case the
    # image gets uploaded more than once
    mapillary_description['MAPPhotoUUID'] = str(uuid.uuid4())
    # a sequene ID to make the images go together (order by MAPCaptureTime)
    mapillary_description['MAPSequenceUUID'] = str(sequence_uuid)

    # The device manufacturer
    if make:
        mapillary_description['MAPDeviceMake'] = make
    else:
        mapillary_description['MAPDeviceMake'] = exif.extract_make()

    # The device model
    if model:
        mapillary_description['MAPDeviceModel'] = model
    else:
        mapillary_description['MAPDeviceModel'] = exif.extract_model()

    if upload_hash is None and secret_hash is not None:
        mapillary_description['MAPVideoSecure'] = secret_hash

    if project:
        mapillary_description["MAPSettingsProject"] = project

    # external properties (optional)
    if external_properties is not None:
        # externl proerties can be saved and searched in Mapillary later on
        mapillary_description['MAPExternalProperties'] = external_properties

    if make:
        mapillary_description['MAPDeviceMake'] = make

    if model:
        mapillary_description['MAPDeviceModel'] = model
    # write to file
    if verbose:
        print("tag: {0}".format(mapillary_description))
    metadata = ExifEdit(filename)
    metadata.add_image_description(mapillary_description)
    metadata.add_orientation(orientation)
    metadata.add_direction(heading)
    metadata.write()
コード例 #8
0
                if len(s.file_list) > 0:
                    sequence_uuid = uuid.uuid4()
                    print("  sequence uuid: {}".format(sequence_uuid))

                file_list = []
                for i, filename in enumerate(s.file_list):
                    if is_image(filename):
                        filepath = os.path.join(filename)

                        # Determine whether use interpolated direction or not
                        if interpolate_directions and len(s.file_list) > 1:
                            bearing = directions[filepath]
                        else:
                            bearing = None

                        if verify_exif(filepath):
                            if not retry_upload:
                                # skip creating new sequence id for failed images
                                create_mapillary_description(filepath,
                                                             MAPILLARY_USERNAME,
                                                             MAPILLARY_EMAIL,
                                                             upload_token,
                                                             sequence_uuid,
                                                             bearing,
                                                             orientation)
                            file_list.append(filepath)
                        else:
                            missing_groups.append(filepath)
                    else:
                        print "   Ignoring {0}".format(os.path.join(root, filename))
                    lib.io.progress(i, len(s.file_list), 'Adding Mapillary tags')
コード例 #9
0
    # Caution: all nested folders will be merged into one sequence!
    s = Sequence(path, skip_folders=['success', 'duplicates'], skip_subfolders=skip_subfolders)

    if len(s.file_list) == 0:
        print('No images in the folder or all images have all ready been uploaded to Mapillary')
        print('Note: If upload fails mid-sequence due to connection failure or similar, you should manually push the images to the server at http://www.mapillary.com/map/upload/im/ and pressing "push to Mapillary".')
        sys.exit()

    print("Uploading sequence {0}.".format(sequence_id))

    # check mapillary tag and required exif
    file_list = []
    for filepath in s.file_list:
        mapillary_tag_exists = EXIF(filepath).mapillary_tag_exists()
        if mapillary_tag_exists:
            print("File {} contains Mapillary EXIF tags, use upload.py instead.".format(filepath))

        required_exif_exist = verify_exif(filepath)
        if not required_exif_exist:
            print("File {} missing required exif".format(filepath))

        if required_exif_exist and (not mapillary_tag_exists):
            file_list.append(filepath)

    #upload valid files
    upload_file_list(file_list, params)

    # ask user if finalize upload to check that everything went fine
    print("===\nFinalizing upload will submit all successful uploads and ignore all failed.\nIf all files were marked as successful, everything is fine, just press 'y'.")
    finalize_upload(params)
コード例 #10
0
ファイル: exifedit.py プロジェクト: habi/mapillary_tools
def create_mapillary_description(filename,
                                 username,
                                 email,
                                 userkey,
                                 upload_hash,
                                 sequence_uuid,
                                 interpolated_heading=None,
                                 offset_angle=0.0,
                                 timestamp=None,
                                 orientation=None,
                                 project="",
                                 secret_hash=None,
                                 external_properties=None,
                                 verbose=False):
    '''
    Check that image file has the required EXIF fields.

    Incompatible files will be ignored server side.
    '''
    # read exif
    exif = EXIF(filename)

    if not verify_exif(filename):
        return False

    if orientation is None:
        orientation = exif.extract_orientation()

    # write the mapillary tag
    mapillary_description = {}
    mapillary_description["MAPLongitude"], mapillary_description[
        "MAPLatitude"] = exif.extract_lon_lat()
    mapillary_description["MAPAltitude"] = exif.extract_altitude()

    # capture time: required date format: 2015_01_14_09_37_01_000
    if timestamp is None:
        timestamp = exif.extract_capture_time()
    mapillary_description["MAPCaptureTime"] = datetime.datetime.strftime(
        timestamp, "%Y_%m_%d_%H_%M_%S_%f")[:-3]
    mapillary_description["MAPOrientation"] = orientation
    heading = exif.extract_direction()

    if heading is None:
        heading = 0.0
    heading = normalize_bearing(
        interpolated_heading + offset_angle
    ) if interpolated_heading is not None else normalize_bearing(heading +
                                                                 offset_angle)
    mapillary_description["MAPCompassHeading"] = {
        "TrueHeading": heading,
        "MagneticHeading": heading
    }

    # authentication
    assert (email is not None or userkey is not None)
    if email is not None:
        mapillary_description["MAPSettingsEmail"] = email
    if username is not None:
        mapillary_description["MAPSettingsUsername"] = username
    if userkey is not None:
        mapillary_description["MAPSettingsUserKey"] = userkey
    if upload_hash is not None:
        settings_upload_hash = hashlib.sha256(
            "%s%s%s" %
            (upload_hash, email, base64.b64encode(filename))).hexdigest()
        mapillary_description['MAPSettingsUploadHash'] = settings_upload_hash

    mapillary_description['MAPPhotoUUID'] = str(uuid.uuid4())
    mapillary_description['MAPSequenceUUID'] = str(sequence_uuid)
    mapillary_description['MAPDeviceModel'] = exif.extract_model()
    mapillary_description['MAPDeviceMake'] = exif.extract_make()
    if upload_hash is None and secret_hash is not None:
        mapillary_description['MAPVideoSecure'] = secret_hash

    mapillary_description["MAPSettingsProject"] = project

    # external properties
    if external_properties is not None:
        mapillary_description['MAPExternalProperties'] = external_properties

    # write to file
    if verbose:
        print("tag: {0}".format(mapillary_description))
    metadata = ExifEdit(filename)
    metadata.add_image_description(mapillary_description)
    metadata.add_orientation(orientation)
    metadata.add_direction(heading)
    metadata.write()