Skip to content

Commit

Permalink
Merge pull request #1060 from pierotofy/gcp
Browse files Browse the repository at this point in the history
Display ground control points on map
  • Loading branch information
pierotofy authored Sep 26, 2021
2 parents 3ce7cb3 + 421306a commit af32e3a
Show file tree
Hide file tree
Showing 73 changed files with 516 additions and 95,686 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
**/.git
2 changes: 2 additions & 0 deletions .github/workflows/build-and-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v2
with:
submodules: 'recursive'
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/test-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ jobs:

- name: Build and Test
run: |
docker-compose -f docker-compose.yml -f docker-compose.build.yml up --build -d
sleep 30
docker-compose -f docker-compose.yml -f docker-compose.build.yml build --build-arg TEST_BUILD=ON
docker-compose -f docker-compose.yml -f docker-compose.build.yml up -d
sleep 20
docker-compose exec -T webapp /webodm/webodm.sh test
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "nodeodm/external/NodeODM"]
path = nodeodm/external/NodeODM
url = https://github.com/OpenDroneMap/NodeODM
[submodule "locale"]
path = locale
url = https://github.com/OpenDroneMap/WebODM-Locale
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
FROM ubuntu:21.04
MAINTAINER Piero Toffanin <pt@masseranolabs.com>

ARG TEST_BUILD
ENV PYTHONUNBUFFERED 1
ENV PYTHONPATH $PYTHONPATH:/webodm
ENV PROJ_LIB=/usr/share/proj
Expand All @@ -20,7 +21,7 @@ RUN apt-get -qq update && apt-get -qq install -y --no-install-recommends wget cu
pip install -U pip && pip install -r requirements.txt "boto3==1.14.14" && \
# Setup cron
ln -s /webodm/nginx/crontab /var/spool/cron/crontabs/root && chmod 0644 /webodm/nginx/crontab && service cron start && chmod +x /webodm/nginx/letsencrypt-autogen.sh && \
cd /webodm/nodeodm/external/NodeODM && npm install --quiet && cd /webodm && \
/webodm/nodeodm/setup.sh && /webodm/nodeodm/cleanup.sh && cd /webodm && \
npm install --quiet -g webpack@4.16.5 && npm install --quiet -g webpack-cli@4.2.0 && npm install --quiet && webpack --mode production && \
echo "UTC" > /etc/timezone && \
python manage.py collectstatic --noinput && \
Expand Down
2 changes: 1 addition & 1 deletion LOCALES
Original file line number Diff line number Diff line change
@@ -1 +1 @@
fr es it de tr ru pt_BR ko zh_Hant az pl
fr es it de tr ru pt_BR ko zh_Hant az pl hu id ja th
87 changes: 85 additions & 2 deletions app/api/imageuploads.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import os

import io
import math

from .tasks import TaskNestedView
from rest_framework import exceptions
from app.models import ImageUpload
from app.models.task import assets_directory_path
from PIL import Image
from PIL import Image, ImageDraw, ImageOps
from django.http import HttpResponse
from .tasks import download_file_response
import numpy as np
Expand All @@ -26,6 +26,18 @@ def normalize(img):

return Image.fromarray(arr)

def hex2rgb(hex_color):
"""
Adapted from https://stackoverflow.com/questions/29643352/converting-hex-to-rgb-value-in-python/29643643
"""
hex_color = hex_color.lstrip('#')
if len(hex_color) != 6:
return tuple((255, 255, 255))
try:
return tuple(int(hex_color[i:i+2], 16) for i in (0, 2, 4))
except ValueError:
return tuple((255, 255, 255))

class Thumbnail(TaskNestedView):
def get(self, request, pk=None, project_pk=None, image_filename=""):
"""
Expand All @@ -49,6 +61,35 @@ def get(self, request, pk=None, project_pk=None, image_filename=""):
quality = int(self.request.query_params.get('quality', 75))
if quality < 0 or quality > 100:
raise ValueError()

center_x = float(self.request.query_params.get('center_x', '0.5'))
center_y = float(self.request.query_params.get('center_y', '0.5'))
if center_x < -0.5 or center_x > 1.5 or center_y < -0.5 or center_y > 1.5:
raise ValueError()

draw_points = self.request.query_params.getlist('draw_point')
point_colors = self.request.query_params.getlist('point_color')
point_radiuses = self.request.query_params.getlist('point_radius')

points = []
i = 0
for p in draw_points:
coords = list(map(float, p.split(",")))
if len(coords) != 2:
raise ValueError()

points.append({
'x': coords[0],
'y': coords[1],
'color': hex2rgb(point_colors[i]) if i < len(point_colors) else (255, 255, 255),
'radius': float(point_radiuses[i]) if i < len(point_radiuses) else 1.0,
})

i += 1

zoom = float(self.request.query_params.get('zoom', '1'))
if zoom < 0.1 or zoom > 10:
raise ValueError()

except ValueError:
raise exceptions.ValidationError("Invalid query parameters")
Expand All @@ -57,6 +98,48 @@ def get(self, request, pk=None, project_pk=None, image_filename=""):
if img.mode != 'RGB':
img = normalize(img)
img = img.convert('RGB')
w, h = img.size
thumb_size = min(max(w, h), thumb_size)

# Move image center
if center_x != 0.5 or center_y != 0.5:
img = img.crop((
w * (center_x - 0.5),
h * (center_y - 0.5),
w * (center_x + 0.5),
h * (center_y + 0.5)
))

# Scale
scale_factor = 1
off_x = 0
off_y = 0

if zoom != 1:
scale_factor = (2 ** (zoom - 1))
off_x = w / 2.0 - w / scale_factor / 2.0
off_y = h / 2.0 - h / scale_factor / 2.0
win = img.crop((off_x, off_y,
off_x + (w / scale_factor),
off_y + (h / scale_factor)
))
img = ImageOps.scale(win, scale_factor, Image.NEAREST)

sw, sh = w * scale_factor, h * scale_factor

# Draw points
for p in points:
d = ImageDraw.Draw(img)
r = p['radius'] * max(w, h) / 100.0

sx = (p['x'] + (0.5 - center_x)) * sw
sy = (p['y'] + (0.5 - center_y)) * sh
x = sx - off_x * scale_factor
y = sy - off_y * scale_factor

d.ellipse([(x - r, y - r),
(x + r, y + r)], outline=p['color'], width=int(max(1.0, math.floor(r / 3.0))))

img.thumbnail((thumb_size, thumb_size))
output = io.BytesIO()
img.save(output, format='JPEG', quality=quality)
Expand Down
1 change: 0 additions & 1 deletion app/api/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,6 @@ def upload(self, request, pk=None, project_pk=None):

task.images_count = models.ImageUpload.objects.filter(task=task).count()
# Update other parameters such as processing node, task name, etc.
print(f"Amount of images currently in task: {task.images_count}")
serializer = TaskSerializer(task, data=request.data, partial=True)
serializer.is_valid(raise_exception=True)
serializer.save()
Expand Down
7 changes: 6 additions & 1 deletion app/models/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ class Task(models.Model):
'cameras.json': 'cameras.json',
'shots.geojson': os.path.join('odm_report', 'shots.geojson'),
'report.pdf': os.path.join('odm_report', 'report.pdf'),
'ground_control_points.geojson': os.path.join('odm_georeferencing', 'ground_control_points.geojson'),
}

STATUS_CODES = (
Expand Down Expand Up @@ -860,14 +861,18 @@ def get_map_items(self):
camera_shots = ''
if 'shots.geojson' in self.available_assets: camera_shots = '/api/projects/{}/tasks/{}/download/shots.geojson'.format(self.project.id, self.id)

ground_control_points = ''
if 'ground_control_points.geojson' in self.available_assets: ground_control_points = '/api/projects/{}/tasks/{}/download/ground_control_points.geojson'.format(self.project.id, self.id)

return {
'tiles': [{'url': self.get_tile_base_url(t), 'type': t} for t in types],
'meta': {
'task': {
'id': str(self.id),
'project': self.project.id,
'public': self.public,
'camera_shots': camera_shots
'camera_shots': camera_shots,
'ground_control_points': ground_control_points
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions app/static/app/js/classes/AssetDownloads.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,11 @@ const api = {
new AssetDownload(_("Textured Model"),"textured_model.zip","fab fa-connectdevelop"),
new AssetDownload(_("Camera Parameters"),"cameras.json","fa fa-camera"),
new AssetDownload(_("Camera Shots (GeoJSON)"),"shots.geojson","fa fa-camera"),
new AssetDownload(_("Ground Control Points (GeoJSON)"),"ground_control_points.geojson","far fa-dot-circle"),
new AssetDownload(_("Quality Report"),"report.pdf","far fa-file-pdf"),



new AssetDownloadSeparator(),
new AssetDownload(_("All Assets"),"all.zip","far fa-file-archive")
];
Expand Down
Loading

0 comments on commit af32e3a

Please sign in to comment.