sacn icon indicating copy to clipboard operation
sacn copied to clipboard

dmxData is a tuple with a max length of 512! The data in the tuple has to be valid bytes!

Open harissutanrafiq opened this issue 7 months ago • 2 comments

SOLVED

I try send a dmx data from opencv frame to Arduino esp32, but error can you help me ..?

import cv2 import sacn

GRID_WIDTH = 64 GRID_HEIGHT = 64

num_pixels = GRID_WIDTH * GRID_HEIGHT num_channels_per_universe = 512 # Max channels per universe for DMX data

sender = sacn.sACNsender(source_name="Python Sender", universeDiscovery=False) sender.start()

num_universes = (num_pixels * 3 + num_channels_per_universe - 1) // num_channels_per_universe

cap = cv2.VideoCapture(0)

while True: ret, frame = cap.read() if not ret: break

frame = cv2.resize(frame, (GRID_WIDTH, GRID_HEIGHT))

frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)

frame_pixels = frame_rgb.reshape(-1, 3)


dmx_data = []
for pixel_color in frame_pixels:
    dmx_data.extend(pixel_color)
    

for i in range(num_universes):
    sender.activate_output(i+1)  # start sending out data in the 1st universe
    start_channel = i * num_channels_per_universe
    end_channel = start_channel + num_channels_per_universe
   
    sender[i+1].dmx_data = tuple(dmx_data[start_channel:end_channel])
    sender[i+1].destination = "192.168.0.101"  
    sender[i+1].send()


cv2.imshow('Video Stream', frame)

if cv2.waitKey(1) & 0xFF == ord('q'):
    break

cap.release() sender.stop() cv2.destroyAllWindows()

Traceback (most recent call last): File "sacntest.py", line 56, in <module> sender[i+1].dmx_data = tuple(dmx_data[start_channel:end_channel]) File "C:\python\lib\site-packages\sacn\sending\output.py", line 26, in dmx_data self._packet.dmxData = dmx_data File "C:\python\lib\site-packages\sacn\messages\data_packet.py", line 130, in dmxData raise ValueError(f'dmxData is a tuple with a max length of 512! The data in the tuple has to be valid bytes! ' ValueError: dmxData is a tuple with a max length of 512! The data in the tuple has to be valid bytes! Length was 512

harissutanrafiq avatar Jul 22 '24 14:07 harissutanrafiq