djitellopy와 opencv를 통한 비디오 스트림 예제

 

drone.streamon()

while True:
    img = drone.get_frame_read().frame()
    # 이미지 절대적 크기 지정
    img = cv2.resize(img,(360,240))
    # imshow("name", 변수)
    cv2.imshow("Image",img)
    # delay, 단위: millisecond
    cv2.waitKey(1)

 

resize

python: cv.resize( src, dsize[, dst[, fx[, fy[, interpolation]]]] ) -> dst
- src: input image, 원본 이미지
- dts: output image, src와 동일한 유형
- dsize: output image size(결과 이미지의 크기를 나타내는 튜플 (width, height)), 𝚍𝚜𝚒𝚣𝚎 = 𝚂𝚒𝚣𝚎(𝚛𝚘𝚞𝚗𝚍(𝚏𝚡*𝚜𝚛𝚌.𝚌𝚘𝚕𝚜), 𝚛𝚘𝚞𝚗𝚍(𝚏𝚢*𝚜𝚛𝚌.𝚛𝚘𝚠𝚜))
- fx, fy: 가로, 세로 방향으로 크기를 조정할 비율로 default = 0
- interpolation: 이미지 크기 조정 시에 사용할 보간법을 나타내는 매개변수로 상수를 통해 지정 가능.

The function resize resizes the image src down to or up to the specified size.
If you want to resize src so that it fits the pre-created dst, you may call the function.

docs.opencv.org

imshow

python: cv.imshow(winname, mat) ->None

The function imshow displays an image in the specified window. If the window was created with the 
cv::WINDOW_AUTOSIZE flag, the image is shown with its original size, however it is still limited by the screen resolution.

This function should be followed by a call to cv::waitKey or cv::pollKey to perform GUI housekeeping tasks that are necessary to actually show the given image and make the window respond to mouse and keyboard events.

docs.opencv.org

waitkey

The function waitKey waits for a key event infinitely (when 𝚍𝚎𝚕𝚊𝚢≤0) or for delay milliseconds, when it is positive.
The functions waitKey and pollKey are the only methods in HighGUI that can fetch and handle GUI events, so one of them needs to be called periodically for normal event processing unless HighGUI is used within an environment that takes care of event processing.

docs.opencv.org

OpenCV VideoCapture

 

capture=cv2.VideoCapture(0)
capture.set()

while True:
    ret, frame = capture.read()
    
    ...

OpenCV에서는 VideoCapture의 API 기본 설정으로 비디오 캡처를 위해  파일 또는 IP 비디오 스트림을 열 수 있다.

 

VideoCapture

cv2.VideoCapture(index, apiPreference=None)

index: id of the video capturing device to open. 시스템 기본 카메라를 열기 위해서 index=0으로 세팅한다. tello를 연결하면 장치 관리자에 등록되어 있는 카메라 순서대로 indexing이 되어있다.
apiPreference: preferred Capture API backends to use. 선호하는 특정 API 방식이 없다면 None으로 세팅한다.

docs.opencv.org

 

VideoCapture를 통해 카메라를 성공적으로 open했으면 read() 메소드를 통해 동영상에서 프레임을 받아올 수 있다.

 

read

python: cv.VideoCapture.read([, image]) -> retval, image
- retval: True or False
- image: 


This is the most convenient method for reading video files or capturing data from decode and returns the just grabbed frame. 

docs.opencv.org

 

sebinChu