我在Ubuntu 13.04上使用OpenCV 2.4.6(在Acer C7 Chromebook上),我正在使用一个简单的测试程序来查看我的网络摄像头是否适用于OpenCV.它适用于Cheese和Skype,所以我知道网络摄像头本身不是问题.
这是我的代码(编译时没有任何错误):
#include "opencv2/opencv.hpp"
#include <stdio.h>
#include <stdlib.h>
using namespace std;
using namespace cv;
int main(int argc, char *argv[])
{
cv::VideoCapture cap;
if(argc > 1)
{
cap.open(string(argv[1]));
}
else
{
cap.open(CV_CAP_ANY);
}
if(!cap.isOpened())
{
printf("Error: could not load a camera or video.\n");
}
Mat frame;
namedWindow("video", 1);
for(;;)
{
waitKey(20);
cap >> frame;
if(!frame.data)
{
printf("Error: no frame data.\n");
break;
}
imshow("video", frame);
}
}
Run Code Online (Sandbox Code Playgroud)
如果我在没有任何参数的情况下运行程序(因为我希望它使用CV_CAP_ANY),我得到了
Error: could not load a camera or video.
init done …Run Code Online (Sandbox Code Playgroud)