Skip to content

embeddip/PyDIPLink

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PyDIPLink

Source repository: https://github.com/embeddip/PyDIPLink

PyDIPLink is a Python package for transferring images, JPEG frames, and one-dimensional signal data between a computer and an embedded device over UART. It is used with the embedded examples from the book Embedded Digital Image Processing with Microcontrollers.

Features

  • Send images from a computer to an embedded device.
  • Receive raw images from an embedded device.
  • Receive and record JPEG frame streams.
  • Receive one-dimensional signal data, such as histograms.
  • Support RGB888, RGB565, grayscale, YUV, HSV, and JPEG data.

Installation

Install from PyPI:

pip install pydiplink

Install from source:

git clone https://github.com/embeddip/PyDIPLink.git
cd PyDIPLink
pip install -e .

Command Line Use

Start the receiver with the default serial settings:

pydiplink

Specify the serial port and baud rate:

pydiplink --port /dev/ttyUSB1 --baud 115200
pydiplink --port COM3 --baud 500000

Set a default image to send when the embedded device requests one:

pydiplink --image input.jpg

Record received JPEG frames to a video file:

pydiplink --record --output video.avi --fps 15

Python Use

Record JPEG frames from Python:

from pydiplink import JpegVideoWriter, receive_and_show_jpeg

with JpegVideoWriter("output.avi", fps=30, resolution=(640, 480)) as writer:
    for _ in range(300):
        frame = receive_and_show_jpeg(ser)
        if frame is not None:
            writer.write_frame(frame)

Receive one-dimensional signal data:

import serial
from pydiplink import receive_1d_signal

ser = serial.Serial("/dev/ttyUSB0", 500000, timeout=5)
signal_data = receive_1d_signal(ser, plot=True, save_path="histogram")
ser.close()

Protocol

The embedded device sends a three-byte command to select the transfer type:

  • STR: device requests an image from the computer.
  • STW: device sends a raw image to the computer.
  • STJ: device sends a JPEG frame to the computer.
  • ST1: device sends one-dimensional signal data.

PyDIPLink handles the serial transfer, timeouts, validation, and file output for these commands.

Configuration

The command line tool can read default settings from environment variables:

export DIPLINK_PORT=/dev/ttyUSB0
export DIPLINK_BAUD=500000
export DIPLINK_IMAGE=input.jpg

Images are limited to 4096 by 4096 pixels and 50 MB.

Examples

Complete examples are available in examples/:

  • basic_image_transfer.py: send and receive images.
  • jpeg_streaming.py: receive JPEG streams.

Documentation

See docs/API.md for API documentation.

License

This project is licensed under the MIT License. See LICENSE for details.

Author

Developed by Ozan Durgut for embedded systems and digital image processing examples.

Packages

 
 
 

Contributors

Languages