コード例 #1
0
ファイル: fr.py プロジェクト: RobotSe7en/FaceRec
def face_rec(fpath, names, known_faces, model='hog'):
    unknown_images = get_file_path(fpath)
    count = 0
    total = len(unknown_images)
    for i in unknown_images:
        count += 1
        try:
            im = Image(i)
        except:
            print('Pass ' + i)
            continue
        # im_xmp = im.read_xmp()
        # if 'Xmp.xmp.Keywords' in im_xmp.keys():
        # 	continue
        final_labels = ''
        xmp_labels = dict()
        xmp_labels.setdefault('Xmp.xmp.Keywords', '')
        unknown = face_recognition.load_image_file(i, pixel=1000)
        face_loc = face_recognition.face_locations(unknown, model=model)
        unknown_face_encoding = face_recognition.face_encodings(
            unknown, known_face_locations=face_loc)
        for f in unknown_face_encoding:
            dis = face_recognition.face_distance(known_faces, f)
            min_dis = min(dis)
            if min_dis <= 0.5:
                idx = dis.tolist().index(min_dis)
                label = names[idx] + ','
                xmp_labels['Xmp.xmp.Keywords'] = xmp_labels[
                    'Xmp.xmp.Keywords'] + label
                im.modify_xmp(xmp_labels)
                final_labels = im.read_xmp()['Xmp.xmp.Keywords']
        print(
            str(count) + '/' + str(total) + '  ' + i + ' added labels: ' +
            str(final_labels))
        im.close()
コード例 #2
0
def writ_gps(image_path, coo):
    # 转换并写入图像地理范围,存储于Xmp.dc字段下(x1、y1)(x2,y2)下
    # {'Xmp.dc.x1': 'E120.25',
    # 'Xmp.dc.y1': 'N31.05000000000001',
    # 'Xmp.dc.x2': 'E121.29999999999994',
    # 'Xmp.dc.y2': 'N30.25'}

    if coo[0][0] > 0:
        long_location_lef = "E"
    else:
        long_location_lef = "W"
    if coo[0][1] > 0:
        lati_location_lef = "N"
    else:
        lati_location_lef = "S"
    if coo[1][0] > 0:
        long_location_rig = "E"
    else:
        long_location_rig = "W"
    if coo[1][1] > 0:
        lati_location_rig = "N"
    else:
        lati_location_rig = "S"

    longituade_lef = abs(coo[0][0])
    latituade_lef = abs(coo[0][1])
    longituade_rig = abs(coo[1][0])
    latituade_rig = abs(coo[1][1])

    point1_x1 = str(long_location_lef) + str(longituade_lef) + "°"
    point1_y1 = str(lati_location_lef) + str(latituade_lef) + "°"
    point2_x1 = str(long_location_rig) + str(longituade_rig) + "°"
    point2_y2 = str(lati_location_rig) + str(latituade_rig) + "°"

    img = Image(image_path)
    img.modify_xmp({"Xmp.dc.x1": point1_x1})
    img.modify_xmp({"Xmp.dc.y1": point1_y1})
    img.modify_xmp({"Xmp.dc.x2": point2_x1})
    img.modify_xmp({"Xmp.dc.y2": point2_y2})
    img.close()
コード例 #3
0
img.read_iptc()
img.read_xmp()
img.read_raw_xmp()

img.clear_exif()
img.read_exif()

img.modify_exif({'Exif.Image.Make': 'test-中文-', 'Exif.Image.Rating': ''})
img.read_exif()

dict1 = {
    "Xmp.xmp.CreateDate": "2019-06-23T19:45:17.834",
    "Xmp.xmp.Rating": "",
    "Xmp.dc.subject": ["tag1", "tag2", "tag3"]
}
img.modify_xmp(dict1)

img.close()

from pyexiv2 import ImageData

with open(r'.\pyexiv2\tests\1.jpg', 'rb') as f:
    with ImageData(f.read()) as img:
        data = img.read_exif()

with open(r'.\pyexiv2\tests\1.jpg', 'rb+') as f:
    with ImageData(f.read()) as img:
        changes = {'Iptc.Application2.ObjectName': 'test'}
        img.modify_iptc(changes)
        f.seek(0)
        f.write(img.get_bytes())
コード例 #4
0
indexFile = open(path + "\\index.txt", mode="r", encoding="utf-8")
os.mkdir(path + "\\to_delete\\")

next_date_for_pictures = ''
num_photos_with_date = 0

while True:
    fileName = indexFile.readline().strip()
    description = indexFile.readline().strip()
    dateTaken = indexFile.readline().strip()
    if not dateTaken: break  # EOF

    if description != 'delete':
        metadata = Image(path + "\\" + fileName)
        xmp = {'Xmp.dc.description': description}
        metadata.modify_xmp(xmp)

        if dateTaken == next_date_for_pictures:
            # add a second to make the next picture think that it comes next
            split_date = dateTaken.split(":")
            minutes = split_date[3]
            split_date[3] = str(int(minutes) + num_photos_with_date).zfill(2)
            num_photos_with_date += 1
            dateTaken = ":".join(split_date)
        else:
            num_photos_with_date = 1
            next_date_for_pictures = dateTaken

        exif = {
            'Exif.Image.ImageDescription': description,
            'Exif.Photo.DateTimeOriginal': dateTaken
コード例 #5
0
ファイル: wutsdis.py プロジェクト: marcelklehr/wutsdis
def write_metadata(path, tags):
    i = Image(path)
    i.modify_xmp({'Xmp.dc.subject': tags})