我目前在使用OpenCV的python上遇到了高视频流延迟。我已经设置了视频流,但当用pygame手动控制无人机时,延迟(约800毫秒(很难处理。我知道这不是无人机,因为当我使用Tello应用程序时,延迟是不明显的。有人有使用Tello无人机进行视频流传输的经验吗?
我在Windows 10中使用了以下代码,可以毫不延迟地显示来自无人机的视频流。但是,请注意,这使用了tellopy库。
def video_thread():
global drone
global run_video_thread
global av
print('START Video thread')
drone.start_video()
try:
container = av.open(drone.get_video_stream())
frame_count = 0
while True:
for frame in container.decode(video=0):
frame_count = frame_count + 1
image = cv2.cvtColor(numpy.array(frame.to_image()), cv2.COLOR_RGB2BGR)
cv2.imshow('Original', image)
cv2.waitKey(1)
cv2.destroyWindow('Original')
except KeyboardInterrupt as e:
print('KEYBOARD INTERRUPT Video thread ' + e)
except Exception as e:
exc_type, exc_value, exc_traceback = sys.exc_info()
print('EXCEPTION Video thread ' + e)
def main():
global drone
drone = tellopy.Tello()
drone.connect()
try:
threading.Thread(target=video_thread).start()
except e:
print(str(e))
finally:
print('Shutting down connection to drone...')
drone.quit()
exit(1)
if __name__ == '__main__':
main()