英文:
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>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论