


import cv2
import os
import serial
from serial.tools import list_ports
import time
import pyrealsense2 as rs
import numpy as np
class FilaWall:
# Display Configuration
screenWidth = 5
screenHeight = 4
pixelWidth = screenWidth * 4
pixelHeight = screenHeight * 4
pipeline = None
ser = None
fps = 30
def init_realsense(self):
self.pipeline = rs.pipeline()
config = rs.config()
config.enable_stream(rs.stream.depth, 640, 480, rs.format.z16, self.fps)
self.pipeline.start(config)
def start_running(self):
while True:
frames = self.pipeline.wait_for_frames()
depth = np.asanyarray(frames.get_depth_frame().get_data())
dimg_gray = cv2.convertScaleAbs(depth, alpha=255/4000)
dimg_gray = cv2.flip(dimg_gray, 1)
gray_part = dimg_gray[0:480, 10:610]
gray_blur = cv2.blur(gray_part, (30, 30))
gray_rescaled = cv2.resize(gray_blur, (self.pixelWidth, self.pixelHeight))
ret, gray_thresh = cv2.threshold(gray_rescaled, 100, 255, cv2.THRESH_BINARY_INV)
for unitRow in range(self.screenHeight):
cols = range(self.screenWidth) if (unitRow % 2 == 0) else range(self.screenWidth - 1, -1, -1)
for unitCol in cols:
self._displayUnit(unitRow, unitCol, gray_thresh)
self._sendCmd(0x10) # sync signal
if cv2.waitKey(1) == ord('q'): break
#include <Arduino.h>
#define LED_OE 9
#define LED_LE 6
#define LED_CLK 3
#define LED_SDI 5
void setup() {
Serial.begin(115200);
pinMode(LED_OE, OUTPUT); pinMode(LED_LE, OUTPUT);
pinMode(LED_CLK, OUTPUT); pinMode(LED_SDI, OUTPUT);
digitalWrite(LED_OE, 0);
}
inline void toggleClock() { digitalWrite(LED_CLK, 1); digitalWrite(LED_CLK, 0); }
inline void toggleLatch() { digitalWrite(LED_LE, 1); digitalWrite(LED_LE, 0); }
void loop() {
while (Serial.available() > 0) readMsg(Serial.read());
}
void readMsg(char msg) {
char cmd = msg >> 4, data = msg & 0x0F;
if (cmd == 0x0) {
for (int i = 0; i < 4; ++i) { digitalWrite(LED_SDI, data & (0x1 << i)); toggleClock(); }
} else if (cmd == 0x1) {
toggleLatch();
}
}
乒乓显示器 / Ping-pong display: YouTube