scan
This commit is contained in:
parent
39885cd5b3
commit
0ad0914522
10
app.py
10
app.py
|
|
@ -1,6 +1,6 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
from flask import Flask, redirect, request, render_template, send_from_directory
|
||||
from flask import Flask, redirect, request, render_template, send_from_directory, jsonify
|
||||
import os
|
||||
from os.path import join
|
||||
import uuid
|
||||
|
|
@ -50,6 +50,14 @@ def preview(id: int):
|
|||
return "Impossible de capturer l'image.", 500
|
||||
|
||||
|
||||
@app.route("/api/scan-for-calibration/<id>")
|
||||
def scan_calibration(id: int):
|
||||
conn = db.get()
|
||||
db.Object.get_from_id(id, conn)
|
||||
scanner.scan(join(config.DATA_DIR, id, 'calibration'))
|
||||
return jsonify(config.LEDS_UUIDS)
|
||||
|
||||
|
||||
@app.route("/calibration/<id>")
|
||||
def calibration(id: int):
|
||||
conn = db.get()
|
||||
|
|
|
|||
14
config.py
14
config.py
|
|
@ -1,2 +1,16 @@
|
|||
DATA_DIR = 'data'
|
||||
|
||||
LEDS_UUIDS = [
|
||||
'ac59350e-3787-46d2-88fa-743c1d34fe86',
|
||||
'83ab3133-d4de-4a42-99a7-8f8a3f3732ba',
|
||||
'577d6e72-f518-4d65-af28-f8faf1ca3f5d',
|
||||
'ec49a20c-bddd-4614-b828-fa45e01bfb19',
|
||||
'5c249cce-d2b6-4b56-96c8-5caa43d8f040',
|
||||
'22d783fb-ae55-4581-a3c6-e010d9d5e9de',
|
||||
'12cb6a32-04a6-433b-8146-b753b8f1286d',
|
||||
'461255a3-259a-4291-adc3-2fb736231a04',
|
||||
'3896662f-9826-4445-ad70-86c2e6c143e7',
|
||||
'f87698ec-3cba-42fe-9a61-5ac9f77d767a',
|
||||
'4c77a655-4b68-4557-a696-29345c6676a1',
|
||||
'b1cfe287-aa3b-445e-bcdc-75ae375efe43',
|
||||
]
|
||||
|
|
|
|||
12
scanner.py
12
scanner.py
|
|
@ -1,4 +1,7 @@
|
|||
import cv2
|
||||
import os
|
||||
from os.path import join
|
||||
from . import config
|
||||
|
||||
|
||||
def capture(output_path: str) -> bool:
|
||||
|
|
@ -8,3 +11,12 @@ def capture(output_path: str) -> bool:
|
|||
cv2.imwrite(output_path, img)
|
||||
cam.release()
|
||||
return s
|
||||
|
||||
|
||||
def scan(output_dir: str):
|
||||
os.makedirs(output_dir, exist_ok=True)
|
||||
for led in config.LEDS_UUIDS:
|
||||
print(f'Turn on {led}')
|
||||
img = join(output_dir, led + '.jpg')
|
||||
capture(img)
|
||||
print(f'Turn off {led}')
|
||||
|
|
|
|||
|
|
@ -4,13 +4,15 @@
|
|||
<section class="section">
|
||||
<div class="container">
|
||||
<h1 class="title">Étalonnage</h1>
|
||||
<p>Placez la mire devant le scanner puis appuyez sur le bouton pour prévisualiser ou étalonner le scanner.</p>
|
||||
<div class="mb-2">
|
||||
<p>Placez la mire devant le scanner puis appuyez sur le bouton pour prévisualiser ou étalonner le scanner.</p>
|
||||
</div>
|
||||
<div class="field is-grouped is-grouped-multiline">
|
||||
<div class="control">
|
||||
<button id="preview-button" class="button is-link">Prévisualiser</button>
|
||||
</div>
|
||||
<div class="control">
|
||||
<button class="button is-link">Étalonner</button>
|
||||
<button id="calibrate-button" class="button is-link">Étalonner</button>
|
||||
</div>
|
||||
</div>
|
||||
<article id="error-container" class="message is-danger" style="display: none;">
|
||||
|
|
@ -20,6 +22,9 @@
|
|||
<div>
|
||||
<img id="preview-image" style="display: none;">
|
||||
</div>
|
||||
<div id="grid" class="grid">
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
{% endblock content %}
|
||||
|
|
@ -27,23 +32,50 @@
|
|||
{% block extrajs %}
|
||||
<script>
|
||||
let previewButton = document.getElementById('preview-button');
|
||||
let calibrateButton = document.getElementById('calibrate-button');
|
||||
let previewImage = document.getElementById('preview-image');
|
||||
let grid = document.getElementById('grid');
|
||||
let buttons = [previewButton, calibrateButton];
|
||||
let errorContainer = document.getElementById('error-container');
|
||||
let errorContent = document.getElementById('error-content');
|
||||
|
||||
previewButton.addEventListener('click', async () => {
|
||||
buttons.forEach(x => x.setAttribute('disabled', 'disabled'));
|
||||
previewButton.classList.add('is-loading');
|
||||
let response = await fetch('/api/preview/{{ object.id }}');
|
||||
let uuid = await response.text();
|
||||
|
||||
if (response.status >= 200 && response.status < 400) {
|
||||
let img = document.getElementById('preview-image');
|
||||
img.src = "/data/{{ object.id }}/previews/" + uuid + ".jpg";
|
||||
img.style.display = "block";
|
||||
previewImage.src = "/data/{{ object.id }}/previews/" + uuid + ".jpg";
|
||||
previewImage.style.display = "block";
|
||||
errorContainer.style.display = "none";
|
||||
} else {
|
||||
errorContainer.style.display = "block";
|
||||
errorContent.innerHTML = uuid;
|
||||
}
|
||||
|
||||
previewButton.classList.remove('is-loading');
|
||||
buttons.forEach(x => x.removeAttribute('disabled'));
|
||||
});
|
||||
|
||||
calibrateButton.addEventListener('click', async () => {
|
||||
previewImage.style.display = "none";
|
||||
buttons.forEach(x => x.setAttribute('disabled', 'disabled'));
|
||||
calibrateButton.classList.add('is-loading');
|
||||
let response = await fetch('/api/scan-for-calibration/{{ object.id }}');
|
||||
let ledsUuids = await response.json();
|
||||
calibrateButton.classList.remove('is-loading');
|
||||
buttons.forEach(x => x.removeAttribute('disabled'));
|
||||
|
||||
for (let led of ledsUuids) {
|
||||
let cell = document.createElement('div');
|
||||
cell.classList.add('cell');
|
||||
cell.classList.add('is-col-min-4');
|
||||
let img = document.createElement('img');
|
||||
img.src = '/data/{{ object.id }}/calibration/' + led + '.jpg';
|
||||
cell.appendChild(img);
|
||||
grid.appendChild(cell);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
{% endblock extrajs %}
|
||||
|
|
|
|||
Loading…
Reference in New Issue