Hundemeier / sacn

A simple ANSI E1.31 (aka sACN) module for python.
MIT License
47 stars 21 forks source link

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

Open harissutanrafiq opened 1 month ago

harissutanrafiq commented 1 month ago

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 commented 1 month ago

hey iam forks and add custom port parameter https://github.com/harissutanrafiq/python_sacn_e131

and this is the result https://youtu.be/--cskecVTWU?si=6G72XJrXCMCE28Os

Hundemeier commented 1 month ago

According to the error ValueError: dmxData is a tuple with a max length of 512! The data in the tuple has to be valid bytes! Length was 512, either the length or the data types inside the tuple are wrong. As the error also states the length of 512, that does not seem to be an issue. I don't know anything about opencv, so I suspect your pixel_color is not a valid integer (an integer in the range 0 to 255).