コード例 #1
0
    def getPara_PICTURE_EXIF(self, standardPicDir):
        """
        从图像EXIF参数中获取相机参数
        :param standardPicDir: 标准像片
        :return:
        """
        # CMOS长宽信息
        w_c = 6.29
        h_c = 5.21

        # 读取图片的长宽信息
        img = cv2.imread(standardPicDir)
        h = img.shape[0]
        w = img.shape[1]
        print(w, h)

        # 从EXIF中读取焦距
        i = Image(standardPicDir)
        a, b = i.read_exif().get('Exif.Photo.FocalLength').split('/')
        fm = int(a) / int(b)
        f = w * fm / w_c

        # 计算内参信息
        K = np.zeros((3, 3))
        K[0][0] = f
        K[1][1] = f
        K[0][2] = w / 2
        K[1][2] = h / 2
        print(K)
コード例 #2
0
def getInternalCalibrationMatrix(path):
    #Using the given info
    # CMOS长宽信息
    w_c = 17.3
    h_c = 13.0
    # 读取图片的长宽信息
    img = cv2.imread(path)
    h = img.shape[0]
    w = img.shape[1]
    print(w, h)

    # 从EXIF中读取焦距
    i = Image(path)
    a, b = i.read_exif().get('Exif.Photo.FocalLength').split('/')
    fm = int(a) / int(b)
    f = w * fm / w_c

    # 计算内参信息
    K = np.zeros((3, 3))
    K[0][0] = f
    K[1][1] = f
    K[0][2] = w / 2
    K[1][2] = h / 2
    K[2][2] = 1
    return K
コード例 #3
0
def read_exif(input_pic):
    img = Image(input_pic)
    data = img.read_exif()
    print("exif:", data)
    # data2 = img.read_iptc()
    # print("iptc:", data2)
    # data3 = img.read_xmp()
    # print("xmp:", data3)
    # data4 = img.read_raw_xmp()
    # print("raw_xmp:", data4)
    # data5 = img.read_comment()
    # print("comment:",data5)
    # data6 = img.read_icc()
    # print("icc:",data6)
    img.close()
    return data
コード例 #4
0
ファイル: EXIF.py プロジェクト: Coderxiaobai1/TolearnC-
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
コード例 #5
0
ファイル: app.py プロジェクト: kangah-codes/metas-strip
def open_image():
    global input_box
    global return_box
    metadata = None
    return_box = guizero.Box(app, width="fill")
    try:
        # using PIl to open image
        img = Image.open(input_box.value)
        # opening pyexiv2 instance from image
        meta = Meta(input_box.value)
        # opening the instance like this so that we don't close it after reading metadata so object is still in memory, although this can cause a memory leak

        # with Meta(input_box.value) as meta: -> using this method will delete the object and we will no longer have access to it in the clear meta function
        metadata = meta.read_exif()
        message = guizero.Text(return_box, text="")
        thumbnail = guizero.Picture(return_box,
                                    image=img,
                                    width=100,
                                    height=100)
        message = guizero.Text(return_box, text="")
        if not metadata:
            # picture has no metadata
            listbox = guizero.ListBox(return_box,
                                      items=["No metadata was extracted"],
                                      width="fill",
                                      height=50)
        else:
            listbox = guizero.ListBox(return_box, items=[], width="fill")
            cancel = guizero.PushButton(buttons_box,
                                        text="Strip Metadata",
                                        align="right",
                                        command=clear_meta,
                                        args=[meta])
            for _ in metadata.items():
                # add each item in metadata to listbox
                listbox.append(f"{_[0]}:     {_[1]}")
    except FileNotFoundError:
        message = guizero.Text(return_box, text="")
        thumbnail = guizero.Picture(return_box,
                                    image=f'error.jpeg',
                                    width=200,
                                    height=200)
        message = guizero.Text(return_box, text="")
        message = guizero.Text(return_box, text="Image not found")
コード例 #6
0
import os
import sys

from pyexiv2 import Image

print('Number of arguments:', len(sys.argv), 'arguments.')
print('Argument List:', str(sys.argv))

path = sys.argv[1]
entries = os.scandir(path)

indexFile = open(path + "\\index.txt", mode="w", encoding="utf-8")

def get_image_description(path, metadata):
    if path.endswith('_b.jpg'):
        return metadata.get('Exif.Image.ImageDescription', 'delete')
    return metadata.get('Exif.Image.ImageDescription', '')

for entry in entries:
    if entry.name.endswith('.jpg'):
        i = Image(entry.path)
        metadata = i.read_exif()
        photo_date = metadata.get('Exif.Photo.DateTimeOriginal')
        description = get_image_description(entry.path, metadata)

        line = entry.name + '\n' + description + '\n' + photo_date
        print(line)
        indexFile.write(line + '\n')
コード例 #7
0
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:
コード例 #8
0
def main():
    sort = list()
    for root, directories, filenames in os.walk(
            sorting_dir):  # Create a list of all files in "path"
        for filename in filenames:
            f = os.path.join(root, filename)
            if osp.splitext(f)[1].casefold() not in [".mp4", ".jpg", ".jpeg"]:
                print(f"Not handling:  {f}")
                continue
            sort.append(f)
    print(f"Sorting {len(sort)} file(s)")

    failed = list()
    copied = dict()

    for f in sort:
        # split the name by _ and extract required information
        fname = osp.basename(f)
        ftype = osp.splitext(fname)[1].casefold()

        print(f"Checking: {fname}")

        try:  # try to get the creation date, else add it to the failed list
            ## get jpgs and mp4 files only
            if ftype in [".jpg", ".jpeg"]:
                fpath = images_dir
                name_prefix = "IMG"

                out = probe(f, show_frames=None)
                try:  # try using ffprobe
                    creation_date = out['frames'][0]['tags'][
                        'DateTimeOriginal']
                except:
                    try:  # try using pyexiv 2
                        img = Image(f)
                    except:  # if reading fails, it might still have the information, because it's weird
                        pass
                    creation_date = img.read_exif()["Exif.Image.DateTime"]

            elif ftype == ".mp4":
                name_prefix = "VID"
                fpath = videos_dir
                out = probe(f)
                creation_date = out['format']['tags']['creation_time']
            else:
                print("Not handling")
                continue
        except:
            failed.append(f)
            continue

        ## get the date parts from the creation_date
        fyear = creation_date[:4]
        fmonth = creation_date[5:7]
        fday = creation_date[8:10]
        fhour = creation_date[11:13]
        fminute = creation_date[14:16]
        fsecond = creation_date[17:19]

        # create a datetime object from the file name info
        fdate = datetime(int(fyear), int(fmonth), int(fday), int(fhour),
                         int(fminute), int(fsecond))
        new_name = f"{name_prefix}_{fyear}{fmonth}{fday}_{fhour}{fminute}{fsecond}"

        # this variable will be an empty string if separate_files is False, else it's equal to fpath
        basename = fpath if separate_filetypes else ""

        # use a splat operator to join every element of the path_format list
        pre_formatted_path = osp.join(*path_format)
        path = osp.join(fdate.strftime(pre_formatted_path), basename)

        os.makedirs(
            path, exist_ok=True)  # make directories, unless they already exist

        new_path = osp.join(
            path, f"{new_name}"
        )  # the path of the file after being copied without the extension

        ## check if the file already exists
        check_name = f"{new_path}{ftype}"
        if osp.isfile(check_name) and check_name not in copied:
            print(f"File already exists:  {check_name}")
            continue

        new_file = copyfile(f, new_path, ftype)
        print(f"Copyied file:  {f} → {new_file}")

        copied[new_file] = f

        if not copy_files:  # delete old files?
            os.remove(floc)

    for f in failed:
        print(f)
コード例 #9
0
ファイル: cai.py プロジェクト: Coderxiaobai1/TolearnC-
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')
コード例 #10
0
ファイル: sample.py プロジェクト: mrghz/pyexiv2
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.modify_exif({'Exif.Image.Make': 'test-中文-', 'Exif.Image.Rating': ''})
img.read_exif()

img.clear_exif()
img.read_exif()

dict1 = {"Xmp.xmp.CreateDate": "2019-06-23T19:45:17.834",
         "Xmp.xmp.Rating": "",
         "Xmp.dc.subject": ["flag1中文", "flag2中文", "flag3中文"]}
img.modify_xmp(dict1)

img.close()
コード例 #11
0
def read_exif():
    i = Image("imgs/2.jpg")
    print(i.read_exif())
    print(i.read_iptc())
    print(i.read_xmp())