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()
def Process_img(path): image = Image(path) i_xmp = image.read_xmp() info = { 'GPSLatitude': i_xmp.get('Xmp.drone-dji.GpsLatitude'), 'GPSLongitude': i_xmp.get('Xmp.drone-dji.GpsLongtitude'), 'GPSAltitude': i_xmp.get('Xmp.drone-dji.AbsoluteAltitude'), 'GPSRelativeAltitude': i_xmp.get('Xmp.drone-dji.RelativeAltitude'), 'CameraRoll': i_xmp.get('Xmp.drone-dji.GimbalRollDegree'), 'CameraYaw': i_xmp.get('Xmp.drone-dji.GimbalYawDegree'), 'CameraPitch': i_xmp.get('Xmp.drone-dji.GimbalPitchDegree'), 'FlightRoll': i_xmp.get('Xmp.drone-dji.FlightRollDegree'), 'FlightYaw': i_xmp.get('Xmp.drone-dji.FlightYawDegree'), 'FlightPitch': i_xmp.get('Xmp.drone-dji.FlightPitchDegree'), 'SpeedX': i_xmp.get('Xmp.drone-dji.FlightXSpeed'), 'SpeedY': i_xmp.get('Xmp.drone-dji.FlightYSpeed'), 'SpeedZ': i_xmp.get('Xmp.drone-dji.FlightZSpeed'), 'CalibratedOpticalCenterX': i_xmp.get('Xmp.drone-dji.CalibratedOpticalCenterX'), 'CalibratedOpticalCenterY': i_xmp.get('Xmp.drone-dji.CalibratedOpticalCenterY'), 'CalibratedOpticalFocalLength': i_xmp.get('Xmp.drone-dji.CalibratedFocalLength'), } i_exif = image.read_exif() info['XResolution'] = i_exif.get('Exif.Image.XResolution') info['YResolution'] = i_exif.get('Exif.Image.YResolution') info['PixelXDimension'] = i_exif.get('Exif.Photo.PixelXDimension') info['PixelYDimension'] = i_exif.get('Exif.Photo.PixelYDimension') info['FocalLength'] = i_exif.get('Exif.Photo.FocalLength') info['FocalLengthIn35mmFilm'] = i_exif.get( 'Exif.Photo.FocalLengthIn35mmFilm') return info
from pyexiv2 import Image img = Image(r'.\pyexiv2\tests\1.jpg') img.read_exif() 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:
from pyexiv2 import Image i = Image('DJI_0294.JPG') Information = i.read_exif() for keys, values in Information.items(): print(keys + ':' + values + '\n') print('*********************') for keys, values in i.read_xmp().items(): print(keys + ':' + values + '\n')
def read_exif(): i = Image("imgs/2.jpg") print(i.read_exif()) print(i.read_iptc()) print(i.read_xmp())
import glob import argparse import io from pyexiv2 import Image if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument("--pathname", type=str) parser.add_argument("--recursive", action="store_true") args = parser.parse_args() for filename in glob.iglob(args.pathname, recursive=args.recursive): print(filename) img = Image(filename) md = img.read_xmp() img.close() reverse_offset = int(md["Xmp.GCamera.MicroVideoOffset"]) with open(filename, "rb") as f: f.seek(reverse_offset * -1, 2) rest_of_file = f.read() print(f.tell()) with open(filename + ".mp4", "wb") as wf: wf.write(rest_of_file)