【发布时间】:2015-12-12 19:30:06
【问题描述】:
我正在使用CV::VideoCapture 从 IP 摄像机捕获帧。它大部分时间都可以工作,但是有时它会报告错误:
[mjpeg @ 0x233aea0] overread 8
当这个错误发生时,我的程序就卡在那里了。 This 可能会解释原因。但是如何在 C++ 代码中解决它? OpenCV 可以在不终止程序的情况下处理这个错误吗?
附言我发现如果我没有立即调用CV::VideoCapture::read(),而是等待一段时间,比如60秒,在CV::VideoCapture::open()之后,每次都会出现这个错误!是OpenCV的bug吗?
#include <unistd.h>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
int main(int argc, char* argv[]) {
// argv[1] is a valid url, like "http://xxxx/mjpg/video.mjpg"
cv::VideoCapture cap(argv[1]);
if (!cap.isOpened()) {
std::cout << "Cannot Open Camera!" << std::endl;
return -1;
}
// The error occures if I pause for a while.
// But it is okay when I capture frames from video files intead of IP camera.
sleep(60);
while (static_cast<char>(cv::waitKey(1)) != 'q') {
cv::Mat frame;
cap >> frame;
if (frame.empty()) break;
cv::imshow("frame", frame);
}
}
【问题讨论】:
-
检查this是否对您有帮助...
-
But it is okay when I capture frames from video files intead of IP camera.因为,情况不同,如果您尝试使用网络摄像头,很可能也可以:) 这些问题主要发生在 IP 摄像头上。 -
对不起,我不擅长 http 或 rtsp。我尝试了“xxxx/mjpg/video.mjpg/ch1-s1?tcp”,但出现了另一个错误,提示“GStreamer 插件:嵌入式视频播放停止;模块源报告:未找到”。
-
是不是因为我的opencv不是用ffmpeg支持构建的?还是我没有使用正确的 IP 摄像机地址?