Fix bugs, better progress, allow custom device id
This commit is contained in:
parent
1643eb636e
commit
c97d06f7d8
|
|
@ -1,4 +1,5 @@
|
|||
db.sqlite
|
||||
.device
|
||||
data
|
||||
node_modules
|
||||
static/calibration-visualiser.*
|
||||
|
|
|
|||
21
scanner.py
21
scanner.py
|
|
@ -1,11 +1,21 @@
|
|||
import cv2
|
||||
import os
|
||||
from os.path import join
|
||||
import time
|
||||
from . import config
|
||||
|
||||
# Delay between to captures
|
||||
DELAY = 0.5
|
||||
|
||||
|
||||
def capture(output_path: str) -> bool:
|
||||
cam = cv2.VideoCapture(0)
|
||||
try:
|
||||
with open('.device', 'r') as f:
|
||||
device_id = int(f.read().rstrip())
|
||||
except:
|
||||
device_id = 0
|
||||
|
||||
cam = cv2.VideoCapture(device_id)
|
||||
s, img = cam.read()
|
||||
if s:
|
||||
cv2.imwrite(output_path, img)
|
||||
|
|
@ -18,6 +28,15 @@ def scan(output_dir: str):
|
|||
for led in config.LEDS_UUIDS:
|
||||
print(f'Turn on {led}')
|
||||
img = join(output_dir, led + '.jpg')
|
||||
|
||||
# Measure the time it takes to capture
|
||||
start = time.time()
|
||||
capture(img)
|
||||
delta = time.time() - start
|
||||
|
||||
# Wait for at least one second between each capture
|
||||
if delta < DELAY:
|
||||
time.sleep(DELAY - delta)
|
||||
|
||||
print(f'Turn off {led}')
|
||||
yield led
|
||||
|
|
|
|||
|
|
@ -65,12 +65,14 @@
|
|||
});
|
||||
|
||||
calibrateButton.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');
|
||||
progressBar.style.display = "block";
|
||||
grid.innerHTML = '';
|
||||
|
||||
let response = await fetch('/api/scan-for-calibration/{{ object.id }}');
|
||||
let reader = response.body.pipeThrough(new TextDecoderStream()).getReader();
|
||||
|
|
@ -89,6 +91,7 @@
|
|||
let cell = document.createElement('div');
|
||||
cell.classList.add('cell');
|
||||
let img = document.createElement('img');
|
||||
img.classList.add('is-loading');
|
||||
img.src = '/data/{{ object.id }}/calibration/' + uuid + '.jpg?v=' + scanIndex;
|
||||
cell.appendChild(img);
|
||||
grid.appendChild(cell);
|
||||
|
|
@ -97,8 +100,7 @@
|
|||
|
||||
function refreshProgressBar() {
|
||||
if (progress !== progressBar.value) {
|
||||
let diff = progress - progressBar.value;
|
||||
progressBar.value += Math.max(diff / 20, 1);
|
||||
progressBar.value = Math.min(progressBar.value + 5, progress);
|
||||
}
|
||||
requestAnimationFrame(refreshProgressBar);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue