Skip to content

Instantly share code, notes, and snippets.

@AncientJames
Created February 28, 2025 02:14
Show Gist options
  • Save AncientJames/31faf6852ea50176702ac05153de4997 to your computer and use it in GitHub Desktop.
Save AncientJames/31faf6852ea50176702ac05153de4997 to your computer and use it in GitHub Desktop.
This is the TPC I used to pixel map the Fibrovisor ( https://www.youtube.com/watch?v=zz59e1wWyVc ). It uses rgbmatrix ( https://github.com/hzeller/rpi-rgb-led-matrix ) to light up one pixel at a time, and opencv to record the position of the brightest spot in the frame.
#!/usr/bin/env python
import time
import sys
import getpass
from rgbmatrix import RGBMatrix, RGBMatrixOptions
import cv2 as cv
options = RGBMatrixOptions()
options.hardware_mapping = 'regular'
options.rows = 64
options.cols = 64
options.chain_length = 1
options.parallel = 1
options.gpio_slowdown = 2
options.disable_hardware_pulsing = getpass.getuser() != 'root'
matrix = RGBMatrix(options = options)
row_zero = 21
row_step = 2
field_step = matrix.height // 2
try:
cap = cv.VideoCapture('/dev/video0')
x = 0
y = 0
row = row_zero
radius = 11
while cap.isOpened():
matrix.Clear()
matrix.SetPixel(x, row, 0, 255, 0)
print(f'{x},{y}, ', end='')
x += 1
if x >= 64:
x = 0
y = (y + 1) % 8
row = row_zero + (y % 4) * row_step + (y // 4) * field_step
for i in range(2):
ret, frame = cap.read()
if not ret:
break
smooth = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)
smooth = cv.GaussianBlur(smooth, (radius, radius), 0)
(minVal, maxVal, minLoc, maxLoc) = cv.minMaxLoc(smooth)
cv.circle(frame, maxLoc, radius, (255, 0, 0), 2)
print(f'{maxLoc[0]},{maxLoc[1]}, {int(maxVal)}')
cv.imshow('frame', frame)
if cv.waitKey(1) == ord('q'):
break
time.sleep(0.2)
cap.release()
except KeyboardInterrupt:
sys.exit(0)
@ItaloSwiss
Copy link

Et ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment