import pylwdrone
import cv2
import numpy as np
# Initialize the LWDrone object
drone = pylwdrone.LWDrone()
# Start the video stream
for packet in drone.start_video_stream():
try:
# Print the size of the frame data
print("Packet frame bytes size:", len(packet.frame_bytes))
# Print a portion of the frame data (first 100 bytes)
print("First 100 bytes of frame data:", packet.frame_bytes[:100])
# Convert the frame data to numpy array
frame = np.frombuffer(packet.frame_bytes, dtype=np.uint8)
# Get the actual frame shape
frame_shape = frame.shape
print("Actual frame shape:", frame_shape)
# Reshape the frame data
frame = frame.reshape((frame_shape[0]//3, 3))
# Display the frame
cv2.imshow("Debug Frame", frame)
# Check for 'q' key to exit
if cv2.waitKey(1) & 0xFF == ord('q'):
break
except ValueError as ve:
print("ValueError:", ve)
# Skip this frame and continue to the next one
continue
except Exception as e:
print("An error occurred:", e)
break
# Clean up
cv2.destroyAllWindows()
drone.stop_video_stream()
error::
Actual frame shape: (31621,)
ValueError: cannot reshape array of size 31621 into shape (10540,3)
Packet frame bytes size: 45509
First 100 bytes of frame data: bytearray(b”x00x00x00x01Ax9ax00x10x00 #xbfxf4 xb7xe8xe0xd3xb5x87xe3xb8x0cxc8xecNxe1Cxb4px18xb682 xb4efx15xc3Btxd3^zx94iFx05x89x1fxd0xd3x1fxa1xe7x12 ‘x8f2tx017[lx1c{[TAx8eLxb6xf7xd0/xc9xb1xfaxa2xc1xbdwx98fdx86x84xbcB$x1d*qxf7x02x1c") Actual frame shape: (45509,) ValueError: cannot reshape array of size 45509 into shape (15169,3) Packet frame bytes size: 20981 First 100 bytes of frame data: bytearray(b"x00x00x00x01Ax9ax00x12x00$!x0fxe2xb8xe0xfdx0cxfbRxd5.x18x94L>xc6xafxa6xbaNxf7x83^Mxff
Qxc1xf7x95uxb2xe00x14x92zx94xf2Vxafe~xc4xaaxa0;,^x8b*x14x00xa9xeaxb8=xc0txd3axbe. ‘xbfxacxd7xf7x84x83x11xe2xc9x80x1axe1Gx89xf9xc4xd1xdfXxfcxcdx98xe3uxed”)
Actual frame shape: (20981,)
ValueError: cannot reshape array of size 20981 into shape (6993,3)
Packet frame bytes size: 23269
i am trying to stream the video from my drone using ffmpeg-python and opencv
Saail Chavan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.