今天要來用pyODM執行NodeODM建立3D模型,這樣才能產出我們要分析的材料。
-main.py
-upload_file
直接把ODM的Sample Code貼上來,然後修改一下。
# coding = utf-8
import os # 匯入os模組
import sys # 匯入sys模組
import pyodm # 匯入pyodm模組
def Run_Nodeodm(filename_list):
node = pyodm.Node("localhost",3000) #連接到localhost,porrt 3000
try:
# Start a task
print("Uploading images...")
task = node.create_task(filename_list,
{'dsm': True, 'orthophoto-resolution': 4})
print(task.info())
try:
# This will block until the task is finished
# or will raise an exception
task.wait_for_completion()
print("Task completed, downloading results...")
# Retrieve results
task.download_assets("./results")
print("Assets saved in ./results (%s)" % os.listdir("./results"))
# Restart task and this time compute dtm
task.restart({'dtm': True})
task.wait_for_completion()
print("Task completed, downloading results...")
task.download_assets("./results_with_dtm")
print("Assets saved in ./results_with_dtm (%s)" % os.listdir("./results_with_dtm"))
except pyodm.exceptions.TaskFailedError as e:
print("\n".join(task.output()))
except pyodm.exceptions.NodeConnectionError as e:
print("Cannot connect: %s" % e)
except pyodm.exceptions.NodeResponseError as e:
print("Error: %s" % e)
def Catch_Filename(upload_file):
file_dir = "./" + str(upload_file) # upload_file的相對路徑
filename_list = [] # 建立一個空的list
for root, dirs, files in os.walk(file_dir): #爬出 file_dir內的資料夾與檔案路徑(root)、資料夾名稱(dirs)、檔案(files)
for file in files: # 爬出files(list)中的元素
if file[-3:] == "JPG": #判斷檔案是否為 JPG
file_path = os.path.join(file_dir,file) # join路徑
filename_list.append(file_path) # 將file_path 元素加入filename_list
return filename_list
def main():
sys.path.append('..')
upload_file = sys.argv[1] # 將外部參數sys.avgv[1]作為upload檔案輸入。
filename_list = Catch_Filename(upload_file) # 遍歷upload_file的所有Jpg並且回傳一個list
Run_Nodeodm(filename_list) # 執行影像建模
if __name__ == "__main__": # 如果Py檔案是主程序,執行main()
main()
還在執行,使用virtualbox資源用太少的缺點。跑好再跟大家分享。
發現前十天所做的基礎建設貌似有點不夠,因為是軟體開發,code有點多,本來要在接近尾聲的版本控制跟外部引入的文章章應該要先寫了,不然文章的code一定會太多,有充字數之嫌。但是終於把檔案與ODM串起來了,感動。