如何从openCV捕获的cv2.VIDEOCAPTURE()捕获的Tello SDK 2.0流。

发布于 2025-01-31 22:56:52 字数 1716 浏览 3 评论 0原文

我想编写一个代码,并实时显示带有Yolov5 Torch模型的Tello流,而潜伏期低。

但是我坚持如何使用cv2.videocapture()与tello。

from threading import Thread
from djitellopy import Tello
import cv2, math, time
import os


tello = Tello()
tello.connect(False)
tello.streamon()
print(tello.get_udp_video_address())
print(type(tello.get_udp_video_address()))
cap = cv2.VideoCapture(tello.get_udp_video_address())
try:
    while True:
        img = cap.read()
        cv2.imshow('frame', img)
except KeyboardInterrupt:
    exit(1)
finally:
    print("fin")

输出:

[INFO] tello.py - 107 - Tello instance was initialized. Host: '192.168.10.1'. Port: '8889'.
[INFO] tello.py - 422 - Send command: 'command'
[WARNING] tello.py - 432 - Aborting command 'command'. Did not receive a response after 7 seconds
[INFO] tello.py - 422 - Send command: 'command'
[INFO] tello.py - 446 - Response command: 'ok'
[INFO] tello.py - 422 - Send command: 'streamon'
[INFO] tello.py - 446 - Response streamon: 'ok'
udp://@0.0.0.0:11111
<class 'str'>
fin
Traceback (most recent call last):
  File "bruh.py", line 16, in <module>
    cv2.imshow('frame', img)
cv2.error: OpenCV(4.5.5) :-1: error: (-5:Bad argument) in function 'imshow'
> Overload resolution failed:
>  - mat is not a numerical tuple
>  - Expected Ptr<cv::cuda::GpuMat> for argument 'mat'
>  - Expected Ptr<cv::UMat> for argument 'mat'

[INFO] tello.py - 422 - Send command: 'streamoff'

我想使用cv2.videocapture(),因为有更多的源使用网络摄像头&amp;实时对象检测。我已经尝试了多种方法来处理它,但是它们似乎对我不起作用。方法包括给捕获一个随机的UDP端口,并让其找出正确的一个端口。

感谢任何人的回应。

I want to write a code, showing stream from tello with yolov5 torch model in real-time with low latency.

But I am stuck with how to use cv2.VideoCapture() with tello.

from threading import Thread
from djitellopy import Tello
import cv2, math, time
import os


tello = Tello()
tello.connect(False)
tello.streamon()
print(tello.get_udp_video_address())
print(type(tello.get_udp_video_address()))
cap = cv2.VideoCapture(tello.get_udp_video_address())
try:
    while True:
        img = cap.read()
        cv2.imshow('frame', img)
except KeyboardInterrupt:
    exit(1)
finally:
    print("fin")

output:

[INFO] tello.py - 107 - Tello instance was initialized. Host: '192.168.10.1'. Port: '8889'.
[INFO] tello.py - 422 - Send command: 'command'
[WARNING] tello.py - 432 - Aborting command 'command'. Did not receive a response after 7 seconds
[INFO] tello.py - 422 - Send command: 'command'
[INFO] tello.py - 446 - Response command: 'ok'
[INFO] tello.py - 422 - Send command: 'streamon'
[INFO] tello.py - 446 - Response streamon: 'ok'
udp://@0.0.0.0:11111
<class 'str'>
fin
Traceback (most recent call last):
  File "bruh.py", line 16, in <module>
    cv2.imshow('frame', img)
cv2.error: OpenCV(4.5.5) :-1: error: (-5:Bad argument) in function 'imshow'
> Overload resolution failed:
>  - mat is not a numerical tuple
>  - Expected Ptr<cv::cuda::GpuMat> for argument 'mat'
>  - Expected Ptr<cv::UMat> for argument 'mat'

[INFO] tello.py - 422 - Send command: 'streamoff'

I want to use cv2.VideoCapture(), since there're more sources with webcam & real-time objects detection. I have tried many ways to deal with it but they seems didn't work for me. Ways include give capture a random udp port and let it find out the correct one itself.

Appreciate anyone's response.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

Bonjour°[大白 2025-02-07 22:56:52

这是从Tello获取视频流的基本代码:

from djitellopy import tello
import cv2

me = tello.Tello()
#cap = cv2.VideoCapture(0)
me.connect()
print(me.get_battery())
me.streamon()


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

这样做时,您必须调用'tello.streamon()',然后在循环中您制作该图像变量:

img = me.get_frame_read().frame

我将其与您的代码合并,这是结果:

from threading import Thread
from djitellopy import Tello
import cv2, math, time
import os


tello = Tello()
tello.connect()#
tello.streamon()
#print(tello.get_udp_video_address())
#print(type(tello.get_udp_video_address()))
#cap = cv2.VideoCapture(tello.get_udp_video_address())

try:
    while True:
        img = tello.get_frame_read().frame#
        cv2.imshow('frame', img)
        cv2.waitKey(1)#
except KeyboardInterrupt:
    exit(1)
finally:
    print("fin")

我在每次添加/更改并评论了所有不安全的所有内容后,都提出了一个注释/#,您基本上只需要调用img = tello.get_frame_frame_read.frame.frame and us good。然后显示它并添加1 milisec的延迟。我建议您观看此视频: https://www.youtube.com/watch = v = v = lmecyqnfpda ,它有很多您可能想尝试的很酷的东西。享受!

this is the basic code for getting video stream from the tello:

from djitellopy import tello
import cv2

me = tello.Tello()
#cap = cv2.VideoCapture(0)
me.connect()
print(me.get_battery())
me.streamon()


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

when doing that, you have to call 'tello.streamon()' and then in the loop you make that image variable:

img = me.get_frame_read().frame

i merged it with your code and this is the result:

from threading import Thread
from djitellopy import Tello
import cv2, math, time
import os


tello = Tello()
tello.connect()#
tello.streamon()
#print(tello.get_udp_video_address())
#print(type(tello.get_udp_video_address()))
#cap = cv2.VideoCapture(tello.get_udp_video_address())

try:
    while True:
        img = tello.get_frame_read().frame#
        cv2.imshow('frame', img)
        cv2.waitKey(1)#
except KeyboardInterrupt:
    exit(1)
finally:
    print("fin")

I put a comment/# after everyting i added/changed and commented out everything that was uneccesary, you basically had to just call img = tello.get_frame_read.frame and ur good. then just show it and add a delay of 1 milisec. and i suggest you watch this video: https://www.youtube.com/watch?v=LmEcyQnfpDA , it has a bunch of cool stuff you might wanna try out. enjoy!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文