如何将子流程的输出保存到数据帧?
我正在编写一个脚本,用于从 RTK 无人机图像中提取 exif 数据(纬度、经度和高度)。我或多或少地从 YouTube 视频(Franchyze923)复制了下面的代码 - 做了一些修改。 [我编码的时间很短]。如何获取子流程的结果以保存到表/数据框(最终我想将信息保存到 .csv)。
该脚本的不同版本为每个图像生成了一个 .csv - 然后我将所有 csv 文件导入并将 pd.concat() 它们放入一个数据帧中。这可行但看起来很笨重。
import os
import subprocess
#Extracting exif data for images in Agisoft folder
exiftool_location = #path to exiftool.exe
images_to_extract_exif = #path to images
for path, directories, files in os.walk(images_to_extract_exif):
for images_to_extract_exif in files:
if images_to_extract_exif.endswith("JPG"):
full_jpg_path = os.path.join(path, images_to_extract_exif)
exiftool_command = [exiftool_location, "-filename", "-gpslatitude", "-gpslongitude", "-gpsaltitude", "-T", "-n", full_jpg_path]
subprocess.run(exiftool_command)
代码的输出看起来很棒 - 我只是不知道如何将其保存到表/数据帧中。
DJI_0001.JPG 45.2405341666667 -95.3808298055556 354.427
DJI_0002.JPG 45.2405253333333 -95.3808253055556 354.434
DJI_0003.JPG 45.2404568888889 -95.3808200277778 354.447
DJI_0004.JPG 45.2403695277778 -95.3808205555556 354.431
I'm working on a script to extract exif data (Latitude, Longitude, and Altitude) from RTK drone images. I have more or less copied the code below from a youtube video (Franchyze923)- with a few modifications. [I've been coding for a very short time]. How can I get the results of the subprocess to save to a table/dataframe (eventually I want to save the information to a .csv).
A different version of this script generated a .csv for every image - which I then imported all the csv files and pd.concat() them into one dataframe. That works but seems clunky.
import os
import subprocess
#Extracting exif data for images in Agisoft folder
exiftool_location = #path to exiftool.exe
images_to_extract_exif = #path to images
for path, directories, files in os.walk(images_to_extract_exif):
for images_to_extract_exif in files:
if images_to_extract_exif.endswith("JPG"):
full_jpg_path = os.path.join(path, images_to_extract_exif)
exiftool_command = [exiftool_location, "-filename", "-gpslatitude", "-gpslongitude", "-gpsaltitude", "-T", "-n", full_jpg_path]
subprocess.run(exiftool_command)
The output from the code looks great - I just have no clue how to save it to a table/dataframe.
DJI_0001.JPG 45.2405341666667 -95.3808298055556 354.427
DJI_0002.JPG 45.2405253333333 -95.3808253055556 354.434
DJI_0003.JPG 45.2404568888889 -95.3808200277778 354.447
DJI_0004.JPG 45.2403695277778 -95.3808205555556 354.431
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是收集 ExifTool 输出并放入 DataFrame 的方法。我没有使用
-T
来输出文本,而是使用-j
来获取 json。 Json 可以很容易地在 Python 中读取,因此我们不必解释文本。默认情况下,ExifTool 的 json 输出包含一个SourceFile
标记,其中文件路径作为值。我将提供一种从输出中删除此标记的方法,但它可以作为-filename
的替代方案。exif_df:
Here is a way to collect the ExifTool output and put in a DataFrame. Instead of using
-T
to output text I used-j
to get json. Json can be easily read in Python so we don't have to interpret the text. By default ExifTool's json output includes aSourceFile
tag with the file path as the value. I'll include a way to delete this tag from the output but it could be an alternative to-filename
.exif_df
: