Camera Module
Camera
Bases: CameraABC
, LoggerConsumerProtocol
Class implementation that wraps the functionality required for the Raspberry Pi Camera.
Source code in devices\raspberry_pi_5\src\camera\__init__.py
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 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
|
__del__()
Destructor to clean up resources when the camera is no longer needed.
Source code in devices\raspberry_pi_5\src\camera\__init__.py
184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
|
__init__(writer_messages_queue, width=WIDTH, height=HEIGHT, rotation=0, video_config=None)
Initialize the camera with the specified width, height, and video configuration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
writer_messages_queue
|
Queue
|
Queue to hold log messages. |
required |
width
|
int
|
Width of the camera image. |
WIDTH
|
height
|
int
|
Height of the camera image. |
HEIGHT
|
video_config(Optional[Dict])
|
Configuration for video recording. |
required | |
rotation
|
int
|
Rotation angle for the camera. |
0
|
Source code in devices\raspberry_pi_5\src\camera\__init__.py
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 |
|
abstracts
CameraABC
Bases: ABC
Abstract class that wraps the functionality required for the Raspberry Pi Camera.
Source code in devices\raspberry_pi_5\src\camera\abstracts.py
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 |
|
logger
abstractmethod
property
Get the logger instance for the Camera.
Returns:
Name | Type | Description |
---|---|---|
Logger |
Logger
|
The logger instance. |
capture_image_stream(image_format=IMAGE_FORMAT, adjust_duration=ADJUST_DURATION)
abstractmethod
Capture an image and return a byte stream.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image_format
|
str
|
Format of the image to be captured. |
IMAGE_FORMAT
|
adjust_duration
|
float
|
Duration to allow the camera to adjust before capturing the image. |
ADJUST_DURATION
|
Returns:
io.BytesIO: Captured image as a byte stream.
Source code in devices\raspberry_pi_5\src\camera\abstracts.py
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
|
convert_image_stream_to_pil(image_stream)
staticmethod
Convert a byte stream to a PIL image.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image_stream
|
BytesIO
|
Byte stream containing the image data. |
required |
Returns:
Image: Converted PIL image.
Source code in devices\raspberry_pi_5\src\camera\abstracts.py
17 18 19 20 21 22 23 24 25 26 27 28 29 |
|
correct_color(image, factor=1.1)
staticmethod
Apply color correction to the image.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image
|
Image
|
The original image. |
required |
factor
|
float
|
Factor by which to enhance the color balance. |
1.1
|
Returns:
Image: Color-corrected image.
Source code in devices\raspberry_pi_5\src\camera\abstracts.py
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
|
record_video(width, height, duration, file_path, encoder)
abstractmethod
Record a video with the camera.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
width
|
int
|
Width of the video. |
required |
height
|
int
|
Height of the video. |
required |
duration
|
int
|
Duration of the video in seconds. |
required |
file_path
|
str
|
Path to save the recorded video file. |
required |
encoder
|
Encoder to use for video recording. |
required |
Source code in devices\raspberry_pi_5\src\camera\abstracts.py
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
|
PhotographerABC
Bases: ABC
Abstract class to handle image processing for the camera.
Source code in devices\raspberry_pi_5\src\camera\abstracts.py
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 |
|
logger()
abstractmethod
Get the logger instance for the Photographer.
Returns:
Name | Type | Description |
---|---|---|
Logger |
Logger
|
The logger instance. |
Source code in devices\raspberry_pi_5\src\camera\abstracts.py
112 113 114 115 116 117 118 119 120 |
|
run()
abstractmethod
Loop to capture images and put them in the input photographer.
Source code in devices\raspberry_pi_5\src\camera\abstracts.py
146 147 148 149 150 151 |
|
multiprocessing
photographer_target(debug, images_queue, capture_image_event, start_event, stop_event, writer_messages_queue, preprocess_fn, server_messages_queue=None)
Target function for a multiprocessing process that handles photography tasks.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
debug
|
bool
|
Flag to indicate if the photographer is in debug mode. |
required |
images_queue
|
Queue
|
Queue to hold input images for processing. |
required |
capture_image_event
|
Event
|
Event to signal when an image should be captured. |
required |
start_event
|
Event
|
Event to signal when the photographer should start. |
required |
stop_event
|
Event
|
Event to signal when the logger should stop. |
required |
writer_messages_queue
|
Queue
|
Queue to hold log messages. |
required |
preprocess_fn
|
Callable[[Image], ndarray]
|
Callable[[Image], np.ndarray]: Function to preprocess images before inference. |
required |
server_messages_queue
|
Optional[Queue]
|
Queue to broadcast messages through the websockets server, if any. |
None
|
Source code in devices\raspberry_pi_5\src\camera\multiprocessing.py
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 |
|
photographer
Photographer
Bases: PhotographerABC
, LoggerConsumerProtocol
Class to handle image processing for the camera.
Source code in devices\raspberry_pi_5\src\camera\photographer.py
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 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 |
|
__del__()
Destructor to clean up resources when the photographer is no longer needed.
Source code in devices\raspberry_pi_5\src\camera\photographer.py
207 208 209 210 211 212 213 214 215 216 |
|
__init__(debug, camera, images_queue, capture_image_event, start_event, stop_event, writer_messages_queue, preprocess_fn, server_messages_queue=None)
Initialize the Photographer class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
debug
|
bool
|
Flag to indicate if the photographer is in debug mode. |
required |
camera
|
CameraABC
|
Camera instance for capturing images. |
required |
images_queue
|
Queue
|
Queue to hold input images for processing. |
required |
capture_image_event
|
Event
|
Event to signal when an image should be captured. |
required |
start_event
|
Event
|
Event to signal when the photographer should start. |
required |
stop_event
|
Event
|
Event to signal when the photographer should stop processing images. |
required |
writer_messages_queue
|
Queue
|
Queue to hold log messages. |
required |
preprocess_fn
|
Callable[[Image], ndarray]
|
Callable[[Image], np.ndarray]: Function to preprocess images before inference. |
required |
server_messages_queue
|
Optional[Queue]
|
Queue to broadcast messages through the websockets server, if any. |
None
|
Source code in devices\raspberry_pi_5\src\camera\photographer.py
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 |
|
server
StreamingServer
Bases: BaseHTTPRequestHandler
Streaming server for live video feed.
Source code in devices\raspberry_pi_5\src\camera\server\__init__.py
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 |
|
do_GET()
Handle GET requests for the streaming server.
Source code in devices\raspberry_pi_5\src\camera\server\__init__.py
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 |
|
generate_frames()
staticmethod
Generate frames from the camera using libcamera-vid.
Source code in devices\raspberry_pi_5\src\camera\server\__init__.py
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 |
|