kopia lustrzana https://github.com/OpenDroneMap/WebODM
Expanded docs
rodzic
c57c97efae
commit
9bcf0b1b74
|
@ -6,56 +6,92 @@ https://mozilla.org/MPL/2.0/.
|
||||||
'''
|
'''
|
||||||
|
|
||||||
# How to authenticate and process drone images using WebODM
|
# How to authenticate and process drone images using WebODM
|
||||||
import requests, sys, os, glob, json
|
import requests, sys, os, glob, json, time
|
||||||
|
import status_codes
|
||||||
|
|
||||||
if len(sys.argv) < 2:
|
if len(sys.argv) < 2:
|
||||||
print("Usage: ./{} <path_to_images>".format(sys.argv[0]))
|
print("Usage: ./{} <path_to_images>".format(sys.argv[0]))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
types = ("*.jpg", "*.jpeg", "*.JPG", "*.JPEG")
|
types = ("*.jpg", "*.jpeg", "*.JPG", "*.JPEG")
|
||||||
images_list = []
|
images_list = []
|
||||||
for t in types:
|
for t in types:
|
||||||
images_list.extend(glob.glob(os.path.join(sys.argv[1], t)))
|
images_list.extend(glob.glob(os.path.join(sys.argv[1], t)))
|
||||||
|
|
||||||
if len(images_list) < 1:
|
if len(images_list) < 1:
|
||||||
print("Need at least 2 images")
|
print("Need at least 2 images")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
else:
|
else:
|
||||||
print("Found {} images".format(len(images_list)))
|
print("Found {} images".format(len(images_list)))
|
||||||
|
|
||||||
res = requests.post('http://localhost:8000/api/token-auth/',
|
res = requests.post('http://localhost:8000/api/token-auth/',
|
||||||
data={'username': 'admin',
|
data={'username': 'admin',
|
||||||
'password': 'admin'}).json()
|
'password': 'admin'}).json()
|
||||||
|
|
||||||
if 'token' in res:
|
if 'token' in res:
|
||||||
print("Logged-in!")
|
print("Logged-in!")
|
||||||
token = res['token']
|
token = res['token']
|
||||||
|
|
||||||
res = requests.post('http://localhost:8000/api/projects/',
|
res = requests.post('http://localhost:8000/api/projects/',
|
||||||
headers={'Authorization': 'JWT {}'.format(token)},
|
headers={'Authorization': 'JWT {}'.format(token)},
|
||||||
data={'name': 'Hello WebODM!'}).json()
|
data={'name': 'Hello WebODM!'}).json()
|
||||||
if 'id' in res:
|
if 'id' in res:
|
||||||
print("Created project: {}".format(res))
|
print("Created project: {}".format(res))
|
||||||
project_id = res['id']
|
project_id = res['id']
|
||||||
|
|
||||||
images = [('images', (os.path.basename(file), open(file, 'rb'), 'image/jpg')) for file in images_list]
|
images = [('images', (os.path.basename(file), open(file, 'rb'), 'image/jpg')) for file in images_list]
|
||||||
options = json.dumps([
|
options = json.dumps([
|
||||||
{'name': "use-opensfm-pointcloud", 'value': True},
|
{'name': "use-opensfm-pointcloud", 'value': True},
|
||||||
{'name': "orthophoto-resolution", 'value': 24},
|
{'name': "orthophoto-resolution", 'value': 24},
|
||||||
])
|
])
|
||||||
res = requests.post('http://localhost:8000/api/projects/{}/tasks/'.format(project_id),
|
res = requests.post('http://localhost:8000/api/projects/{}/tasks/'.format(project_id),
|
||||||
headers={'Authorization': 'JWT {}'.format(token)},
|
headers={'Authorization': 'JWT {}'.format(token)},
|
||||||
files=images,
|
files=images,
|
||||||
data={
|
data={
|
||||||
'options': options
|
'options': options
|
||||||
}).json()
|
}).json()
|
||||||
|
|
||||||
print("Created task: {}".format(res))
|
print("Created task: {}".format(res))
|
||||||
task_id = res['id']
|
task_id = res['id']
|
||||||
|
|
||||||
|
while True:
|
||||||
else:
|
time.sleep(3)
|
||||||
print("Cannot create project: {}".format(res))
|
res = requests.get('http://localhost:8000/api/projects/{}/tasks/{}/'.format(project_id, task_id),
|
||||||
|
headers={'Authorization': 'JWT {}'.format(token)}).json()
|
||||||
|
|
||||||
|
if res['status'] == status_codes.COMPLETED:
|
||||||
|
print("Task has completed!")
|
||||||
|
break
|
||||||
|
elif res['status'] == status_codes.FAILED:
|
||||||
|
print("Task failed: {}".format(res))
|
||||||
|
print("Cleaning up...")
|
||||||
|
requests.delete("http://localhost:8000/api/projects/{}/".format(project_id),
|
||||||
|
headers={'Authorization': 'JWT {}'.format(token)})
|
||||||
|
sys.exit(1)
|
||||||
|
else:
|
||||||
|
seconds = res['processing_time'] / 1000
|
||||||
|
if seconds < 0:
|
||||||
|
seconds = 0
|
||||||
|
m, s = divmod(seconds, 60)
|
||||||
|
h, m = divmod(m, 60)
|
||||||
|
sys.stdout.write("\rProcessing... [%02d:%02d:%02d]" % (h, m, s))
|
||||||
|
sys.stdout.flush()
|
||||||
|
|
||||||
|
res = requests.get("http://localhost:8000/api/projects/{}/tasks/{}/download/geotiff/".format(project_id, task_id),
|
||||||
|
headers={'Authorization': 'JWT {}'.format(token)},
|
||||||
|
stream=True)
|
||||||
|
with open("orthophoto.tif", 'wb') as f:
|
||||||
|
for chunk in res.iter_content(chunk_size=1024):
|
||||||
|
if chunk:
|
||||||
|
f.write(chunk)
|
||||||
|
|
||||||
|
print("Saved ./orthophoto.tif")
|
||||||
|
|
||||||
|
print("Cleaning up...")
|
||||||
|
requests.delete("http://localhost:8000/api/projects/{}/".format(project_id),
|
||||||
|
headers={'Authorization': 'JWT {}'.format(token)})
|
||||||
|
else:
|
||||||
|
print("Cannot create project: {}".format(res))
|
||||||
else:
|
else:
|
||||||
print("Invalid credentials!")
|
print("Invalid credentials!")
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
QUEUED = 10
|
||||||
|
RUNNING = 20
|
||||||
|
FAILED = 30
|
||||||
|
COMPLETED = 40
|
||||||
|
CANCELED = 50
|
|
@ -65,4 +65,37 @@ task_id = res['id']
|
||||||
|
|
||||||
We can then create a <a href="#task">Task</a>. The only required parameter is a list of multiple, multipart-encoded `images`. Processing will start automatically
|
We can then create a <a href="#task">Task</a>. The only required parameter is a list of multiple, multipart-encoded `images`. Processing will start automatically
|
||||||
as soon as a <a href="#processingnode">Processing Node</a> is available. It is possible to specify additional options by passing an `options` value, which is a JSON-encoded list of name/value pairs. Several other options are available. See the <a href="#task">Task</a> reference for more information.
|
as soon as a <a href="#processingnode">Processing Node</a> is available. It is possible to specify additional options by passing an `options` value, which is a JSON-encoded list of name/value pairs. Several other options are available. See the <a href="#task">Task</a> reference for more information.
|
||||||
|
<div class="clear"></div>
|
||||||
|
|
||||||
|
```python
|
||||||
|
while True:
|
||||||
|
res = requests.get('http://localhost:8000/api/projects/{}/tasks/{}/'.format(project_id, task_id),
|
||||||
|
headers={'Authorization': 'JWT {}'.format(token)}).json()
|
||||||
|
|
||||||
|
if res['status'] == status_codes.COMPLETED:
|
||||||
|
print("Task has completed!")
|
||||||
|
break
|
||||||
|
elif res['status'] == status_codes.FAILED:
|
||||||
|
print("Task failed: {}".format(res))
|
||||||
|
sys.exit(1)
|
||||||
|
else:
|
||||||
|
print("Processing, hold on...")
|
||||||
|
time.sleep(3)
|
||||||
|
```
|
||||||
|
|
||||||
|
We periodically check for the <a href="#task">Task</a> status using a loop.
|
||||||
|
<div class="clear"></div>
|
||||||
|
|
||||||
|
```python
|
||||||
|
res = requests.get("http://localhost:8000/api/projects/{}/tasks/{}/download/geotiff/".format(project_id, task_id),
|
||||||
|
headers={'Authorization': 'JWT {}'.format(token)},
|
||||||
|
stream=True)
|
||||||
|
with open("orthophoto.tif", 'wb') as f:
|
||||||
|
for chunk in res.iter_content(chunk_size=1024):
|
||||||
|
if chunk:
|
||||||
|
f.write(chunk)
|
||||||
|
```
|
||||||
|
|
||||||
|
Our orthophoto is ready to be downloaded. A variety of other assets, including a dense 3D point cloud and a textured model <a href="#download">is also available</a>.
|
||||||
|
|
||||||
|
A <a href="" target="_blank">TMS</a> layer is also made available at `http://localhost:8000/api/projects/{project_id}/tasks/{task_id}/tiles.json` for inclusion in programs such as <a href="http://leafletjs.com/" target="_blank">Leaflet</a> or <a href="http://cesiumjs.org" target="_blank">Cesium</a>.
|
||||||
|
|
Ładowanie…
Reference in New Issue