解决OpenCV的GStreamer warning警告

调用 cv::VideoCapture出现的警告:

[ WARN:0] global ../modules/videoio/src/cap_gstreamer.cpp (1758) handleMessage OpenCV | GStreamer warning: Embedded video playback halted; module v4l2src0 reported: Internal data stream error.
[ WARN:0] global ../modules/videoio/src/cap_gstreamer.cpp (888) open OpenCV | GStreamer warning: unable to start pipeline
[ WARN:0] global ../modules/videoio/src/cap_gstreamer.cpp (480) isPipelinePlaying OpenCV | GStreamer warning: GStreamer: pipeline have not been created
[ WARN:0] global ../modules/videoio/src/cap_gstreamer.cpp (1758) handleMessage OpenCV | GStreamer warning: Embedded video playback halted; module v4l2src1 reported: Internal data stream error.
[ WARN:0] global ../modules/videoio/src/cap_gstreamer.cpp (888) open OpenCV | GStreamer warning: unable to start pipeline
[ WARN:0] global ../modules/videoio/src/cap_gstreamer.cpp (480) isPipelinePlaying OpenCV | GStreamer warning: GStreamer: pipeline have not been created

原代码 :

cv::VideoCapture cap(0);
if (!cap.isOpened())
{
    cout << "摄像头打开失败!" << endl;
    return -1;
}
else
{
    cap.open(0);  //0-笔记本自带摄像头,1-外接usb双目摄像头
    cap.set(cv::CAP_PROP_FRAME_WIDTH, FRAME_WIDTH);  //设置捕获视频的宽度
    cap.set(cv::CAP_PROP_FRAME_HEIGHT, FRAME_HEIGHT);  //设置捕获视频的高度
    cap.set(cv::CAP_PROP_FPS, 60);
}

修改代码:

//增加cv::CAP_V4L2,即可解决
cv::VideoCapture cap(0, cv::CAP_V4L2);
if (!cap.isOpened())
{
    cout << "摄像头打开失败!" << endl;
    return -1;
}
else
{
	//增加cv::CAP_V4L2,即可解决
    cap.open(0, cv::CAP_V4L2);  //0-笔记本自带摄像头,1-外接usb双目摄像头
    cap.set(cv::CAP_PROP_FRAME_WIDTH, FRAME_WIDTH);  //设置捕获视频的宽度
    cap.set(cv::CAP_PROP_FRAME_HEIGHT, FRAME_HEIGHT);  //设置捕获视频的高度
    cap.set(cv::CAP_PROP_FPS, 60);
}

PS:记录一下这条命令,可以看摄像头的一些参数

v4l2-ctl --info -d /dev/video0 --list-formats-ext

解决OpenCV的GStreamer warning警告_第1张图片

你可能感兴趣的:(笔记,opencv)