我正在做一个非常简单的程序,可以在飞行期间在我的计算机上打印 AR.Drone 视频。
它在几秒钟内运行良好,然后程序随机中止,因为框架是空的。我决定测试它,但是现在,当一个框架为空时,以下所有框架也都是空的。
这是我的简单代码:
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;
}
我的输出是:
>OK
>OK
>[...]
>OK
>ERR
>ERR
>ERR
但它应该是:
>OK
>OK
>[...]
>OK
>ERR // okay you got an error ? ...
>OK // ... I give you a new frame :)
>OK
为什么会永远失败?
如果我不保护它,我会收到错误“OpenCV Error: Bad flag”并且它中止。AR.Drone 上的连接是 TCP,所以我无法减慢 waitKey...
任何想法?