如何使用Python脚本将指定文件添加到Metashape块中?

huangapple go评论62阅读模式
英文:

How can I use a Python script to add a specified file to Metashape chunks?

问题

The code you've written appears to be in Python and is used to add photos to a Metashape project. However, it seems like you're looking for assistance with it. To help you find any mistakes and provide a corrected version, please provide more specific details about the issues or errors you are encountering.

英文:

want to automatically add a specified file using a script in Metashape program, but it's not appearing in the chunks. What should I do?

import Metashape
import os

doc = Metashape.Document()
photo_folder = os.path.expanduser("~/Desktop/dronepics")
chunk = doc.addChunk()

for filename in os.listdir(photo_folder):
    if filename.endswith(".jpg") or filename.endswith(".jpeg"):
        photo_path = os.path.join(photo_folder, filename)
        photo = Metashape.Photo()
        photo.open(photo_path)
        chunk.addPhotos([photo])
doc.save(os.path.expanduser("~/Desktop/çıktı/proje.psx"))

The code I have written, where did I make a mistake and can you tell me the correct version?

答案1

得分: 0

以下是翻译好的部分:

import os, Metashape
def find_files(folder, types):
    return [entry.path for entry in os.scandir(folder) if (entry.is_file() and os.path.splitext(entry.name)[1].lower() in types)]
doc = Metashape.Document()
doc.save(output_folder + '/project.psx')
chunk = doc.addChunk()
photos = find_files(image_folder, [".jpg", ".jpeg", ".tif", ".tiff"])
chunk.addPhotos(photos)
doc.save()

请注意,我已经将代码段中的HTML实体(如<pre>')还原为普通的Python代码。如果您需要进一步的翻译,请告诉我。

英文:

See how it is done in official GitHub script:
https://github.com/agisoft-llc/metashape-scripts/blob/master/src/samples/general_workflow.py

<pre>
import os, Metashape
def find_files(folder, types):
return [entry.path for entry in os.scandir(folder) if (entry.is_file() and os.path.splitext(entry.name)[1].lower() in types)]
doc = Metashape.Document()
doc.save(output_folder + '/project.psx')
chunk = doc.addChunk()
photos = find_files(image_folder, [".jpg", ".jpeg", ".tif", ".tiff"])
chunk.addPhotos(photos)
doc.save()

</pre>

huangapple
  • 本文由 发表于 2023年5月22日 06:26:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/76302174.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定