简体   繁体   English

Video AR Drone的随机帧为空,然后无法使用OpenCV获得新图像

[英]Random frame of Video AR Drone is empty and then can't get a new image with OpenCV

I'm doing a very simple program that print the AR.Drone video during the flight on my computer. 我正在做一个非常简单的程序,可以在飞行中在计算机上打印AR.Drone视频。

It works well during a few seconds and then, randomly, the program abort because the frame is empty. 它在几秒钟内运行良好,然后由于框架为空,因此随机中止了程序。 I decided to test it, but now, when a frame is empty, all the following frames are empty too. 我决定对其进行测试,但是现在,当一个框架为空时,以下所有框架也都为空。

Here is my simple code : 这是我的简单代码:

int main(void)
{
  cv::VideoCapture cap;
  cv::Mat image;

  if (!cap.open("tcp://192.168.1.1:5555"))
    {
      printf("AR.Drone ERROR CONNECT\n");
      return -1;
    }

  takeoff();

  while (42)
    {
      cap >> image;

      if (!image.empty())
        {
           cv::imshow("AR.Drone", image);
           std::cout << "OK" << std::endl;
        }
      else
        std::cout << "ERROR" << std::endl;
      cv::waitKey(1);
    }    
  return 0;
}

My output is : 我的输出是:

>OK
>OK
>[...]
>OK
>ERR
>ERR
>ERR

But it should be : 但是应该是:

>OK
>OK
>[...]
>OK
>ERR   // okay you got an error ? ...
>OK    // ... I give you a new frame :)
>OK

Why does it fail forever? 为什么它会永远失败?

If I don't protect it I get the error “OpenCV Error: Bad flag” and it abort. 如果我不保护它,则会收到错误“ OpenCV错误:错误标志”,并且它会中止。 The connection on the AR.Drone is TCP, so I can't slow down the waitKey... AR.Drone上的连接是TCP,所以我不能放慢waitKey ...

Any Idea? 任何想法?

I got the same issue when I wanted to get stable video stream with AR.Drone 2.0 It took some time, but I realized the frame missing is because the drone consider the connection as lost after 2 seconds without AT command. 当我想使用AR.Drone 2.0获得稳定的视频流时,我遇到了同样的问题,但是花了一些时间,但我意识到丢失帧是因为无人机认为在没有AT命令的情况下2秒钟后连接丢失了。 So if you open the stream and do nothing more it is fine (the stream will be good), but after you send any AT command then after 2 second the drone will disconnect. 因此,如果您打开流并且不执行任何操作就可以了(流会很好),但是在发送任何AT命令后,2秒钟后无人机将断开连接。 So all you need to do to send for example hovering command to the drone if no other command sent to keep the connection alive. 因此,如果未发送其他命令来保持连接有效,则您需要做的所有操作(例如,将悬停命令发送至无人机)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM