-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCameraTest.py
More file actions
176 lines (138 loc) · 4.84 KB
/
Copy pathCameraTest.py
File metadata and controls
176 lines (138 loc) · 4.84 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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
import os
import time
from datetime import datetime
from picamera2 import Picamera2, Preview
from pprint import *
class MyCamera(Picamera2):
'''Camera display and configuration setting
Returns a class for the camera
'''
def __init__(self, camera_id, directory, name):
super().__init__(camera_id)
self.directory = directory
self.last_second = -1
self.image_count = 0
self.name = name
def create_config(self):
'''Sets the camera config'''
self.config = self.create_still_configuration(main={"size": (2592, 2592)}, raw={"size": (4608, 2592)})
def print_config(self):
'''Returns the config name'''
return(self.name + " config: " + str(self.config["main"]))
def capture_count_interval(self, count=1, interval=1):
'''param number of iterations and intervals
Captures files and sleeps at a certain interval
'''
# iterate count number of times
for i in range(count):
current_time = datetime.now()
current_second = current_time.second
if current_second != self.last_second:
self.image_count = 0
self.last_second = current_second
timestamp = current_time.strftime("%Y%m%d_%H%M%S")
self.filename = f"{timestamp}_{self.image_count}_{self.name}.jpg"
self.full_path = os.path.join(self.directory, self.filename)
# capture file
self.capture_file(self.full_path)
self.image_count += 1
# sleeps for a certain interval
time.sleep(interval)
def captureBoth_count_interval(count=1, interval=1):
'''param number of iterations and intervals
Captures files and sleeps at a certain interval for both cam0 and cam1
'''
last_second = -1
image_count = 0
directory = "/home/bread/Desktop/TestPics"
# iterate until exited
while True:
current_time = datetime.now()
current_second = current_time.second
if current_second != last_second:
image_count = 0
last_second = current_second
# capture with cam0
timestamp = current_time.strftime("%Y%m%d_%H%M%S")
filename = f"{timestamp}_{image_count}_RGB.jpg"
full_path = os.path.join(directory, filename)
cam0.capture_file(full_path)
# capture with cam1
filename = f"{timestamp}_{image_count}_IR.jpg"
full_path = os.path.join(directory, filename)
cam1.capture_file(full_path)
# increment image count
image_count += 1
# sleeps for a certain interval
time.sleep(interval)
if __name__ == "__main__":
cam0 = MyCamera(0, "/home/bread/Desktop/TestPics", "RGB")
cam1 = MyCamera(1, "/home/bread/Desktop/TestPics", "IR")
'''
# <Config info>
# GENERAL, global params
* transform: hori/vert flip
* queue
* sensor
output_size (res)
bit_depth
> will auto pick best match, use exact sensor mode spec for certainty
...
# STREAM-specific configs (main stream always defined)
* image size
> optimize using cam.align_configuration(config)
* image format
For main:
• XBGR8888 - every pixel is packed into 32-bits, with a dummy 255 value at the end, so a pixel would look like [R, G, B,
255] when captured in Python. (These format descriptions can seem counter-intuitive, but the underlying
infrastructure tends to take machine endianness into account, which can mix things up!)
• XRGB8888 - as above, with a pixel looking like [B, G, R, 255].
• RGB888 - 24 bits per pixel, ordered [B, G, R].
• BGR888 - as above, but ordered [R, G, B].
• YUV420 - YUV images with a plane of Y values followed by a quarter plane of U values and then a quarter plane of V
values.
# SENSOR mode (res, bit depth, etc.) can be specified.
> If not, will be inferred from raw stream (if present).
* cam.sensor_modes
bit_depth
crop_limits (fov)
exposure_limits
format: can be passed as stream image format
fps
size (res)
# RUNTIME controls excluded unless specified
# Config generation
config = cam.create_still_configuration
# Apply configuration
cam.configure(config)
# View configuration
cam.camera_configuration()
'''
sensor_modes = (cam0.sensor_modes)
sensor_mode = sensor_modes[2]
print(sensor_mode)
cam0.create_config()
cam1.create_config()
cam0.align_configuration(cam0.config)
cam1.align_configuration(cam0.config)
cam0.configure(cam0.config)
cam1.configure(cam1.config)
print(cam0.print_config())
print(cam1.print_config())
cam0.start()
cam1.start()
MyCamera.captureBoth_count_interval(0, 1)
cam0.close()
cam1.close()
# cam0.camera_configuration()
# cam0.camera_controls
# cam0.create_config()
# cam0.print_config()
# cam0.align_configuration(cam0.config)
# cam0.print_config()
# cam0.configure(cam0.config)
# # cam0.start_preview(Preview.QTGL)
# cam0.start(show_preview=True)
# cam0.capture_count_interval()
# cam0.close()
# cam1.close()