从摄像机捕捉视频
Capturing video from a camera
我用的是OSX Mavericks和Macbook Air 2013。
#include <iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/video/tracking.hpp>
int main()
{
cv::VideoCapture cap;
cap.open(0);
if( !cap.isOpened() )
{
std::cerr << "***Could not initialize capturing...***n";
return -1;
}
cv::Mat frame;
while(1){
cap >> frame;
if(frame.empty()){
std::cerr<<"frame is empty"<<std::endl;
break;
}
cv::imshow("", frame);
cv::waitKey(10);
}
return 1;
}
相机初始化正确(isopen返回true),但是它一直返回空帧。但是,从文件中检索帧而不是从相机中检索帧效果很好。
此外,使用C API的cvQueryFrame似乎工作得很好!
关于如何调试我的问题有什么想法吗?
Edit:下面的代码似乎可以让相机正常工作。有人知道为什么吗?
#include <iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/video/tracking.hpp>
using namespace cv;
using namespace std;
int main()
{
VideoCapture cap;
cap.open(0);
namedWindow("Window");
if( !cap.isOpened() )
{
std::cerr << "***Could not initialize capturing...***n";
return -1;
}
cv::Mat frame;
while(1){
cap >> frame;
if(!(frame.empty())){
imshow("Window", frame);
}
waitKey(10);
}
return 1;
}
这是我在笔记本电脑上使用OpenCv时遇到的同样的问题。
只需在while
环前添加cvWaitKey(6700);
。
#include <iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/video/tracking.hpp>
using namespace cv;
using namespace std;
int main()
{
VideoCapture cap;
cap.open(0);
namedWindow("Window");
if( !cap.isOpened() )
{
std::cerr << "***Could not initialize capturing...***n";
return -1;
}
cv::Mat frame;
waitKey(6700);
while(1){
cap >> frame;
if(!(frame.empty())){
imshow("Window", frame);
}
waitKey(25);
}
return 1;
}
Try
while(cap.grab()){
cap.retrieve(frame);
waitKey(25);
}
它不会给你空的框架
相关文章:
- 如何在c++中录制具有精确帧时间戳的视频
- 如何在QT中的自定义视频小工具t上绘制矩形
- 如何使用OpenCV-C++编写*.mp4视频?
- 开放 CV 中的动态内存分配,用于视频处理
- 错误:(-210:不支持的格式或格式组合)功能'create'中的硬件视频解码器不支持视频源
- 将摄像机调整到俯视图
- 使用mynteye立体声摄像机在ROS中发布左右视频
- Opencv 从多个摄像机捕获视频
- OpenCV噪声消除静态摄像机的视频
- 当我使用RTSP摄像机流时,OpenCV视频贴中滞后
- OPENCV是否可以使用视频捕获设备访问模拟摄像机
- 使用OpenCv和多线程的IP摄像机实时视频馈送
- 物体相对于摄像机和视频的角度?视频和相机输出不同
- 使用 Live555 从连接到 H264 编码器的 IP 摄像机流式传输实时视频
- 使用 OpenCV 从摄像机捕获视频时"Unable to Locate DLL"
- C++/OpenCV流媒体摄像机视频/图像(MJPEG)从套接字进入浏览器(Windows 8.1)
- 来自IP摄像机的MJPEG视频太快
- 从摄像机捕捉视频
- 3摄像机捕获与视频输入或其他任何东西
- 如何将PTAM的视频源更改为IP摄像机?