Working
This commit is contained in:
parent
1e150c95d5
commit
8676b21969
15
app.py
15
app.py
|
|
@ -1,10 +1,11 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
from flask import Flask, redirect, request, render_template, send_from_directory
|
||||
import json
|
||||
import os
|
||||
from os.path import join
|
||||
import uuid
|
||||
from . import db, config, scanner
|
||||
from . import db, config, scanner, calibration
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
|
|
@ -63,8 +64,18 @@ def scan_calibration(id: int):
|
|||
return app.response_class(generate(), mimetype='text/plain')
|
||||
|
||||
|
||||
@app.route("/api/calibrate/<id>")
|
||||
def run_calibration(id: int):
|
||||
conn = db.get()
|
||||
db.Object.get_from_id(id, conn)
|
||||
calibration_json = calibration.calibrate(join(config.DATA_DIR, str(id), 'calibration'))
|
||||
with open(join(config.DATA_DIR, str(id), 'calibration.json'), 'w') as f:
|
||||
json.dump(calibration_json, f, indent=4)
|
||||
return 'ok'
|
||||
|
||||
|
||||
@app.route("/calibration/<id>")
|
||||
def calibration(id: int):
|
||||
def calibration_page(id: int):
|
||||
conn = db.get()
|
||||
object = db.Object.get_from_id(id, conn)
|
||||
return render_template('calibration.html', object=object)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import io
|
||||
import json
|
||||
import functools
|
||||
import numpy as np
|
||||
|
|
@ -8,7 +7,7 @@ import os
|
|||
import sys
|
||||
from PIL import Image
|
||||
|
||||
import utils
|
||||
from . import utils
|
||||
|
||||
|
||||
# To extract a few images and resize them at 20% of their size:
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import cv2
|
||||
import os
|
||||
from os.path import join
|
||||
import shutil
|
||||
import time
|
||||
from . import config
|
||||
|
||||
|
|
@ -31,7 +32,11 @@ def scan(output_dir: str):
|
|||
|
||||
# Measure the time it takes to capture
|
||||
start = time.time()
|
||||
capture(img)
|
||||
|
||||
# capture(img)
|
||||
# For debug purposes
|
||||
shutil.copyfile(join(config.DATA_DIR, 'small', led + '.jpg'), img)
|
||||
|
||||
delta = time.time() - start
|
||||
|
||||
# Wait for at least one second between each capture
|
||||
|
|
|
|||
|
|
@ -12,22 +12,29 @@
|
|||
<button id="preview-button" class="button is-link">Prévisualiser</button>
|
||||
</div>
|
||||
<div class="control">
|
||||
<button id="calibrate-button" class="button is-link">Étalonner</button>
|
||||
<button id="scan-button" class="button is-link">Acquérir les données d'étalonnage</button>
|
||||
</div>
|
||||
</div>
|
||||
<article id="error-container" class="message is-danger" style="display: none;">
|
||||
<div id="error-content" class="message-body">
|
||||
</div>
|
||||
</article>
|
||||
<div>
|
||||
<div class="columns is-desktop">
|
||||
<div class="column is-offset-4 is-4">
|
||||
<img id="preview-image" style="display: none;">
|
||||
</div>
|
||||
</div>
|
||||
<div class="fixed-grid has-8-cols">
|
||||
<div id="grid" class="grid">
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<progress id="progress-bar" class="progress is-link" style="display: none;" value="0" max="1000"></progress>
|
||||
<div id="calibrate" style="display: none;">
|
||||
<p>Si les données d'étalonnage conviennent, appuyez sur le bouton ci-dessous pour procéder à l'étalonnage du scanner</p>
|
||||
<button id="calibrate-button" class="button is-link">Étalonner le scanner</button>
|
||||
<p id="calibration-info"></p>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
{% endblock content %}
|
||||
|
|
@ -37,13 +44,16 @@
|
|||
let scanIndex = 0;
|
||||
let progress = 0;
|
||||
let previewButton = document.getElementById('preview-button');
|
||||
let calibrateButton = document.getElementById('calibrate-button');
|
||||
let scanButton = document.getElementById('scan-button');
|
||||
let progressBar = document.getElementById('progress-bar');
|
||||
let previewImage = document.getElementById('preview-image');
|
||||
let grid = document.getElementById('grid');
|
||||
let buttons = [previewButton, calibrateButton];
|
||||
let buttons = [previewButton, scanButton];
|
||||
let errorContainer = document.getElementById('error-container');
|
||||
let errorContent = document.getElementById('error-content');
|
||||
let calibrateDiv = document.getElementById('calibrate');
|
||||
let calibrateButton = document.getElementById('calibrate-button');
|
||||
let calibrationInfo = document.getElementById('calibration-info');
|
||||
|
||||
previewButton.addEventListener('click', async () => {
|
||||
buttons.forEach(x => x.setAttribute('disabled', 'disabled'));
|
||||
|
|
@ -64,13 +74,13 @@
|
|||
buttons.forEach(x => x.removeAttribute('disabled'));
|
||||
});
|
||||
|
||||
calibrateButton.addEventListener('click', async () => {
|
||||
scanButton.addEventListener('click', async () => {
|
||||
scanIndex++;
|
||||
progress = 0;
|
||||
progressBar.value = 0;
|
||||
previewImage.style.display = "none";
|
||||
buttons.forEach(x => x.setAttribute('disabled', 'disabled'));
|
||||
calibrateButton.classList.add('is-loading');
|
||||
scanButton.classList.add('is-loading');
|
||||
progressBar.style.display = "block";
|
||||
grid.innerHTML = '';
|
||||
|
||||
|
|
@ -82,7 +92,8 @@
|
|||
|
||||
if (done) {
|
||||
buttons.forEach(x => x.removeAttribute('disabled'));
|
||||
calibrateButton.classList.remove('is-loading');
|
||||
scanButton.classList.remove('is-loading');
|
||||
calibrateDiv.style.display = "block";
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -98,6 +109,14 @@
|
|||
}
|
||||
});
|
||||
|
||||
calibrateButton.addEventListener('click', async () => {
|
||||
calibrateButton.classList.add('is-loading');
|
||||
|
||||
await fetch('/api/calibrate/{{ object.id }}');
|
||||
window.location.href = '/calibration/{{ object.id }}';
|
||||
|
||||
});
|
||||
|
||||
function refreshProgressBar() {
|
||||
if (progress !== progressBar.value) {
|
||||
progressBar.value = Math.min(progressBar.value + 5, progress);
|
||||
|
|
|
|||
|
|
@ -295,8 +295,8 @@ export class Engine {
|
|||
*/
|
||||
showImage(led: Led): void {
|
||||
if (led.on) {
|
||||
this.selectedObject.innerText = led.name + ' (' + (<number> this.leds.currentLedIndex + 1) + '/' + this.leds.children.length + ')';
|
||||
this.ledView.src = '/data/' + this.objectId + '/' + led.name;
|
||||
this.selectedObject.innerText = led.name.split('.')[0] + ' (' + (<number> this.leds.currentLedIndex + 1) + '/' + this.leds.children.length + ')';
|
||||
this.ledView.src = '/data/' + this.objectId + '/calibration/' + led.name;
|
||||
this.ledView.style.display = 'block';
|
||||
} else {
|
||||
this.selectedObject.innerText = 'aucune';
|
||||
|
|
|
|||
Loading…
Reference in New Issue