Introduction
This article goes over how to save the DMA buffer to JPEG using python. The app subscribes to DMA camera topic and then uses vaal to process the frames which are then stored to a jpeg file.
Requirements
Before proceeding, ensure you have the following prerequisites:
- Maivin 2
- Requirements.txt.
- Access to the git repo here
Understanding the Code
- Parse Command-Line Arguments: The script parses command-line arguments using the ArgumentParser class from the argparse module. It allows specifying the connection point, running time, and topic to subscribe to.
- Initialize Zenoh Session: The script creates a Zenoh session with the specified connection point.
- Define Callback Function: A callback function message_callback(msg) is defined to handle received messages. It extracts image data from the received message, deserializes it into a DmaBuffer object, and processes the image.
- Register Exit Handler: An exit handler _on_exit() is defined to close the Zenoh session when the script terminates.
- Subscribe to Topic: The script declares a subscriber for the specified topic and sets the message callback function.
- Run the Subscriber: The script sleeps for the specified time duration while the subscriber receives messages.
The repo also has a docker file which goes over how to use the sample using a docker container, the container is self contained and should include all the dependencies inside the container it self. However as the sample requires access to the board resources it need to run as follow:
docker run -it --privileged --pid=host --network=host --entrypoint bash <NAME_OF_CONTAINER>
How to Use
To use the provided code:
- Clone the git repo from here.
- Ensure all prerequisites are installed on your system.
- Run the script with appropriate command-line arguments:
sudo -E python dmaSub.py
python dmaSub.py -h
usage: pid.py [-h] [-c CONNECT] [-t TIME] [topic]
Topics Example
positional arguments:
topic The topic to which to subscribe. Default: rt/camera/dma
options:
-h, --help show this help message and exit
-c CONNECT, --connect CONNECT
Connection point for the zenoh session, default='tcp/127.0.0.1:7447'
-t TIME, --time TIME Time to run the subscriber before exiting.
Comments
0 comments
Please sign in to leave a comment.