如何获得列表视频捕获设备NAMES(网络摄像头)使用Qt(交叉平台)? (C ++) [英] How to get a list video capture devices NAMES (web cameras) using Qt (crossplatform)? (C++)

查看:510
本文介绍了如何获得列表视频捕获设备NAMES(网络摄像头)使用Qt(交叉平台)? (C ++)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所有我需要的是简单的 - 当前可用的视频捕获设备(网络摄像头)的列表。我需要它在简单的C + + Qt控制台应用程序。按名单我的意思是这样的控制台输出:

So all I need is simple - a list of currently avaliable video capture devices (web cameras). I need it in simple C++ Qt console app. By list I mean something like such console output:

1) Asus Web Camera
2) Sony Web Camera



(如果可能,我很想看看如何做纯净的Qt - 没有额外的库...)

So my question is how to cout such list using Qt C++? (if it is possible I'd love to see how to do it in pure Qt - no extra libs...)

也来自此系列:

  • How to get a list of video capture devices on linux? and special details on getting cameras NAMES with correct, tested answers
  • How to get a list of video capture devices on Mac OS? with correct, not yet tested by my answers
  • How to get a list of video capture devices on windows? with correct, tested answers
  • How to get a list video capture devices NAMES using Qt (crossplatform)?

推荐答案

我写了以下代码来列出所有的USB捕获设备。记住要包括webcam.h和libwebcam.h,并使用-lwebcam将你的代码链接到libwecam。

I've wrote the following code to list all the USB capture devices. Remember to include webcam.h and libwebcam.h and link your code to libwecam using -lwebcam.

bool QextCamera::listAvailableDevices(QStringList * captureDeviceList){
    CResult ret;
    CDevice *devices = NULL;

    quint32 req_size = 0;
    quint32 buffer_size = 0;
    quint32 count = 0;
    QStringList availableDevices;

    c_init();

    do {
        if (devices){
        free(devices);
    }

    if(req_size){
        devices = (CDevice *)malloc(req_size);

        if(devices == NULL){
                // LOG ERROR...
        return false;
        }

        buffer_size = req_size;
   }

   // Try to enumerate. If the buffer is not large enough, the required size is returned.
   ret = c_enum_devices(devices, &req_size, &count);

   if(ret != C_SUCCESS && ret != C_BUFFER_TOO_SMALL){
       // LOG ERROR...
       return false;
   }

    } while(buffer_size < req_size);

    if(count == 0) {
        // LOG ERROR...
    return false;
    }

    for(quint32 i = 0; i < count; i++) {
        CDevice *device = &devices[i];
    availableDevices << QString("%1 : %2 : %3").arg(device->shortName).arg(device->driver).arg(device->location);
    }

    if(devices){
        free(devices);
    }

    c_cleanup();

    *captureDeviceList = availableDevices;

    return true;
}

这篇关于如何获得列表视频捕获设备NAMES(网络摄像头)使用Qt(交叉平台)? (C ++)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆