我正努力在OpenCV连接我的网络摄像头 . 我的笔记本电脑's webcam in Windows 7 64-bit works properly. But if I connect another webcam, the code doesn' t全部工作:
capWebcam = cvCaptureFromCAM(0);
if(capWebcam == NULL) {
printf("error: capture is NULL \n");
getchar();
return(-1);
}
由于没有任何网络摄像头,它会返回消息错误 . 我禁用笔记本电脑摄像头,它工作,但我得到黑屏 .
我尝试了两个网络摄像头,即微软的Logitech HD Pro C920和LifeCam Cinema . 这是负责获取凸轮的线:
CvCapture* mycapWebcam = cvCaptureFromCAM(0);
我将0更改为另一个值(0-10),这是有关此结构的信息:
CvCapture * cvCaptureFromCAM(int index)初始化从摄像机捕获视频 . 参数:index - 要使用的摄像机的索引 . 如果只有一台摄像机或使用什么摄像机无关紧要,可以通过-1 . 函数cvCaptureFromCAM()分配并初始化CvCapture结构,以便从摄像机读取视频流 . 目前,Windows上可以使用两个摄像头接口:Windows视频(VFW)和Matrox成像库(MIL); Linux上有两个:V4L和FireWire(IEEE1394) . 要释放结构,请使用ReleaseCapture .
我该如何解决这个问题?
2 回答
尝试使用不同的API - 请查看my answer to Stack Overflow question OpenCV on Mac is not opening USB web camera .
第一帧经常是黑色的(我不知道为什么) . 试着等一段时间再换一帧 .
如果您使用的是其他相机,则应将1设为索引: