有时候在项目中我们需要检测当前连接在机子上的摄像头的数量,可以通过下面的代码实现,其中连接摄像头的最大数量maxCamNum可以任意修改:

 

/**
 * Count current camera number
 */
int countCamera() {
    int maxCamNum = 5;
    int count = 0;
    for(int device = 0; device < maxCamNum; device++) 
    {
        CvCapture* capture;
        if (_capture[device]) {
            ++count;
        }
        else {
            capture = cvCaptureFromCAM(CV_CAP_DSHOW + device);
            if (capture) {
                ++count;
            }
            cvReleaseCapture(&capture);
        }
    }
    return count;
}

 

OpenCV中没有能返回摄像头设备名称的函数,有些时候也不太方便,但是没有办法,将就的用着吧~~

 

相关文章:

  • 2022-12-23
  • 2021-06-15
  • 2021-12-18
  • 2021-10-18
  • 2021-08-30
  • 2022-12-23
  • 2022-12-23
  • 2021-10-01
猜你喜欢
  • 2021-07-06
  • 2022-12-23
  • 2021-06-27
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案