2017-02-14 02:13:23 +00:00
# Quickstart
## How To Process Images
2017-03-01 22:06:55 +00:00
In this tutorial we'll explore how to process an orthophoto from a set of aerial images using Python. To do that we'll need to:
2017-02-14 02:13:23 +00:00
- Authenticate
- Create a [Project ](#project ). Projects are a way to group together related [Task ](#task ) items
- Upload some images to create a [Task ](#task )
- Check for [Task ](#task ) progress. Photogrammetry can take a long time, so results could take a few minutes to a few hours to be processed.
2017-02-20 23:58:25 +00:00
- Download the resulting orthophoto.
2017-02-14 02:13:23 +00:00
< aside class = "notice" > Most of the examples in this document use < a href = "http://docs.python-requests.org/en/latest/index.html" target = "_blank" > requests< / a > . Make sure it's installed before running any code:< br / > < br / >
< pre class = "higlight shell" >
$ pip install requests
< / pre >
< / aside >
2017-02-16 23:37:27 +00:00
< aside class = "notice" >
The < a href = "https://github.com/OpenDroneMap/WebODM/tree/master/slate/examples/process_images.py" target = "_blank" > source code< / a > for this example is available on GitHub< / a > .
< / aside >
2017-02-14 02:13:23 +00:00
```python
import requests
res = requests.post('http://localhost:8000/api/token-auth/',
data={'username': 'admin',
'password': 'admin'}).json()
2017-02-16 23:37:27 +00:00
token = res['token']
2017-02-14 02:13:23 +00:00
```
First, we < a href = "#authenticate" > authenticate</ a > with WebODM. A `token` is returned when authentication is successful.
< div class = "clear" > < / div >
```python
2017-02-16 23:37:27 +00:00
res = requests.post('http://localhost:8000/api/projects/',
headers={'Authorization': 'JWT {}'.format(token)},
data={'name': 'Hello WebODM!'}).json()
project_id = res['id']
```
2017-02-20 23:58:25 +00:00
Then we need to create a [Project ](#project ). We pass our `token` via the `Authorization` header. If we forget to pass this header, the system will not authenticate us and will refuse to process the request. We also assign a `name` to our project.
2017-02-16 23:37:27 +00:00
< div class = "clear" > < / div >
```python
images = [
('images', ('image1.jpg', open('image1.jpg', 'rb'), 'image/jpg')),
('images', ('image2.jpg', open('image2.jpg', 'rb'), 'image/jpg')),
# ...
]
options = json.dumps([
2017-03-01 22:06:55 +00:00
{'name': "orthophoto-resolution", 'value': 24}
2017-02-16 23:37:27 +00:00
])
res = requests.post('http://localhost:8000/api/projects/{}/tasks/'.format(project_id),
headers={'Authorization': 'JWT {}'.format(token)},
files=images,
data={
'options': options
}).json()
task_id = res['id']
2017-02-14 02:13:23 +00:00
```
2017-02-20 23:58:25 +00:00
We can then create a [Task ](#task ). The only required parameter is a list of multiple, multipart-encoded `images` . Processing will start automatically
2017-03-01 22:06:55 +00:00
as soon as a [Processing Node ](#processing-node ) 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 [Task - Processing Options ](#processing-options ) reference for more information.
2017-02-20 00:53:30 +00:00
< 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)
```
2017-02-20 23:58:25 +00:00
We periodically check for the [Task ](#task ) status using a loop.
2017-02-20 00:53:30 +00:00
< 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)
2017-02-20 23:58:25 +00:00
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")
2017-02-20 00:53:30 +00:00
```
2017-03-01 22:06:55 +00:00
Our orthophoto is ready to be downloaded. A variety of other assets, including a dense 3D point cloud and a textured model [are also available ](#download-assets ).
2017-02-16 23:37:27 +00:00
2017-02-20 23:58:25 +00:00
Congratulations! You just processed some images.
