0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【 Tello & OpenCV 】key = cv2.waitKey()を削除すると、フレーム画像のウィンドウ表示ができなくなるので、みんな気をつけよう

Last updated at Posted at 2021-08-02

__key = cv2.waitKey(1) & 0xff__のコードは消したり、コメントアウトすると、Telloから画像を受信して、Macbookのウィンドウに出なくなる。

そこで、今回は、key = cv2.waitKey(1) & 0xffで取得したkey変数__ではなく、Python組込の*input("")*メソッド__を使って、Terminalから標準入力されたキーボード入力を受け取る場合も、この行は、残しておく必要がある。

( 参考 )

画像出力に成功するスクリプト

OKスクリプト1
# key = cv2.waitKey(1) & 0xffを削除すると、画像が入らなくなる。
# かなり遅延して画像が入る。
import sys
import traceback
import tellopy
import av
import cv2.cv2 as cv2  # for avoidance of pylint error
import numpy
import time

def main():
    drone = tellopy.Tello()
    drone.connect()
    drone.wait_for_connection(60.0)

    container = av.open(drone.get_video_stream())
    #frame_skip=300
    
    for frame in container.decode(video=0):
        image = cv2.cvtColor(numpy.array(frame.to_image()), cv2.COLOR_RGB2BGR)
        cv2.imshow("org",image)
        key = cv2.waitKey(1) & 0xff
       #key = cv2.waitKey(1)

if __name__ == '__main__':
    main()
    

画像出力に成功するスクリプト

OKスクリプト1
# key = cv2.waitKey(1) & 0xffを削除すると、画像が入らなくなる。
# かなり遅延して画像が入る。
import sys
import traceback
import tellopy
import av
import cv2.cv2 as cv2  # for avoidance of pylint error
import numpy
import time

def main():
    drone = tellopy.Tello()
    drone.connect()
    drone.wait_for_connection(60.0)

    container = av.open(drone.get_video_stream())
    #frame_skip=300
    
    for frame in container.decode(video=0):
        image = cv2.cvtColor(numpy.array(frame.to_image()), cv2.COLOR_RGB2BGR)
        cv2.imshow("org",image)
       #key = cv2.waitKey(1) & 0xff
        key = cv2.waitKey(1)

if __name__ == '__main__':
    main()
    

画像出力に失敗するスクリプト

OKスクリプト1
# key = cv2.waitKey(1) & 0xffを削除すると、画像が入らなくなる。
# かなり遅延して画像が入る。
import sys
import traceback
import tellopy
import av
import cv2.cv2 as cv2  # for avoidance of pylint error
import numpy
import time

def main():
    drone = tellopy.Tello()
    drone.connect()
    drone.wait_for_connection(60.0)

    container = av.open(drone.get_video_stream())
    #frame_skip=300
    
    for frame in container.decode(video=0):
        image = cv2.cvtColor(numpy.array(frame.to_image()), cv2.COLOR_RGB2BGR)
        cv2.imshow("org",image)
       #key = cv2.waitKey(1) & 0xff
       #key = cv2.waitKey(1)

if __name__ == '__main__':
    main()
    
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?