Thermal Shared Memory Module

Thermal Shared Memory Reader

Provides a reusable class for reading thermal camera data from shared memory. Handles YUYV frame data, temperature arrays, and metadata.

pythermal.core.thermal_shared_memory.get_shm_name(device_index: int = 0) str[source]

Generate shared memory name based on device index.

Parameters:

device_index – Device index (0 for first device, 1 for second, etc.)

Returns:

Shared memory file path

class pythermal.core.thermal_shared_memory.FrameMetadata(seq: int, flag: int, width: int, height: int, min_temp: float, max_temp: float, avg_temp: float)[source]

Bases: NamedTuple

Frame metadata structure

seq: int

Alias for field number 0

flag: int

Alias for field number 1

width: int

Alias for field number 2

height: int

Alias for field number 3

min_temp: float

Alias for field number 4

max_temp: float

Alias for field number 5

avg_temp: float

Alias for field number 6

class pythermal.core.thermal_shared_memory.ThermalSharedMemory(shm_name: str = '/dev/shm/yuyv240_shm')[source]

Bases: object

Reader for thermal camera shared memory

Provides methods to read YUYV frames, temperature arrays, and metadata from the shared memory buffer created by the C++ thermal capture system.

__init__(shm_name: str = '/dev/shm/yuyv240_shm')[source]

Initialize thermal shared memory reader

Parameters:

shm_name – Path to shared memory file (default: /dev/shm/yuyv240_shm)

initialize() bool[source]

Initialize shared memory connection

Returns:

True if successful, False otherwise

is_initialized() bool[source]

Check if shared memory is initialized

get_metadata() FrameMetadata | None[source]

Read frame metadata from shared memory

Returns:

FrameMetadata named tuple, or None if not initialized

has_new_frame() bool[source]

Check if a new frame is available

Returns:

True if flag is set (new frame available), False otherwise

get_yuyv_frame() ndarray | None[source]

Read YUYV frame data from shared memory

Returns:

numpy array of shape (HEIGHT, WIDTH, 2) with YUYV data, or None if not initialized

get_temperature_array() ndarray | None[source]

Read raw temperature array (96x96) from shared memory

Returns:

numpy array of shape (TEMP_HEIGHT, TEMP_WIDTH) with uint16 temperature values, or None if not initialized

get_temperature_map_celsius() ndarray | None[source]

Get temperature map in Celsius (96x96)

Converts the raw temperature array to actual Celsius values using the metadata min/max temperatures for calibration.

Returns:

numpy array of shape (TEMP_HEIGHT, TEMP_WIDTH) with float32 Celsius values, or None if not initialized or metadata unavailable

mark_frame_read() bool[source]

Mark the current frame as read by setting flag to 0

This should be called after reading frame data to allow the producer to write new frames.

Returns:

True if successful, False otherwise

cleanup()[source]

Clean up resources and close shared memory