Originally published at: let’s GO Stream – BrainPad
BrainPad Rave Stream with Python
The BrainPad Rave Stream with Python project represents an innovative compatibility of BrainPad Microcomputers and the universal Python programming language, showcasing the BrainPad microcomputer’s ability to create a dynamic interplay between hardware and software components.
How It Works
This project shows the development of Python code capable of streaming live camera frames from a computer onto the colorful LCD screen of the BrainPad Rave microcomputer.
The hardware requirements for this project are elegantly minimalistic, demanding only a BrainPad Rave and a standard USB cable for establishing a connection. In scenarios where the computer or laptop doesn’t have an integrated camera, we need an external USB camera to be connected to any available USB port.
Executing this project successfully requires a Python version 3.10 or above. Additionally, certain crucial software components must be installed, including the CV2 library for computer vision tasks using this command:
pip install opencv-python
And The DUE Link library using the command:
pip install DUELink
The provided code initiates the connection with the BrainPad Rave through any available port. Subsequently, it continuously captures frames from the designated camera, resizes them to match the dimensions of the BrainPad Rave LCD screen, and converts the color type to RGBA.
The code snippet begins by establishing the BrainPad connection and accessing the camera feed through OpenCV. It clears the Rave LCD screen before initiating the streaming loop. The captured frames are resized and color-transformed, and their bytes matrix is then drawn onto the Rave LCD with a 16-bit color range.
The captured frames are then processed, converted to a matrix of bytes, and seamlessly drawn onto the Rave LCD with a 16-bit color range, transcending in a stunning real-time streaming experience.
import cv2 from DUELink.DUELinkController import DUELinkController # Initialize BrainPad Connection availablePort = DUELinkController.GetConnectionPort() BrainPad = DUELinkController(availablePort) # Open the camera (default laptop camera index is usually 0 / USB camera index is usually 1) cap = cv2.VideoCapture(1) # Clear the LCD screen before streaming BrainPad.Display.Clear(0) while True: # Read a frame from the camera ret, frame = cap.read() if not ret: print("Error reading frame") break # Set the Rave LCD dimensions heightRave = 160 widthRave = 120 # Resize the frame to 160x120 (BrainPad Rave) frameRave = cv2.resize(frame, (heightRave, widthRave)) # Convert the frame color form BGRA to RGBA frameRave = cv2.cvtColor(frameRave, cv2.COLOR_BGRA2RGBA) # Display the camera output on the computer screen cv2.imshow('Camera Output', frameRave) # Convert the frame to a matrix of bytes rave_frame_matrix = frameRave.tobytes() # Draw the bytes matrix on the Rave LCD with 16 bits BrainPad.Display.DrawBuffer(rave_frame_matrix, 16) # Break the loop when the 'q' key is pressed if cv2.waitKey(1) & 0xFF == ord('q'): break # Release the camera and close all OpenCV windows cap.release() cv2.destroyAllWindows()