Skip to content

Commit

Permalink
Merge pull request #688 from pierotofy/cameracalib
Browse files Browse the repository at this point in the history
Camera Calibration and other fixes
  • Loading branch information
pierotofy committed Jun 27, 2019
2 parents c324049 + c83ee57 commit 8f0a8a8
Show file tree
Hide file tree
Showing 32 changed files with 550 additions and 245 deletions.
79 changes: 68 additions & 11 deletions app/api/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ def set_pending_action(self, pending_action, request, pk=None, project_pk=None,
raise exceptions.NotFound()

task.pending_action = pending_action
task.partial = False # Otherwise this will not be processed
task.last_error = None
task.save()

Expand Down Expand Up @@ -158,28 +159,84 @@ def retrieve(self, request, pk=None, project_pk=None):
serializer = TaskSerializer(task)
return Response(serializer.data)

def create(self, request, project_pk=None):
project = get_and_check_project(request, project_pk, ('change_project', ))

@detail_route(methods=['post'])
def commit(self, request, pk=None, project_pk=None):
"""
Commit a task after all images have been uploaded
"""
get_and_check_project(request, project_pk, ('change_project', ))
try:
task = self.queryset.get(pk=pk, project=project_pk)
except (ObjectDoesNotExist, ValidationError):
raise exceptions.NotFound()

# TODO: check at least two images are present

task.partial = False
task.images_count = models.ImageUpload.objects.filter(task=task).count()

if task.images_count < 2:
raise exceptions.ValidationError(detail="You need to upload at least 2 images before commit")

task.save()
worker_tasks.process_task.delay(task.id)

serializer = TaskSerializer(task)
return Response(serializer.data, status=status.HTTP_200_OK)

@detail_route(methods=['post'])
def upload(self, request, pk=None, project_pk=None):
"""
Add images to a task
"""
get_and_check_project(request, project_pk, ('change_project', ))
try:
task = self.queryset.get(pk=pk, project=project_pk)
except (ObjectDoesNotExist, ValidationError):
raise exceptions.NotFound()

files = flatten_files(request.FILES)

if len(files) <= 1:
raise exceptions.ValidationError(detail="Cannot create task, you need at least 2 images")
if len(files) == 0:
raise exceptions.ValidationError(detail="No files uploaded")

with transaction.atomic():
task = models.Task.objects.create(project=project,
pending_action=pending_actions.RESIZE if 'resize_to' in request.data else None)

for image in files:
models.ImageUpload.objects.create(task=task, image=image)
task.images_count = len(files)

# Update other parameters such as processing node, task name, etc.
return Response({'success': True}, status=status.HTTP_200_OK)

def create(self, request, project_pk=None):
project = get_and_check_project(request, project_pk, ('change_project', ))

# If this is a partial task, we're going to upload images later
# for now we just create a placeholder task.
if request.data.get('partial'):
task = models.Task.objects.create(project=project,
pending_action=pending_actions.RESIZE if 'resize_to' in request.data else None)
serializer = TaskSerializer(task, data=request.data, partial=True)
serializer.is_valid(raise_exception=True)
serializer.save()
else:
files = flatten_files(request.FILES)

worker_tasks.process_task.delay(task.id)
if len(files) <= 1:
raise exceptions.ValidationError(detail="Cannot create task, you need at least 2 images")

with transaction.atomic():
task = models.Task.objects.create(project=project,
pending_action=pending_actions.RESIZE if 'resize_to' in request.data else None)

for image in files:
models.ImageUpload.objects.create(task=task, image=image)
task.images_count = len(files)

# Update other parameters such as processing node, task name, etc.
serializer = TaskSerializer(task, data=request.data, partial=True)
serializer.is_valid(raise_exception=True)
serializer.save()

worker_tasks.process_task.delay(task.id)

return Response(serializer.data, status=status.HTTP_201_CREATED)

Expand Down
18 changes: 18 additions & 0 deletions app/migrations/0028_task_partial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 2.1.7 on 2019-06-26 18:31

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('app', '0027_plugin'),
]

operations = [
migrations.AddField(
model_name='task',
name='partial',
field=models.BooleanField(default=False, help_text='A flag indicating whether this task is currently waiting for information or files to be uploaded before being considered for processing.'),
),
]
9 changes: 4 additions & 5 deletions app/models/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ class Task(models.Model):
'deferred_path': 'orthophoto_tiles.zip',
'deferred_compress_dir': 'orthophoto_tiles'
},
'cameras.json': 'cameras.json',
}

STATUS_CODES = (
Expand Down Expand Up @@ -212,6 +213,7 @@ class Task(models.Model):
blank=True)
import_url = models.TextField(null=False, default="", blank=True, help_text="URL this task is imported from (only for imported tasks)")
images_count = models.IntegerField(null=False, blank=True, default=0, help_text="Number of images associated with this task")
partial = models.BooleanField(default=False, help_text="A flag indicating whether this task is currently waiting for information or files to be uploaded before being considered for processing.")

def __init__(self, *args, **kwargs):
super(Task, self).__init__(*args, **kwargs)
Expand Down Expand Up @@ -444,7 +446,6 @@ def callback(progress):
nonlocal last_update

time_has_elapsed = time.time() - last_update >= 2

if time_has_elapsed:
testWatch.manual_log_call("Task.process.callback")
self.check_if_canceled()
Expand Down Expand Up @@ -482,13 +483,11 @@ def callback(progress):
self.status = status_codes.CANCELED
self.pending_action = None
self.save()
elif self.import_url:
# Imported tasks need no special action
else:
# Tasks with no processing node or UUID need no special action
self.status = status_codes.CANCELED
self.pending_action = None
self.save()
else:
raise NodeServerError("Cannot cancel a task that has no processing node or UUID")

elif self.pending_action == pending_actions.RESTART:
logger.info("Restarting {}".format(self))
Expand Down
2 changes: 1 addition & 1 deletion app/static/app/css/bootstrap.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions app/static/app/css/theme.scss
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ body,
a, a:hover, a:focus{
color: theme("tertiary");
}
.progress-bar-success{
background-color: theme("tertiary");
}

/* Button primary */
#navbar-top .navbar-top-links,{
Expand Down
48 changes: 48 additions & 0 deletions app/static/app/fonts/Lato.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/* latin-ext */
@font-face {
font-family: 'Lato';
font-style: italic;
font-weight: 400;
src: local('Lato Italic'), local('Lato-Italic'), url(latoItalic400.woff2) format('woff2');
unicode-range: U+0100-024F, U+0259, U+1E00-1EFF, U+2020, U+20A0-20AB, U+20AD-20CF, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
/* latin */
@font-face {
font-family: 'Lato';
font-style: italic;
font-weight: 400;
src: local('Lato Italic'), local('Lato-Italic'), url(latoItalic400-2.woff2) format('woff2');
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
/* latin-ext */
@font-face {
font-family: 'Lato';
font-style: normal;
font-weight: 400;
src: local('Lato Regular'), local('Lato-Regular'), url(latoRegular.woff2) format('woff2');
unicode-range: U+0100-024F, U+0259, U+1E00-1EFF, U+2020, U+20A0-20AB, U+20AD-20CF, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
/* latin */
@font-face {
font-family: 'Lato';
font-style: normal;
font-weight: 400;
src: local('Lato Regular'), local('Lato-Regular'), url(latoRegular-2.woff2) format('woff2');
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
/* latin-ext */
@font-face {
font-family: 'Lato';
font-style: normal;
font-weight: 700;
src: local('Lato Bold'), local('Lato-Bold'), url(latoBold.woff2) format('woff2');
unicode-range: U+0100-024F, U+0259, U+1E00-1EFF, U+2020, U+20A0-20AB, U+20AD-20CF, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
/* latin */
@font-face {
font-family: 'Lato';
font-style: normal;
font-weight: 700;
src: local('Lato Bold'), local('Lato-Bold'), url(latoBold-2.woff2) format('woff2');
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
Binary file added app/static/app/fonts/latoBold-2.woff2
Binary file not shown.
Binary file added app/static/app/fonts/latoBold.woff2
Binary file not shown.
Binary file added app/static/app/fonts/latoItalic400-2.woff2
Binary file not shown.
Binary file added app/static/app/fonts/latoItalic400.woff2
Binary file not shown.
Binary file added app/static/app/fonts/latoRegular-2.woff2
Binary file not shown.
Binary file added app/static/app/fonts/latoRegular.woff2
Binary file not shown.
16 changes: 1 addition & 15 deletions app/static/app/js/Console.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ class Console extends React.Component {
this.handleMouseOver = this.handleMouseOver.bind(this);
this.handleMouseOut = this.handleMouseOut.bind(this);
this.downloadTxt = this.downloadTxt.bind(this);
this.copyTxt = this.copyTxt.bind(this);
this.enterFullscreen = this.enterFullscreen.bind(this);
this.exitFullscreen = this.exitFullscreen.bind(this);
}
Expand Down Expand Up @@ -69,17 +68,7 @@ class Console extends React.Component {
}

downloadTxt(filename="console.txt"){
Utils.saveAs(this.state.lines.join("\r\n"), filename);
}

copyTxt(){
const el = document.createElement('textarea');
el.value = this.state.lines.join("\r\n");
document.body.appendChild(el);
el.select();
document.execCommand('copy');
document.body.removeChild(el);
console.log("Output copied to clipboard");
Utils.saveAs(this.state.lines.join("\n"), filename);
}

enterFullscreen(){
Expand Down Expand Up @@ -172,9 +161,6 @@ class Console extends React.Component {
<a href="javascript:void(0);" onClick={() => this.downloadTxt()} className="btn btn-sm btn-primary" title="Download To File">
<i className="fa fa-download"></i>
</a>
<a href="javascript:void(0);" onClick={this.copyTxt} className="btn btn-sm btn-primary" title="Copy To Clipboard">
<i className="fa fa-clipboard"></i>
</a>
<a href="javascript:void(0);" onClick={this.enterFullscreen} className="btn btn-sm btn-primary" title="Toggle Fullscreen">
<i className="fa fa-expand"></i>
</a>
Expand Down
1 change: 1 addition & 0 deletions app/static/app/js/classes/AssetDownloads.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const api = {
new AssetDownload("Point Cloud (PLY)","georeferenced_model.ply","fa fa-cube"),
new AssetDownload("Point Cloud (CSV)","georeferenced_model.csv","fa fa-cube"),
new AssetDownload("Textured Model","textured_model.zip","fa fa-connectdevelop"),
new AssetDownload("Camera Parameters","cameras.json","fa fa-camera"),
new AssetDownloadSeparator(),
new AssetDownload("All Assets","all.zip","fa fa-file-archive-o")
];
Expand Down
5 changes: 2 additions & 3 deletions app/static/app/js/classes/ResizeModes.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
const dict = [
{k: 'NO', v: 0, human: "No"}, // Don't resize
{k: 'YES', v: 1, human: "Yes"}, // Resize on server
{k: 'YESINBROWSER', v: 2, human: "Yes (In browser)"} // Resize on browser
{k: 'YES', v: 1, human: "Yes"} // Resize on server
];

const exp = {
all: () => dict.map(d => d.v),
fromString: (s) => {
let v = parseInt(s);
if (!isNaN(v) && v >= 0 && v <= 2) return v;
if (!isNaN(v) && v >= 0 && v <= 1) return v;
else return 0;
},
toHuman: (v) => {
Expand Down
24 changes: 4 additions & 20 deletions app/static/app/js/classes/Utils.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const FileSaver = require('file-saver');

let escapeEntityMap = {
"&": "&amp;",
"<": "&lt;",
Expand Down Expand Up @@ -83,26 +85,8 @@ export default {
},

saveAs: function(text, filename){
function save(uri, filename) {
let link = document.createElement('a');
if (typeof link.download === 'string') {
link.href = uri;
link.download = filename;

//Firefox requires the link to be in the body
document.body.appendChild(link);

//simulate click
link.click();

//remove the link when done
document.body.removeChild(link);
} else {
window.open(uri);
}
}

save("data:application/octet-stream," + encodeURIComponent(text), filename);
var blob = new Blob([text], {type: "text/plain;charset=utf-8"});
FileSaver.saveAs(blob, filename);
}
};

Loading

0 comments on commit 8f0a8a8

Please sign in to comment.