This repository was archived by the owner on Jan 4, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathcamera_baumer.py
More file actions
148 lines (114 loc) · 4.17 KB
/
camera_baumer.py
File metadata and controls
148 lines (114 loc) · 4.17 KB
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
from __future__ import annotations
from typing import List
import numpy as np
try:
import neoapi
except ImportError:
neoapi_found = False
else:
neoapi_found = True
from camera import Camera
class CameraBaumer(Camera):
def __init__(self, camera: neoapi.Cam, serial_number: str = None):
self.camera = camera
if serial_number is not None:
self.camera.Connect(serial_number)
else:
self.camera.Connect()
self.type = 'baumer'
@staticmethod
def get_available_cameras(cameras_num_to_find: int = 2, cameras_serial_numbers: List[str] = []) -> list[Camera]:
cameras = []
if neoapi_found:
i = 0
while i < cameras_num_to_find:
# Get next camera from neoapi
if len(cameras_serial_numbers) == 0:
camera = CameraBaumer(neoapi.Cam())
else:
camera = CameraBaumer(neoapi.Cam(), cameras_serial_numbers[i])
if camera.camera.f.DeviceSerialNumber.value not in cameras_serial_numbers:
raise Exception(f'Error, camera serial number is not {cameras_serial_numbers[i]}')
# Set default cameras parameters
camera.exposure = 20_000
camera.gain = 2.0
camera.frame_rate_enable = True
camera.frame_rate = 10.0
camera.camera.f.PixelFormat = neoapi.PixelFormat_Mono8
# Set first camera as master for triggering
if i == 0:
camera.trigger_mode = neoapi.TriggerMode_Off
camera.line_selector = neoapi.LineSelector_Line1
camera.line_mode = neoapi.LineMode_Output
camera.line_source = neoapi.LineSource_ExposureActive
else:
# Set next camera as slave for trigger wait
camera.trigger_mode = neoapi.TriggerMode_On
camera.line_selector = neoapi.LineSelector_Line1
camera.line_mode = neoapi.LineMode_Input
cameras.append(camera)
i = i + 1
return cameras
def get_image(self) -> np.array:
img = self.camera.GetImage().GetNPArray()
return img.reshape(img.shape[0], img.shape[1])
@property
def exposure(self):
return self.camera.f.ExposureTime.value
@exposure.setter
def exposure(self, x):
self.camera.f.ExposureTime.value = x
@property
def gain(self):
return self.camera.f.Gain.value
@gain.setter
def gain(self, x):
self.camera.f.Gain.value = x
@property
def gamma(self):
return self.camera.f.Gamma.value
@gamma.setter
def gamma(self, x):
self.camera.f.Gamma.value = x
@property
def exposure_auto(self):
return self.camera.f.ExposureAuto.value
@exposure_auto.setter
def exposure_auto(self, x):
self.camera.f.ExposureAuto.value = x
@property
def trigger_mode(self):
return self.camera.f.TriggerMode.value
@trigger_mode.setter
def trigger_mode(self, x):
self.camera.f.TriggerMode.value = x
@property
def line_selector(self):
return self.camera.f.LineSelector.value
@line_selector.setter
def line_selector(self, x):
self.camera.f.LineSelector.value = x
@property
def line_mode(self):
return self.camera.f.LineMode.value
@line_mode.setter
def line_mode(self, x):
self.camera.f.LineMode.value = x
@property
def line_source(self):
return self.camera.f.LineSource.value
@line_source.setter
def line_source(self, x):
self.camera.f.LineSource.value = x
@property
def frame_rate_enable(self):
return self.camera.f.AcquisitionFrameRateEnable.value
@frame_rate_enable.setter
def frame_rate_enable(self, x):
self.camera.f.AcquisitionFrameRateEnable.value = x
@property
def frame_rate(self):
return self.camera.f.AcquisitionFrameRate.value
@frame_rate.setter
def frame_rate(self, x):
self.camera.f.AcquisitionFrameRate.value = x