VideoCapture select timeout with OpenCV 3.0.0-rc1
VideoCapture select timeout with OpenCV 3.0.0-rc1
我在VirtualBox和Windows 8 Host的Ubuntu 14.04 LTS Guest上使用OpenCV 3.0.0-rc1。我有一个非常简单的程序可以从网络摄像头(罗技 C170)(来自 OpenCV 文档)读取帧。不幸的是,它不起作用(我尝试了 3 种不同的网络摄像头)。它每隔几秒钟抛出一个错误"选择超时"并读取一个帧,但帧是黑色的。有什么想法吗?
代码如下:
#include <iostream>
#include <opencv2/opencv.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/imgproc.hpp>
using namespace std;
using namespace cv;
// Main
int main(int argc, char **argv) {
/* webcam setup */
VideoCapture stream;
stream.open(0);
// check if video device has been initialized
if (!stream.isOpened()) {
fprintf(stderr, "Could not open Webcam device");
return -1;
}
int image_width = 640; // image resolution
int image_height = 480;
Mat colorImage,currentImage;
bool loop = true;
/* infinite loop for video stream */
while (loop) {
loop = stream.read(colorImage); // read webcam stream
cvtColor(colorImage, currentImage, CV_BGR2GRAY); // color to gray for current image
imshow("Matches", currentImage);
if(waitKey(30) >= 0) break;
// end stream while-loop
}
return 0;
}
我发现了问题:使用网络摄像头时,请确保使用Devices->Webcams
而不是Devices->USB
将其连接到虚拟机。即使网络摄像头在通过Devices->USB
连接时被检测为video0
,由于某些原因它不起作用。
相关文章:
- C++,OpenCV,尝试显示图像时"OpenCV(4.3.0) Error: Assertion failed (size.width>0 && size.height>0)"此错误
- 尝试导入pybind-opencv模块时出现libgtk错误
- 在编译C++代码(具有dlib和opencv)到WASM时面临问题
- 如何使用OpenCV将RBG图像转换为HSV,并将H、S和V值保存为C++中的3个独立图像
- OpenCV EqualizeHist()从彩色图像创建黑白图像
- 将OpenCV C++重写为EmguCV C#-如何使用指针
- OpenCV C++.快速计算混淆矩阵
- 在C++代码中包含opencv时,使用ctypes创建.so文件
- 哪些库可以通过Opencv调整曝光率
- 安装opencv失败-粘贴CMakeError.log的内容
- C++中的openCV Mat访问冲突
- OpenCV Android C++ imwrite not found
- 未定义的引用 .. 使用 OpenCV 编译 C++ 代码时,从命令行
- 将 OpenCV 与 CMAKE 中的项目一起构建为第三方库的正确方法
- CV_OCL_RUN宏如何在OpenCV(版本3.4.5)的goodFeaturesToTrack实现中工作?
- OpenCV 4.1.2 - 从网络摄像头获取帧并将其拆分
- C++ OpenCV 卡尔曼滤波器构造函数错误
- (OPENCV RC1)什么导致MAT乘法比每像素乘法慢20倍
- VideoCapture select timeout with OpenCV 3.0.0-rc1
- 编译private.hpp OpenCV 3.0.0-rc1时出错