-
Notifications
You must be signed in to change notification settings - Fork 0
/
camera.py
82 lines (67 loc) · 2.48 KB
/
camera.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import imageio
import gphoto2 as gp
import logging
import sys
import io
from PIL import Image
from PIL.ImageQt import ImageQt
class Camera(object):
def __init__(self):
self.exposure = 1
self.driftDelay = 30
logging.basicConfig(
format='%(levelname)s: %(name)s: %(message)s', level=logging.WARNING)
callback_obj = gp.check_result(gp.use_python_logging())
def camera_list(self):
camera_list = []
for name, addr in gp.check_result(gp.gp_camera_autodetect()):
camera_list.append((name, addr))
return camera_list
def connect(self, cam):
self.camera = gp.check_result(gp.gp_camera_new())
port_info_list = gp.PortInfoList()
port_info_list.load()
idx = port_info_list.lookup_path(cam)
self.camera.set_port_info(port_info_list[idx])
gp.check_result(gp.gp_camera_init(self.camera))
print (self.camera.get_summary())
# required configuration will depend on camera type!
print('Checking camera config')
# get configuration tree
self.config = gp.check_result(gp.gp_camera_get_config(self.camera))
def getImage(self):
cfg = self.camera.get_config()
capturetarget_cfg = cfg.get_child_by_name('capturetarget')
capturetarget = capturetarget_cfg.get_value()
capturetarget_cfg.set_value('Internal RAM')
self.camera.set_config(cfg)
camera_file = gp.check_result(gp.gp_camera_capture_preview(self.camera))
file_data = gp.check_result(gp.gp_file_get_data_and_size(camera_file))
tempPath='/tmp/align.cr2'
data = memoryview(file_data)
image = Image.open(io.BytesIO(file_data))
qimage = ImageQt(image)
# TiffPath = '/tmp/align.tiff'
# image.save(TiffPath)
return qimage
def exit(self):
self.camera.exit()
class CameraSimulator(Camera):
def __init__(self):
self.exposure = 1
self.driftDelay = 30
self.imageid = 0
self.images = ['Resources/orion_simulator_1.jpg', 'Resources/orion_simulator_2.jpg']
def connect(self):
return True
def getImage(self):
image = Image.open(self.images[self.imageid])
print ('Camera Simulator - showing: ', self.images[self.imageid])
qimage = ImageQt(image)
if self.imageid == 0:
self.imageid = 1
else:
self.imageid = 0
return qimage
def exit(self):
return