调用 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

在这里插入图片描述

GitHub 加速计划 / opencv31 / opencv
166
15
下载
OpenCV: 开源计算机视觉库
最近提交(Master分支:4 个月前 )
4a4031dc VideoCapture open camera slow 1 天前
c623a5af Android camera refactoring #26646 This patch set does not contain any functional changes. It just cleans up the code structure to improve readability and to prepare for future changes. * videoio(Android): Use 'unique_ptr' instead of 'shared_ptr' Using shared pointers for unshared data is considered an antipattern. * videoio(Android): Make callback functions private static members Don't leak internal functions into global namespace. Some member variables are now private as well. * videoio(Android): Move resolution matching into separate function Also make internally used member functions private. * videoio(Android): Move ranges query into separate function Also remove some unneccessary initialisations from initCapture(). * videoio(Android): Wrap extremly long source code lines * videoio(Android): Rename members of 'RangeValue' ### Pull Request Readiness Checklist See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [x] I agree to contribute to the project under Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [ ] The PR is proposed to the proper branch - [ ] There is a reference to the original bug report and related work - [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [ ] The feature is well documented and sample code can be built with the project CMake 1 天前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐