Hello Tello Pilot!
Join our DJI Tello community & remove this banner.
Sign up

Issues with Tello video stream to Windows Computer

mbrh

New member
Joined
May 16, 2021
Messages
3
Reaction score
1
Hi everyone!

I am trying to follow along Murtaza's Workshop YouTube "Drone Programming With Python Course | 3 Hours | Including x4 Projects | Computer Vision" course:


However I have hit a wall at the imageCapture section.

The Tello drone connects to the computer and I can use the basic movements commands without any difficulty, having the drone take off / move around with commands issued from the laptop. However when I try to run the code below to get a video stream:

from djitellopy import tello
import cv2

me = tello.Tello()
me.connect()
print(me.get_battery())

me.streamon()

while True:
img = me.get_frame_read().frame
img = cv2.resize(img, (360, 240))
cv2.imshow("Image", img)
cv2.waitKey(1)

the code returns the error:

[h264 @ 000001d171fc08c0] non-existing PTraceback (most recent call last):
File "C:/Users/Andrew Rudy/PycharmProjects/TelloDroneYouTubeProject/Video test 2.py", line 11, in <module>
frame_read = tello.get_frame_read()
File "C:\Users\Andrew Rudy\PycharmProjects\TelloDroneYouTubeProject\venv\lib\site-packages\djitellopy\enforce_types.py", line 54, in wrapper
return func(*args, **kwargs)
File "C:\Users\Andrew Rudy\PycharmProjects\TelloDroneYouTubeProject\venv\lib\site-packages\djitellopy\tello.py", line 404, in get_frame_read
self.background_frame_read = BackgroundFrameRead(self, address) # also sets self.cap
File "C:\Users\Andrew Rudy\PycharmProjects\TelloDroneYouTubeProject\venv\lib\site-packages\djitellopy\tello.py", line 932, in __init__
raise Exception('Failed to grab first frame from video stream')

If you debug look at the return value for the Frame = "None" so there is no stream is coming back to the computer. Also seen in the returned "raise Exception('Failed to grab first frame from video stream')".

I have tried to turn the firewall completely off and also to create special inbound rules to allow the UDP port 11111 to come through, however that has not solved the issue.

I am using Windows 10, pycharm, and have tried this with Python 3.7 and 3.9. Additionally I have tried it with djitello and djitello2, am using opencv-python 4.5.2.52.

The issue isn't with the Tello drone - it can send a video to my phone, and my friend ran the same code on his laptop (running on Linux) and it opened up a live stream.

Does anyone have any idea how to troubleshoot this or what may be wrong? Thanks in advance!
 
Last edited:
  • Like
Reactions: skygawk310
So I got it to work by changing the tello.py file


in line 930 I changed the if statement to a while statement for grabbing the first frame. It appears that my computer took longer to initialize that first frame and the exception would cancel out the code.

```
self.grabbed, self.frame = self.cap.read()
while not self.grabbed or self.frame is None:
print('still trying to grab first frame')
self.grabbed, self.frame = self.cap.read()
```

This gave it time to be able to grab the first frame and initialize. Going to see if I can find a workaround that doesn't involve editing the tello.py file.

If you look around online it seems that a lot of people are having this issue so it might be nice if the base file could be updated.
 
I was having this same issue and this solved the problem. Thank you so much!
 
Dear all,

I have similar issue on Windows 10 /Python 3.7.7 / OpenCV 4.5.3
Tello live video is feed is given into Yolo4 /Darknet for Real Object Detection. i.e from Tello video, i can find the object like wall crack. of course, using deep learning framework.. here Darknet.

I am importing the video feed from the blow file (tello_live_video_3_copy.py) to Darknet. ( i.e darknet_video.py)

darknet_video --> takes Web camera video - no issue. When i try with tello_live_video_3_copy.py - code - this script works as a standalone with Tello Edu. ( after removing comments part)
Later, i comment try to import the udp_video_address then it works some time without error but most of the time gives error like this ..any suggestion welcome.. This methods works in Ubuntu 20.4 but Windows got some issue. Trying to solve this for last 1 week.. Please advise ..many thanks.
Cheers!
-Chandra
darknet_import.jpg

Monday_tello_opencv_2.jpg

Python:
#!/usr/bin/python3 
 #File name:  tello_live_video_3_copy.py
import socket
import threading
import time

import cv2
import sys
import time
import platform
import numpy as np
from tello import Tello

tello_ip = '192.168.10.1'
tello_port = 8889

tello_address = (tello_ip, tello_port)


# Receiving from tello
VS_UDP_IP = '0.0.0.0'
VS_UDP_PORT = 11111

# Preparing Objects for VideoCapture
cap = None
#Object preparation for data receiving
response = None

drone_instance = Tello()
time.sleep(2)
drone_instance.connect()
#drone_instance.takeoff()
drone_instance.streamon()


# # Create sockets for communication
# # Address family: AF_INET (IPv4), Socket type: SOCK_DGRAM (UDP)
serversocket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
serversocket.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1)

def socketclose():
                serversocket.close()
#Functions for receiving data

def run_udp_receiver():
    while True:
        try:
            response,_ = serversocket.recvfrom(1024)
            print (response.decode (encoding = "utf-8"))
          
          
        except Exception as e:
            #socketclose()
            print ("**** Exit recv_****")
            print(e)
            break

thread = threading.Thread(target=run_udp_receiver,args=())
thread.daemon = True
thread.start()

# # Start of video streaming
# serversocket.sendto('streamon'.encode('utf-8'), tello_address)
          
udp_video_address = ('udp://@' + VS_UDP_IP + ':' + str(VS_UDP_PORT))

# if cap is None:
    # cap = cv2.VideoCapture(udp_video_address)
# if not cap.isOpened():
    # cap.open(udp_video_address)
# while True:
    # ret, frame = cap.read()
    # if ret:
    # Any preprocessing you want to make on the frame goes here
        # frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
     
          
        # cv2.imshow('tello', frame)
    # if cv2.waitKey(1) & 0xFF == ord('q'):
        # break
# cap.release()
# cv2.destroyAllWindows()

 # Stop video streaming
 # socket.sendto('streamoff'.encode('utf-8'), tello_address)

 # Landing
 # socket.sendto('land'.encode('utf-8'), tello_address)
 #video_capture ()
 
Last edited:
Solved the issue. in the video capture code, if some ret is empty ,it was designed to break. now change to continue
Hope it will useful for use Darknet library code on Windows 10.

Code:
def video_capture(frame_queue, darknet_image_queue):
    global stopflyingevent
    while not stopflyingevent.isSet():
        while cap.isOpened():
            ret, frame = cap.read()
            #print("***** video capture ...")
            if not ret:
                #print("#########video capture 1 ...")
                continue //earlier it was break
 

New Posts

Members online

No members online now.

Forum statistics

Threads
5,690
Messages
39,934
Members
17,023
Latest member
Repiv

New Posts