Add camera for image shoot

This commit is contained in:
Nicolas Bertrand 2024-10-08 16:09:42 +02:00
parent 809d11cb49
commit 9be861b01c
1 changed files with 19 additions and 11 deletions

View File

@ -3,6 +3,8 @@ import os
from os.path import join from os.path import join
import shutil import shutil
import time import time
import gphoto2 as gp
from . import config from . import config
# Delay between to captures # Delay between to captures
@ -11,16 +13,22 @@ DELAY = 0.5
def capture(output_path: str) -> bool: def capture(output_path: str) -> bool:
try: try:
with open('.device', 'r') as f: camera = gp.Camera()
device_id = int(f.read().rstrip()) 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: except:
device_id = 0 print(f'Somethings wrong on gphoto2')
s = False
cam = cv2.VideoCapture(device_id) finally:
s, img = cam.read() camera.exit()
if s:
cv2.imwrite(output_path, img)
cam.release()
return s return s
@ -33,9 +41,9 @@ def scan(output_dir: str):
# Measure the time it takes to capture # Measure the time it takes to capture
start = time.time() start = time.time()
# capture(img) capture(img)
# For debug purposes # 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 delta = time.time() - start