ExifToolを使用して、写真のexif情報を抽出します[ウィンドウの下](完全な情報)

小叙:最近参与导师的地籍测量项目,无人机飞回来的照片和pos数据有点问题,博主做内业时接到把照片的经纬度、相机倾角等详细数据提取出来的任务,奈何到处找资料,头晕眼花后也没有得到满意的解决办法,最终终于在github上找到了一个炫酷的解决办法,地址与可获取信息如下:

https://github.com/CarletonArchives/ExifTool-Batch-Processor

表1.使用可能な画像exif情報
ここに画像の説明を挿入
ブロガーは、環境を構成およびデバッグするときにいくつかの問題を抱えています。この記事では、デバッグの問題を整理して説明すると同時に、コードのPython2の部分をPython3の部分に書き換えて、 cmdコマンドの解決策。

1. Perl環境をインストールして構成する

ExifToolはPerl言語で記述されているため、MacおよびLinuxシステムで実行するのは非常に便利ですが、Windowsプラットフォームでは、最初に環境を構成する必要があります。ここで、ActiveStateの公式WebサイトからActivePerlを直接ダウンロードし、ダウンロードする最新バージョン、インストールパッケージのダウンロードアドレスを選択することをお勧めします次のように:

https://www.activestate.com/products/activeperl/downloads/

ダウンロードが完了したら、ダブルクリックしてインストールし、コンピューターパス環境変数の自動追加に注意してください。自動追加がない場合は、手動でパスを追加する必要があります。WindowsシステムでのActiveperlの詳細なインストールプロセスについては、次のリンクを参照してください。

https://jingyan.baidu.com/article/9113f81b68e2ce2b3214c7f9.html

2. exiftoolをダウンロードして簡単に設定する

1. ExifToolの公式Webサイトにアクセスして、ツールキットをダウンロードします。

Pythonソリューションを使用する場合は図1(1)をダウンロードし、cmdソリューションを使用する場合は図1(1)/図1(2)をダウンロードできます。命令を入力するときはプログラム呼び出しに注意してください名前だけ。

https://sno.phy.queensu.ca/~phil/exiftool/
ExifTool公式ウェブサイト
https://sno.phy.queensu.ca/~phil/exiftool/exiftool_pod.html#reading_examples
ExifToolヘルプドキュメント

ここに画像の説明を挿入
図1. ExifToolツールキットの選択

2.plファイル構成

この記事では、図1(1)のファイル構成の特別な説明しかありません。図1(2)のファイル構成については、ブロガーの「Python Study Notes:Application:Implementation of Batch Decompression of Compression Packages(WinRAR、 python、cmd) "WinRAR.exe環境設定と呼び出し方法、ブログアドレスは次のとおりです:

https://blog.csdn.net/knkn123/article/details/83020382

次に、ExifToolの簡単な変更を開始します。まず「Image-ExifTool-11.34.tar.gz」ファイルを解凍し、解凍されたフォルダ内の「exiftool」ファイルの名前を「exiftool.pl」に変更します。「exiftool覚えておいてください。 pl "ファイルパス、ブロガーのコンピューター上のパスは" D:\ Image-ExifTool-11.34 \ exiftool.pl "です。
ここに画像の説明を挿入
図2. ExifToolフォルダー内のファイルを簡単に変更した結果

3、cmdソリューション

1.コンソールコマンド

勝つ+ R、cmdを入力してコンソールを開き、次のコードを入力して、スペースに注意してください!

perl D:\Image-Exiftool-11.34\exiftool.pl -csv -r E:\19040501\100MEDIA > E:\19040501\100MEDIA\data\meta\exif.csv

perl 【exiftool.pl路径+文件名】 -csv -r 【image文件路径】 > 【CSV文件数据路径+CSV文件名】

Enterを押して実行すると、結果が図3に表示され、対応するパスの下に出力CSVファイルが見つかります。
ここに画像の説明を挿入
図3 .cmd実行結果

2.batファイル

パスを入力する問題を解決するためにbatファイルを使用し、txtに次のコードを入力し、「。bat」サフィックスファイルとして保存し、それを写真フォルダーに入れ、ダブルクリックして実行します

perl D:\Image-Exiftool-11.34\exiftool.pl -csv -r *.jpg > exif.csv

4、Pythonソリューション

Caitlin Donahueによって共有された元のコードのおかげで、ブロガーはPython3環境で実行できるように内部コードに特定の変更を加え、主要なパラメーター、個人的なテスト、完璧な操作をマークしました。

import os
import sys
import platform
import errno

def usage_message():
    print("RunExifTool is a program to automatically run exiftool on a set of bags contained within a directory supplied by the user")
    print( "--------------------")
    print("Usage:")
    print("-h or --help to display this message")
    print("<python RunExifTool.py> with no arguments will prompt you for the directory you would like to analyze")
    print("<python RunExifTool.py <path to files to validate>> will run exiftool on the supplied directory")
    print("--------------------")
    print("Dependencies:")
    print("Must have exiftool installed on your computer")
    print("Must have perl version 5.004 or newer n your computer")

def main():
    #环境参数设置
    ExifTool_path = 'D:\\Image-ExifTool-11.34\\exiftool.pl' # 根据exiftool.pl文件的路径进行设置
    Image_bag_path = 'E:\\19040501\\' # 根据待处理图像的路径进行设置
    #store the original directory so we can navigate back to it at the end of the program
    original_location = os.getcwd()
    parent = ""
    exif = ""
    exifName = ""
    if len(sys.argv) == 2:
        if sys.argv[1] == "-h" or sys.argv[1] == "--help":
            usage_message()
        else:
            parent = sys.argv[1]
    if parent == "":
        #get file locations from the user
        print("Please enter the directory that holds the bags you would like to scan: ")
        #parent = input().strip()
        parent = Image_bag_path.strip()

    #check what os the user is running to account for terminal command differences
    if platform.system() == "Windows":
        exifName = "exiftool.pl"
    else:
        exifName = "exiftool"
    #make sure the directories are in the correct format
    parent = parent.strip().strip("'").strip('"')
    #navigate to the file that the user's exif program is located in
    #获取当前路径下的文件夹列表
    path_list = [x for x in os.listdir(parent)]

    for folder in path_list:
        full_folder_path = os.path.join(parent, folder).strip()
        if os.path.isdir(full_folder_path):
            print("--------------------------------------")
            print("Running exif tool on files in " + full_folder_path)
            print("--------------------------------------")
            meta_path = os.path.join(full_folder_path,"data","meta")
            print("--------------------------------------")
            print( "Making sure " + meta_path + " exists.")
            print( "--------------------------------------")
            try:
                os.makedirs(meta_path)
            #If an error is raised
            #ignore it if it is telling us the file already exists
            #raise the error if it is related to something else
            except OSError as exception:
                if exception.errno != errno.EEXIST:
                    raise
            full_folder_path = ('"' + full_folder_path + '"')
            meta_path = ('"' + meta_path + '"')
            print( "--------------------------------------")
            print( "Making xml file in " + meta_path)
            print("--------------------------------------")
            cmd = "perl {0} -csv -r {1} > {2}".format(ExifTool_path, full_folder_path.strip('"'), os.path.join(meta_path.strip('"'), "exif.xml").strip('"'))
            os.system(cmd)
            print("--------------------------------------")
            print( "Making csv file in " + meta_path)
            print( "--------------------------------------")
            cmd = "perl {0} -csv -r {1} > {2}".format(ExifTool_path, full_folder_path.strip('"'), os.path.join(meta_path.strip('"'), "exif.csv").strip('"'))
            os.system(cmd)
            print( "--------------------------------------")
            print("Run on " + full_folder_path + " complete")
            print("--------------------------------------")
    print("--------------------------------------")
    print("Run Complete")
    print("--------------------------------------")
main()
8件の元の記事を公開 16 件を獲得・4 万回以上の閲覧

おすすめ

転載: blog.csdn.net/knkn123/article/details/89178313