From 78bde487da1a9938614e3ddba2959abeb5142d93 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sat, 26 Jan 2013 14:52:44 +0000 Subject: Add camera human-readable names to HT tracker. c14 please do the same PT is your turf :P git-svn-id: svn+ssh://svn.code.sf.net/p/facetracknoir/code@232 19e81ba0-9b1a-49c3-bd6c-561e1906d5fb --- FTNoIR_Tracker_HT/FTNoIR_Tracker_HT_vc8.vcproj | 8 ++-- FTNoIR_Tracker_HT/TrackerControls.ui | 51 +++++++++------------ FTNoIR_Tracker_HT/ftnoir_tracker_ht.cpp | 61 ++++++++++++++++++++++++-- FTNoIR_Tracker_HT/stdafx.h | 5 ++- 4 files changed, 87 insertions(+), 38 deletions(-) diff --git a/FTNoIR_Tracker_HT/FTNoIR_Tracker_HT_vc8.vcproj b/FTNoIR_Tracker_HT/FTNoIR_Tracker_HT_vc8.vcproj index 5ad20937..bf9b23c2 100644 --- a/FTNoIR_Tracker_HT/FTNoIR_Tracker_HT_vc8.vcproj +++ b/FTNoIR_Tracker_HT/FTNoIR_Tracker_HT_vc8.vcproj @@ -1,7 +1,7 @@ diff --git a/FTNoIR_Tracker_HT/TrackerControls.ui b/FTNoIR_Tracker_HT/TrackerControls.ui index 561d6118..23ae4cad 100644 --- a/FTNoIR_Tracker_HT/TrackerControls.ui +++ b/FTNoIR_Tracker_HT/TrackerControls.ui @@ -2,11 +2,14 @@ Form + + Qt::NonModal + 0 0 - 333 + 500 127 @@ -18,7 +21,7 @@ - 378 + 500 127 @@ -43,7 +46,7 @@ 130 10 - 91 + 251 22 @@ -78,7 +81,7 @@ 130 40 - 81 + 251 22 @@ -113,35 +116,13 @@ - Camera index - - - - - - 130 - 70 - 42 - 22 - - - - -1 - - - 255 - - - 1 - - - -1 + Camera name - 170 + 340 100 75 23 @@ -154,7 +135,7 @@ - 250 + 420 100 75 23 @@ -167,7 +148,7 @@ - 220 + 390 10 101 81 @@ -255,6 +236,16 @@ + + + + 130 + 70 + 251 + 22 + + + diff --git a/FTNoIR_Tracker_HT/ftnoir_tracker_ht.cpp b/FTNoIR_Tracker_HT/ftnoir_tracker_ht.cpp index cf67c732..ff89c04d 100644 --- a/FTNoIR_Tracker_HT/ftnoir_tracker_ht.cpp +++ b/FTNoIR_Tracker_HT/ftnoir_tracker_ht.cpp @@ -11,6 +11,57 @@ static TCHAR mutexName[] = TEXT(HT_MUTEX_NAME); #define WIDGET_WIDTH 250 #define WIDGET_HEIGHT 170 +// delicious copypasta +static QList get_camera_names(void) { + QList ret; + // Create the System Device Enumerator. + HRESULT hr; + ICreateDevEnum *pSysDevEnum = NULL; + hr = CoCreateInstance(CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER, IID_ICreateDevEnum, (void **)&pSysDevEnum); + if (FAILED(hr)) + { + return ret; + } + // Obtain a class enumerator for the video compressor category. + IEnumMoniker *pEnumCat = NULL; + hr = pSysDevEnum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory, &pEnumCat, 0); + + if (hr == S_OK) { + // Enumerate the monikers. + IMoniker *pMoniker = NULL; + ULONG cFetched; + while (pEnumCat->Next(1, &pMoniker, &cFetched) == S_OK) { + IPropertyBag *pPropBag; + hr = pMoniker->BindToStorage(0, 0, IID_IPropertyBag, (void **)&pPropBag); + if (SUCCEEDED(hr)) { + // To retrieve the filter's friendly name, do the following: + VARIANT varName; + VariantInit(&varName); + hr = pPropBag->Read(L"FriendlyName", &varName, 0); + if (SUCCEEDED(hr)) + { + // Display the name in your UI somehow. + QString str((QChar*)varName.bstrVal, wcslen(varName.bstrVal)); + ret.append(str); + } + VariantClear(&varName); + + ////// To create an instance of the filter, do the following: + ////IBaseFilter *pFilter; + ////hr = pMoniker->BindToObject(NULL, NULL, IID_IBaseFilter, + //// (void**)&pFilter); + // Now add the filter to the graph. + //Remember to release pFilter later. + pPropBag->Release(); + } + pMoniker->Release(); + } + pEnumCat->Release(); + } + pSysDevEnum->Release(); + return ret; +} + static void load_settings(ht_config_t* config, Tracker* tracker) { QSettings settings("Abbequerque Inc.", "FaceTrackNoIR"); @@ -256,7 +307,7 @@ TrackerControls::TrackerControls() { ui.setupUi(this); loadSettings(); - connect(ui.cameraIndex, SIGNAL(valueChanged(int)), this, SLOT(settingChanged(int))); + connect(ui.cameraName, SIGNAL(currentIndexChanged(int)), this, SLOT(settingChanged(int))); connect(ui.cameraFPS, SIGNAL(currentIndexChanged(int)), this, SLOT(settingChanged(int))); connect(ui.cameraFOV, SIGNAL(valueChanged(double)), this, SLOT(settingChanged(double))); connect(ui.rx, SIGNAL(stateChanged(int)), this, SLOT(settingChanged(int))); @@ -285,11 +336,15 @@ void TrackerControls::Initialize(QWidget* parent) void TrackerControls::loadSettings() { + ui.cameraName->clear(); + QList names = get_camera_names(); + names.prepend("Any available"); + ui.cameraName->addItems(names); QSettings settings("Abbequerque Inc.", "FaceTrackNoIR"); QString currentFile = settings.value( "SettingsFile", QCoreApplication::applicationDirPath() + "/Settings/default.ini" ).toString(); QSettings iniFile( currentFile, QSettings::IniFormat ); iniFile.beginGroup( "HT-Tracker" ); - ui.cameraIndex->setValue(iniFile.value("camera-index", -1).toInt()); + ui.cameraName->setCurrentIndex(iniFile.value("camera-index", -1).toInt() + 1); ui.cameraFOV->setValue(iniFile.value("fov", 69).toFloat()); int fps; switch (iniFile.value("fps", 0).toInt()) @@ -345,7 +400,7 @@ void TrackerControls::save() break; } iniFile.setValue("fps", fps); - iniFile.setValue("camera-index", ui.cameraIndex->value()); + iniFile.setValue("camera-index", ui.cameraName->currentIndex() - 1); iniFile.setValue("enable-rx", ui.rx->checkState()); iniFile.setValue("enable-ry", ui.ry->checkState()); iniFile.setValue("enable-rz", ui.rz->checkState()); diff --git a/FTNoIR_Tracker_HT/stdafx.h b/FTNoIR_Tracker_HT/stdafx.h index a0c72843..9cbe1001 100644 --- a/FTNoIR_Tracker_HT/stdafx.h +++ b/FTNoIR_Tracker_HT/stdafx.h @@ -37,4 +37,7 @@ #include #include #include -#include \ No newline at end of file +#include +#include +#include +#include \ No newline at end of file -- cgit v1.2.3