Grabar nubes de puntos
Grabe la nube de puntos a través de la API cuando la grabación deba iniciarla un programa, o cuando el Visor de la WebGUI no esté disponible.
El ejemplo utiliza la biblioteca de Python e inicia sesión con una clave de aplicación. Sustituya qb2-xxxxxxxxx por el nombre de host o la dirección IP de su sensor y application-key-for-qb2-xxxxxxxxx por el secreto de su clave.
Crear una grabación
El método Stream del servicio Record transmite los metadatos y los archivos de nube de puntos de una grabación.
El ejemplo los escribe en un archivo zip en el directorio en el que se ejecuta, hasta que usted pulsa Ctrl+C.
import pathlib
import zipfile
from datetime import datetime
import blickfeld_qb2
def stream_recording(zip_archive: zipfile.ZipFile) -> None:
# Create token factory using an application key
token_factory = blickfeld_qb2.TokenFactory(
application_key_secret="application-key-for-qb2-xxxxxxxxx"
)
# Open a secure connection to the sensor
with blickfeld_qb2.Channel("qb2-xxxxxxxxx", token=token_factory) as channel:
# Use recording service
recording_service = blickfeld_qb2.toolkit.services.Record(channel=channel)
# Request a recording stream from the sensor
for response in recording_service.stream(
# The type of point cloud to record, e.g. the full frame or only the foreground
point_cloud_type=blickfeld_qb2.percept_pipeline.data.PointCloudType.POINT_CLOUD_TYPE_FULL,
# Option to disable the states stream in the recording to reduce data
disable_states=False,
# Option to disable recording the tracked objects to reduce data
disable_objects=False,
# Option to disable streaming of .vtu and .pcd formats to reduce data
disable_vtu_and_pcd=False
):
# The recording service sets a flag if data is potentially lost
if response.data_loss:
print("Potential data loss e.g. due to low network bandwidth")
# Create a new file inside the zip archive
with zip_archive.open(response.file.path, mode="w") as zf:
# Write the data to the file
zf.write(response.file.binary)
# Set the name of the recording
recording_name = f"recording_{datetime.now().strftime('%Y-%m-%d_%H-%M-%S')}.zip"
# The recording will be saved under the recording name
output_zip = pathlib.Path(recording_name)
# Create a zipfile at the set path to store the data from the stream
with zipfile.ZipFile(output_zip, mode="w", compression=zipfile.ZIP_STORED) as zip_archive:
# Start the recording stream
print("Start recording ...")
try:
stream_recording(zip_archive)
# Stop the recording by pressing Ctrl+C
except KeyboardInterrupt:
zip_size_mb = sum([zinfo.file_size for zinfo in zip_archive.filelist]) / 1_000_000
print(f"Finished recording {recording_name} with size {round(zip_size_mb, ndigits=1)} MB.")
Estructura del archivo de grabación
|-📁 recording/ # Archive containing the recorded data
| |-📁 states/ # Output of the states stream
| |-states_timestamp-1.json # States captured at timestamp 1
| |-states_timestamp-2.json
| |- ...
|
| |-📁 objects/ # Output of the objects stream
| |-objects_timestamp-1.json # Tracked Objects at timestamp 1
| |-objects_timestamp-2.json
| |- ...
|
| |-📁 raw/ # Point clouds in Frame format
| |-frame_timestamp-1.pb # Frame at timestamp 1
| |-frame_timestamp-2.pb
| |- ...
|
| |-📁 metadata/ # Configurations saved as .json
| |-toolkitRecordStreamRequest.json # RecordStreamRequest that was sent to start the recording
| |-systemScanPattern.json # The ScanPattern of the sensor
| |-systemFirmware.json # The Firmware running on the sensor
| |-perceptPipelineReferenceFrame.json # The background point cloud as a Frame
| |-perceptPipelinePerception.json # The Perception settings of the sensor
| |-perceptPipelineZones.json # The configured zones as a list of ZoneAlgorithm, only when zones are configured
| |-perceptPipelineBackgroundModel.pb # The state of the dynamic background model, 10 to 20 MB, only with dynamic motion detection
| |-perceptPipelineDataSource.json # The configured DataSource
| |-hardwareIdentification.json # The product Identification
| |-coreProcessingAcceleration.json # The measured Acceleration
|
| |-frame_frame-id-1.vtu # Point cloud at frame-id-1 as .vtu (1)
| |-frame_frame-id-1.pcd # Point cloud at frame-id-1 as .pcd (2)
| |-frame_frame-id-2.vtu
| |-frame_frame-id-2.pcd
| |- ...
| 1 | Formato VTK Unstructured Grid. |
| 2 | Formato Point Cloud Data. |
En el líder de un enjambre, los directorios raw/ y metadata/ de cada sensor del enjambre, incluido el líder, se encuentran en sensors/<serial-number>/. La raíz contiene los directorios states/ y objects/, los archivos .vtu y .pcd y metadata/toolkitRecordStreamRequest.json.
Un sensor que procesa la nube de puntos de otro Qb2, fuera de un enjambre, graba la nube de puntos de ese Qb2 y su patrón de escaneo, firmware, identificación y aceleración. La configuración del procesamiento procede del sensor que graba.
Los campos de RecordStreamRequest reducen los datos:
| Campo | Efecto |
|---|---|
|
Omite el directorio |
|
Omite el directorio |
|
Omite los archivos |
|
Selecciona el PointCloudType que se graba, por ejemplo el fotograma completo o solo el primer plano. |
Sea cual sea el tipo, los fotogramas de la nube de puntos grabados se guardan siempre en el directorio raw/.