![](/img/trans.png)
[英]How to get a list video capture devices NAMES (web cameras) on linux ( ubuntu )? (C/C++)
[英]How to get a list video capture devices NAMES (web cameras) using Qt (crossplatform)? (C++)
所以我需要的只是簡單 - 當前可用的視頻捕獲設備(網絡攝像頭)列表。 我需要在簡單的C ++ Qt控制台應用程序中。 按列表我的意思是像這樣的控制台輸出:
1) Asus Web Camera
2) Sony Web Camera
所以我的問題是如何使用Qt C ++來表達這樣的列表? (如果可能的話,我很想知道如何在純Qt中做到這一點 - 沒有額外的庫...)
也來自這個系列:
我使用此示例代碼列出相機並獲取有關它們的一些信息。
#include <QtMultimedia/QCameraInfo>
QList<QCameraInfo> cameras = QCameraInfo::availableCameras();
foreach (const QCameraInfo &cameraInfo, cameras) {
qDebug() << "Name: " << cameraInfo.deviceName();
qDebug() << "Position: " << cameraInfo.position();
qDebug() << "Orientation: " << cameraInfo.orientation();
}
記得包含在pro文件中:
QT += multimedia
我寫了下面的代碼來列出所有USB捕獲設備。 請記住包含webcam.h和libwebcam.h,並使用-lwebcam將您的代碼鏈接到libwecam。
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;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.