Skip to content

Instantly share code, notes, and snippets.

@f41ardu
Last active January 28, 2020 20:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save f41ardu/2f88bc199d4d26c58d68f04058a50b5e to your computer and use it in GitHub Desktop.
Save f41ardu/2f88bc199d4d26c58d68f04058a50b5e to your computer and use it in GitHub Desktop.
Tello Camera in c++
//Uncomment the following line if you are compiling this code in Visual Studio
//#include "stdafx.h"
#include <opencv2/opencv.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main(int argc, char* argv[])
{
//Open tello udp port
VideoCapture cap("udp://@0.0.0.0:11111");
// if not success, exit program
if (cap.isOpened() == false)
{
cout << "Cannot open udp port for Tello" << endl;
cin.get(); //wait for any key press
return -1;
}
double dWidth = cap.get(CAP_PROP_FRAME_WIDTH); //get the width of frames of the video
double dHeight = cap.get(CAP_PROP_FRAME_HEIGHT); //get the height of frames of the video
cout << "Resolution of the video : " << dWidth << " x " << dHeight << endl;
string window_name = "Tello Camera feed";
namedWindow(window_name); //create a window called "Tello Camera feed"
while (true)
{
Mat frame;
bool bSuccess = cap.read(frame); // read a new frame from video
//Breaking the while loop if the frames cannot be captured
if (bSuccess == false)
{
cout << "Video camera is disconnected" << endl;
cin.get(); //Wait for any key press
break;
}
//show the frame in the created window
imshow(window_name, frame);
//wait for for 10 ms until any key is pressed.
//If the 'Esc' key is pressed, break the while loop.
//If the any other key is pressed, continue the loop
//If any key is not pressed withing 10 ms, continue the loop
if (waitKey(10) == 27)
{
cout << "Esc key is pressed by user. Stoppig the video" << endl;
break;
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment