Add camera for image shoot
This commit is contained in:
parent
809d11cb49
commit
9be861b01c
30
scanner.py
30
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
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue