Fast mode
This commit is contained in:
parent
9a64bc47cb
commit
01f59f55f2
35
camera.py
35
camera.py
|
|
@ -4,8 +4,8 @@ from . import leds, config
|
||||||
|
|
||||||
|
|
||||||
class Camera:
|
class Camera:
|
||||||
def capture(self, output_path: str) -> bool:
|
def capture(self):
|
||||||
return False
|
return None
|
||||||
|
|
||||||
|
|
||||||
class RealCamera(Camera):
|
class RealCamera(Camera):
|
||||||
|
|
@ -19,19 +19,18 @@ class RealCamera(Camera):
|
||||||
def __exit__(self, *args):
|
def __exit__(self, *args):
|
||||||
self.inner.exit()
|
self.inner.exit()
|
||||||
|
|
||||||
def capture(self, output_path: str) -> bool:
|
def capture(self):
|
||||||
try:
|
try:
|
||||||
file_path = self.inner.capture(gp.GP_CAPTURE_IMAGE)
|
return self.inner.capture(gp.GP_CAPTURE_IMAGE)
|
||||||
preview = self.inner.file_get(file_path.folder, file_path.name[:-3] + 'JPG', gp.GP_FILE_TYPE_NORMAL)
|
|
||||||
raw = self.inner.file_get(file_path.folder, file_path.name, gp.GP_FILE_TYPE_RAW)
|
|
||||||
|
|
||||||
preview.save(output_path + '.jpg')
|
|
||||||
raw.save(output_path + '.cr2')
|
|
||||||
return True
|
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print('An error occured when capturing photo', e)
|
print('An error occured when capturing photo', e)
|
||||||
return False
|
return None
|
||||||
|
|
||||||
|
def save(self, capture, output_file):
|
||||||
|
preview = self.inner.file_get(capture.folder, capture.name[:-3] + 'JPG', gp.GP_FILE_TYPE_NORMAL)
|
||||||
|
raw = self.inner.file_get(capture.folder, capture.name, gp.GP_FILE_TYPE_RAW)
|
||||||
|
preview.save(output_file + '.jpg')
|
||||||
|
raw.save(output_file + '.cr2')
|
||||||
|
|
||||||
|
|
||||||
class DummyCamera(Camera):
|
class DummyCamera(Camera):
|
||||||
|
|
@ -44,7 +43,7 @@ class DummyCamera(Camera):
|
||||||
def __exit__(self, *args):
|
def __exit__(self, *args):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def capture(self, output_path: str) -> bool:
|
def capture(self):
|
||||||
# Find which leds are turned on
|
# Find which leds are turned on
|
||||||
found = None
|
found = None
|
||||||
all_on = False
|
all_on = False
|
||||||
|
|
@ -56,12 +55,14 @@ class DummyCamera(Camera):
|
||||||
all_on = True
|
all_on = True
|
||||||
|
|
||||||
if all_on:
|
if all_on:
|
||||||
shutil.copyfile('data-keep/small/all_on.jpg', output_path + '.jpg')
|
return 'data-keep/small/all_on.jpg'
|
||||||
elif found is not None:
|
elif found is not None:
|
||||||
shutil.copyfile('data-keep/small/' + str(found) + '.jpg', output_path + '.jpg')
|
return 'data-keep/small/' + str(found) + '.jpg'
|
||||||
else:
|
else:
|
||||||
print('ALL_OFF')
|
return 'data-keep/small/all_off.jpg'
|
||||||
shutil.copyfile('data-keep/small/all_off.jpg', output_path + '.jpg')
|
|
||||||
|
def save(self, capture, output_file):
|
||||||
|
shutil.copyfile(capture, output_file + '.jpg')
|
||||||
|
|
||||||
|
|
||||||
camera = DummyCamera(leds.get()) if config.CAMERA == "dummy" else RealCamera()
|
camera = DummyCamera(leds.get()) if config.CAMERA == "dummy" else RealCamera()
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ OBJECT_DIR = join(DATA_DIR, 'objects')
|
||||||
DATABASE_PATH = join(DATA_DIR, 'db.sqlite')
|
DATABASE_PATH = join(DATA_DIR, 'db.sqlite')
|
||||||
|
|
||||||
AUTO_USE_LAST_CALIBRATION = True
|
AUTO_USE_LAST_CALIBRATION = True
|
||||||
|
DELAY = 0.0
|
||||||
GPIO_CHIP = 'gpiochip0'
|
GPIO_CHIP = 'gpiochip0'
|
||||||
LEDS_UUIDS = [17, 18, 22, 23, 24, 27]
|
LEDS_UUIDS = [17, 18, 22, 23, 24, 27]
|
||||||
CAMERA = 'real'
|
CAMERA = 'real'
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ OBJECT_DIR = join(DATA_DIR, 'objects')
|
||||||
DATABASE_PATH = join(DATA_DIR, 'db.sqlite')
|
DATABASE_PATH = join(DATA_DIR, 'db.sqlite')
|
||||||
|
|
||||||
AUTO_USE_LAST_CALIBRATION = False
|
AUTO_USE_LAST_CALIBRATION = False
|
||||||
|
DELAY = 0.5
|
||||||
GPIO_CHIP = None
|
GPIO_CHIP = None
|
||||||
LEDS_UUIDS = [17, 18, 22, 23, 24, 27]
|
LEDS_UUIDS = [17, 18, 22, 23, 24, 27]
|
||||||
CAMERA = 'dummy'
|
CAMERA = 'dummy'
|
||||||
|
|
|
||||||
40
scanner.py
40
scanner.py
|
|
@ -1,21 +1,18 @@
|
||||||
import os
|
import os
|
||||||
from os.path import join
|
from os.path import join
|
||||||
import time
|
import time
|
||||||
from . import leds, camera
|
from . import leds, camera, config
|
||||||
|
|
||||||
# Delay between to captures
|
|
||||||
DELAY = 0.5
|
|
||||||
|
|
||||||
|
|
||||||
def delay_capture(cam, output_path):
|
def delay_capture(cam):
|
||||||
# Measure the time it takes to capture
|
# Measure the time it takes to capture
|
||||||
start = time.time()
|
start = time.time()
|
||||||
output = cam.capture(output_path)
|
output = cam.capture()
|
||||||
delta = time.time() - start
|
delta = time.time() - start
|
||||||
|
|
||||||
# Wait for at least one second between each capture
|
# Wait for at least one second between each capture
|
||||||
if delta < DELAY:
|
if delta < config.DELAY:
|
||||||
time.sleep(DELAY - delta)
|
time.sleep(config.DELAY - delta)
|
||||||
|
|
||||||
return output
|
return output
|
||||||
|
|
||||||
|
|
@ -23,29 +20,30 @@ def delay_capture(cam, output_path):
|
||||||
def scan(output_dir: str, on_and_off: bool = True):
|
def scan(output_dir: str, on_and_off: bool = True):
|
||||||
os.makedirs(output_dir, exist_ok=True)
|
os.makedirs(output_dir, exist_ok=True)
|
||||||
|
|
||||||
with leds.get() as gpio_leds:
|
file_paths = []
|
||||||
for count, led in enumerate(gpio_leds.leds):
|
with camera.get() as cam:
|
||||||
with camera.get() as cam:
|
with leds.get() as gpio_leds:
|
||||||
|
for count, led in enumerate(gpio_leds.leds):
|
||||||
print(f'Turn on {led}')
|
print(f'Turn on {led}')
|
||||||
img = join(output_dir, f'{led}')
|
img = join(output_dir, f'{led}')
|
||||||
|
|
||||||
led.on()
|
led.on()
|
||||||
delay_capture(cam, img)
|
file_paths.append((str(led), delay_capture(cam)))
|
||||||
led.off()
|
led.off()
|
||||||
|
|
||||||
print(f'Turn off {led}')
|
print(f'Turn off {led}')
|
||||||
yield str(led)
|
|
||||||
|
|
||||||
# capture with all leds ON OFF
|
# capture with all leds ON OFF
|
||||||
if on_and_off:
|
if on_and_off:
|
||||||
with camera.get() as cam:
|
|
||||||
gpio_leds.on()
|
gpio_leds.on()
|
||||||
img = join(output_dir, 'all_on')
|
img = join(output_dir, 'all_on')
|
||||||
delay_capture(cam, img)
|
file_paths.append(('all_on', delay_capture(cam)))
|
||||||
yield 'all_on'
|
|
||||||
|
|
||||||
with camera.get() as cam:
|
|
||||||
gpio_leds.off()
|
gpio_leds.off()
|
||||||
img = join(output_dir, 'all_off')
|
img = join(output_dir, 'all_off')
|
||||||
delay_capture(cam, img)
|
file_paths.append(('all_off', delay_capture(cam)))
|
||||||
yield 'all_off'
|
|
||||||
|
with camera.get() as cam:
|
||||||
|
for target, source in file_paths:
|
||||||
|
cam.save(source, join(output_dir, target))
|
||||||
|
yield target
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue