问题描述
我使用 OpenCV 的 VideoCapture.open(int) 获取视频捕获失败来自我的 MacBook Pro 中的 USB 网络摄像头,运行 MacOS X v10.7 (Lion).使用 open(0) 成功从 iSight 摄像头获取捕获.但我没有找到网络摄像头.
I have been unsuccessful using OpenCV's VideoCapture.open(int) to get video capture from a USB web cam in my MacBook Pro running Mac OS X v10.7 (Lion). Using open(0) successfully gets capture from the iSight camera. But I didn't have any luck trying to find the WebCam.
网络摄像头已安装并与 Skype 和 macam 驱动程序.
The WebCam is installed and works well with Skype, and the macam driver application.
这是我正在使用的部分代码:
Here is a portion of the code that I'm using:
VideoCapture cap;
for (int i = 1; i < 1500; i++) {
if (cap.open(i))
{
cout << "Found camera %d
" << i;
break;
}
}
if(!cap.isOpened()) { // Check if we succeeded
return -1;
}
如果我用 0 初始化 i
,它会立即找到 iSight 摄像头.如果我用 1 初始化 i
,那么当 i
= 500 时它会再次找到 iSight.
If I initialize i
with 0 it immediately finds the iSight camera. If I initialize i
with 1, then it finds iSight again when i
= 500.
我该如何解决这个问题?
How can I fix this problem?
推荐答案
尝试在没有以下行的情况下运行您的代码:break;
.可能您会发现不止一台相机,其中一台是网络摄像头.
请注意,cap.open
的参数不仅是相机的数量 - 它还定义了您要使用的 API:
Try to run your code without this line: break;
. Probably you will find more than just one camera, and one of them will WebCam.
Note that parameter of cap.open
is not only the number of camera - it also defines which API you want to use:
摄像头调度方式:index
为摄像头编号.
Camera dispatching method: index
is the camera number.
- 如果给定一个从 0 到 99 的索引,它会尝试找到第一个
- 可以访问给定相机索引的 API.
- 添加 100 的倍数以选择 API(来自 cap.cpp 的评论)
可能性(取自 highgui_c.h):
Possibilities (taken from highgui_c.h):
CV_CAP_ANY =0, // autodetect
CV_CAP_MIL =100, // MIL proprietary drivers
CV_CAP_VFW =200, // platform native
CV_CAP_V4L =200,
CV_CAP_V4L2 =200,
CV_CAP_FIREWARE =300, // IEEE 1394 drivers
CV_CAP_FIREWIRE =300,
CV_CAP_IEEE1394 =300,
CV_CAP_DC1394 =300,
CV_CAP_CMU1394 =300,
CV_CAP_STEREO =400, // TYZX proprietary drivers
CV_CAP_TYZX =400,
CV_TYZX_LEFT =400,
CV_TYZX_RIGHT =401,
CV_TYZX_COLOR =402,
CV_TYZX_Z =403,
CV_CAP_QT =500, // QuickTime
CV_CAP_UNICAP =600, // Unicap drivers
CV_CAP_DSHOW =700, // DirectShow (via videoInput)
CV_CAP_PVAPI =800, // PvAPI, Prosilica GigE SDK
CV_CAP_OPENNI =900, // OpenNI (for Kinect)
CV_CAP_OPENNI_ASUS =910, // OpenNI (for Asus Xtion)
CV_CAP_ANDROID =1000, // Android
CV_CAP_XIAPI =1100, // XIMEA Camera API
CV_CAP_AVFOUNDATION = 1200 // AVFoundation framework for iOS (OS X Lion will have the same API)
可能 CV_CAP_AVFOUNDATION = 1200
是你正在寻找的 - 尝试从 1200 开始循环,不要忘记删除 break;
我认为你会找到您要找的东西.
Probably CV_CAP_AVFOUNDATION = 1200
is what you are looking for - try to start you loop from 1200 and don't forget to remove break;
and I think that you will find what you are looking for.
这篇关于Mac 上的 OpenCV 无法打开 USB 网络摄像头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!