import cv2 import os from os.path import join import shutil import time from . import config # Delay between to captures DELAY = 0.5 def capture(output_path: str) -> bool: 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) 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') # Measure the time it takes to capture start = time.time() # capture(img) # For debug purposes shutil.copyfile(join('data-keep/small', led + '.jpg'), 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