From 9be861b01cd980c2cf2749b97e8b572b639c8e9e Mon Sep 17 00:00:00 2001 From: Nicolas Bertrand Date: Tue, 8 Oct 2024 16:09:42 +0200 Subject: [PATCH] Add camera for image shoot --- scanner.py | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/scanner.py b/scanner.py index 3cbf673..142e9b4 100644 --- a/scanner.py +++ b/scanner.py @@ -3,6 +3,8 @@ import os from os.path import join import shutil import time +import gphoto2 as gp + from . import config # Delay between to captures @@ -11,16 +13,22 @@ DELAY = 0.5 def capture(output_path: str) -> bool: try: - with open('.device', 'r') as f: - device_id = int(f.read().rstrip()) + camera = gp.Camera() + camera.init() + print('Capturing image') + file_path = camera.capture(gp.GP_CAPTURE_IMAGE) + print('Camera file path: {0}/{1}'.format(file_path.folder, file_path.name)) + target =output_path + print('Copying image to', target) + camera_file = camera.file_get( + file_path.folder, file_path.name, gp.GP_FILE_TYPE_NORMAL) + camera_file.save(target) + s = True except: - device_id = 0 - - cam = cv2.VideoCapture(device_id) - s, img = cam.read() - if s: - cv2.imwrite(output_path, img) - cam.release() + print(f'Somethings wrong on gphoto2') + s = False + finally: + camera.exit() return s @@ -33,9 +41,9 @@ 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('data-keep/small', led + '.jpg'), img) + #shutil.copyfile(join('data-keep/small', led + '.jpg'), img) delta = time.time() - start