Camera
This module provides a Camera class for handling camera feed
CLASS | DESCRIPTION |
---|---|
Camera |
Camera class for handling camera feed |
Documentation last updated: 2025-02-22
Camera
Camera(
*,
connection_details: dict | None = None,
init_timeout: int = 1,
buffer_size: int = 2000,
simulation: bool = False,
verbose: bool = False,
**kwargs,
)
Camera class for handling camera feed
ATTRIBUTE | DESCRIPTION |
---|---|
placeholder |
Placeholder image
TYPE:
|
transforms |
List of transformations
TYPE:
|
callbacks |
List of callbacks
TYPE:
|
connection |
Connection to the device
TYPE:
|
connection_details |
Connection details for the device
TYPE:
|
flags |
Flags for the device
TYPE:
|
init_timeout |
Timeout for initialization
TYPE:
|
buffer |
Buffer for storing frames
TYPE:
|
data_queue |
Queue for storing data
TYPE:
|
show_event |
Event for showing the stream
TYPE:
|
stream_event |
Event for streaming
TYPE:
|
threads |
Threads for streaming and processing data
TYPE:
|
verbose |
Verbosity of class
TYPE:
|
feed |
Video feed
TYPE:
|
is_connected |
Whether the device is connected
TYPE:
|
verbose |
Verbosity of class
TYPE:
|
frame_rate |
Frame rate of camera feed
TYPE:
|
frame_size |
Frame size of camera feed
TYPE:
|
METHOD | DESCRIPTION |
---|---|
checkDeviceConnection |
Check the connection to the device |
connect |
Connect to the device |
connectFeed |
Connect to the camera feed |
disconnect |
Disconnect from the device |
disconnectFeed |
Disconnect from the camera feed |
setFrameRate |
Set the frame rate of camera feed |
setFrameSize |
Set the resolution of camera feed |
decodeBytesToFrame |
Decode byte array of image |
encodeFrameToBytes |
Encode image into byte array |
loadImageFile |
Load an image from file |
saveFrame |
Save image to file |
saveFramesToVideo |
Save frames to video file |
transformFrame |
Transform the frame |
processFrame |
Process the frame |
getFrame |
Get image from camera feed |
show |
Show image in window |
checkDeviceBuffer |
Check the connection buffer |
clear |
Clear the input and output buffers |
read |
Read data from the device |
showStream |
Show the stream |
startStream |
Start the stream |
stopStream |
Stop the stream |
stream |
Toggle the stream |
Initialize the camera object
PARAMETER | DESCRIPTION |
---|---|
connection_details
|
connection details for the device. Defaults to None.
TYPE:
|
init_timeout
|
timeout for initialization. Defaults to 1.
TYPE:
|
buffer_size
|
size of the buffer. Defaults to 2000.
TYPE:
|
simulation
|
whether to simulate the camera feed. Defaults to False.
TYPE:
|
verbose
|
verbosity of the class. Defaults to False.
TYPE:
|
checkDeviceBuffer
Check the connection buffer
RETURNS | DESCRIPTION |
---|---|
bool
|
whether the device buffer is available
TYPE:
|
checkDeviceConnection
Check the connection to the device
RETURNS | DESCRIPTION |
---|---|
bool
|
whether the device is connected
TYPE:
|
decodeBytesToFrame
staticmethod
Decode byte array of image
PARAMETER | DESCRIPTION |
---|---|
bytearray
|
byte array of image
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
ndarray
|
np.ndarray: image array of decoded byte array |
encodeFrameToBytes
staticmethod
Encode image into byte array
PARAMETER | DESCRIPTION |
---|---|
frame
|
image array to be encoded
TYPE:
|
extension
|
image format to encode to. Defaults to '.png'.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
bytes
|
byte array of image
TYPE:
|
getFrame
Get image from camera feed
PARAMETER | DESCRIPTION |
---|---|
latest
|
whether to get the latest image. Default to False.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
tuple[bool, ndarray]
|
tuple[bool, np.ndarray]: (whether an image is obtained, image array) |
loadImageFile
staticmethod
Load an image from file
PARAMETER | DESCRIPTION |
---|---|
filename
|
image filename
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
ndarray
|
np.ndarray: image array from file |
processFrame
staticmethod
processFrame(
frame: ndarray,
callbacks: Iterable[
tuple[
Callable[[ndarray, Any], ndarray],
Iterable | None,
Mapping | None,
]
]
| None = None,
) -> ndarray
Process the frame
PARAMETER | DESCRIPTION |
---|---|
frame
|
image array to be processed
TYPE:
|
callbacks
|
list of callbacks. Defaults to None.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
ndarray
|
np.ndarray: processed image array |
read
Read data from the device
RETURNS | DESCRIPTION |
---|---|
tuple[bool, ndarray]
|
tuple[bool, np.ndarray]: (whether data is received, data) |
saveFrame
staticmethod
Save image to file
PARAMETER | DESCRIPTION |
---|---|
frame
|
frame array to be saved
TYPE:
|
filename
|
filename to save to. Defaults to 'image.png'.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
bool
|
whether the image array is successfully saved
TYPE:
|
saveFramesToVideo
staticmethod
saveFramesToVideo(
frames: Iterable[ndarray],
fps: int | float,
filename: str | None = None,
) -> bool
Save frames to video file
PARAMETER | DESCRIPTION |
---|---|
frames
|
list of frames to be saved
TYPE:
|
fps
|
frame rate of video
TYPE:
|
filename
|
filename to save to. Defaults to 'video.mp4'.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
bool
|
whether the video is successfully saved
TYPE:
|
setFrameRate
Set the frame rate of camera feed
PARAMETER | DESCRIPTION |
---|---|
fps
|
frame rate in frames per second. Defaults to 30.0.
TYPE:
|
setFrameSize
Set the resolution of camera feed
PARAMETER | DESCRIPTION |
---|---|
size
|
width and height of feed in pixels. Defaults to (10000,10000).
TYPE:
|
show
Show image in window
PARAMETER | DESCRIPTION |
---|---|
transforms
|
list of transformations. Defaults to None.
TYPE:
|
showStream
Show the stream
PARAMETER | DESCRIPTION |
---|---|
on
|
whether to show the stream
TYPE:
|
startStream
startStream(
buffer: deque | None = None,
*,
show: bool = False,
sync_start: Barrier | None = None,
)
Start the stream
PARAMETER | DESCRIPTION |
---|---|
buffer
|
buffer to store frames. Defaults to None.
TYPE:
|
show
|
whether to show the stream. Defaults to False.
TYPE:
|
sync_start
|
synchronization barrier. Defaults to
TYPE:
|
stream
Toggle the stream
PARAMETER | DESCRIPTION |
---|---|
on
|
whether to start the stream
TYPE:
|
buffer
|
buffer to store frames. Defaults to None.
TYPE:
|
sync_start
|
synchronization barrier. Defaults to None.
TYPE:
|
transformFrame
staticmethod
transformFrame(
frame: ndarray,
transforms: Iterable[
tuple[
Callable[[ndarray, Any], ndarray],
Iterable | None,
Mapping | None,
]
]
| None = None,
) -> ndarray
Transform the frame
PARAMETER | DESCRIPTION |
---|---|
frame
|
image array to be transformed
TYPE:
|
transforms
|
list of transformations. Defaults to None.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
ndarray
|
np.ndarray: transformed image array |