Commit 4c296197 authored by Thiago Santini's avatar Thiago Santini

Parametrization

parent fce1f275
#include "uvccamerasession.h"
#include <QThread>
#include <QtConcurrent/QtConcurrent>
#include <QDebug>
#include <QCoreApplication>
#include <QDir>
#include <QSettings>
QMutex UVCCameraSession::sessionMutex;
QMap<QString,bool> UVCCameraSession::devices;
......@@ -123,6 +127,17 @@ void UVCCameraSession::presentFrame(QVideoFrame frame, const qreal t)
// qWarning() << "Dropping frame (" << latency << "ms old )";
}
template<typename T> bool set(const QSettings *settings, const QString key, T &v)
{
if (!settings)
return false;
QVariant variant = settings->value(key);
if (variant.isValid()) {
v = qvariant_cast<T>(variant);
return true;
}
return false;
}
bool UVCCameraSession::load()
{
QMutexLocker sessionLocker(&sessionMutex);
......@@ -136,21 +151,128 @@ bool UVCCameraSession::load()
qWarning() << "uvc_open" << uvc_strerror(res);
devh = NULL;
return false;
}
}
// TODO: parametrize this
uvc_set_focus_auto(devh, 0);
if (isPupilFieldCamera()) {
bandwidthFactor = 2.0f;
uvc_set_ae_priority(devh, 1);
} else if (isPupilEyeCamera()) {
uvc_set_ae_priority(devh, 0);
uvc_set_ae_mode(devh, 1);
uvc_set_saturation(devh, 127); // do not set saturation to zero as to not lose color information
uvc_set_exposure_abs(devh, 63);
uvc_set_backlight_compensation(devh, 2);
uvc_set_gamma(devh, 100);
}
/*
// TODO: parametrize this
uvc_set_focus_auto(devh, 0);
if (isPupilFieldCamera()) {
bandwidthFactor = 2.0f;
uvc_set_ae_priority(devh, 1);
} else if (isPupilEyeCamera()) {
uvc_set_ae_priority(devh, 0);
uvc_set_ae_mode(devh, 1);
uvc_set_saturation(devh, 127); // do not set saturation to zero as to not lose color information
uvc_set_exposure_abs(devh, 63);
uvc_set_backlight_compensation(devh, 2);
uvc_set_gamma(devh, 100);
}
*/
uint8_t focus_auto;
uint8_t ae_priority;
uint8_t ae_mode;
uint8_t contrast_auto;
uint16_t saturation;
uint16_t backlight_compensation;
uint16_t gamma;
uint16_t contrast;
uint16_t gain;
int16_t brightness;
uint32_t exposure_abs;
QSettings *settings;
QFileInfo uvcSettingsFile( QString("%1/cfg/uvc/%2.ini").arg(QCoreApplication::applicationDirPath()).arg(deviceName) );
bool hasSettings = uvcSettingsFile.exists();
settings = new QSettings(uvcSettingsFile.absoluteFilePath(), QSettings::IniFormat);
// If we didn't have settings, create with default values; otherwise read and set
if ( !hasSettings ) {
qDebug() << uvcSettingsFile.absoluteFilePath() << "not found. Generating...";
QDir dir;
dir.mkpath( uvcSettingsFile.absolutePath() );
settings->setValue("bandwidthFactor", bandwidthFactor);
uvc_get_focus_auto(devh, &focus_auto, UVC_GET_CUR);
settings->setValue("focus_auto", focus_auto);
uvc_get_ae_priority(devh, &ae_priority, UVC_GET_CUR);
settings->setValue("ae_priority", ae_priority);
uvc_get_ae_mode(devh, &ae_mode, UVC_GET_CUR);
settings->setValue("ae_mode", ae_mode);
uvc_get_contrast_auto(devh, &contrast_auto, UVC_GET_CUR);
settings->setValue("contrast_auto", contrast_auto);
uvc_get_saturation(devh, &saturation, UVC_GET_CUR);
settings->setValue("saturation", saturation);
uvc_get_exposure_abs(devh, &exposure_abs, UVC_GET_CUR);
settings->setValue("exposure_abs", exposure_abs);
uvc_get_backlight_compensation(devh, &backlight_compensation, UVC_GET_CUR);
settings->setValue("backlight_compensation", backlight_compensation);
uvc_get_gamma(devh, &gamma, UVC_GET_CUR);
settings->setValue("gamma", gamma);
uvc_get_brightness(devh, &brightness, UVC_GET_CUR);
settings->setValue("brightness", brightness);
uvc_get_gain(devh, &gain, UVC_GET_CUR);
settings->setValue("gain", gain);
uvc_get_contrast(devh, &contrast, UVC_GET_CUR);
settings->setValue("contrast", contrast);
} else {
bandwidthFactor = settings->value("bandwidthFactor").toFloat();
if (set(settings, "focus_auto", focus_auto ) )
uvc_set_focus_auto(devh, 0);
if (set(settings, "ae_priority", ae_priority ) )
uvc_set_ae_priority(devh, ae_priority);
if (set(settings, "ae_mode", ae_mode ) )
uvc_set_ae_mode(devh, ae_mode);
if (set(settings, "contrast_auto", contrast_auto ) )
uvc_set_contrast_auto(devh, contrast_auto);
if (set(settings, "saturation", saturation ) )
uvc_set_saturation(devh, saturation);
if (set(settings, "exposure_abs", exposure_abs ) )
uvc_set_exposure_abs(devh, exposure_abs);
if (set(settings, "backlight_compensation", backlight_compensation ) )
uvc_set_backlight_compensation(devh, backlight_compensation);
if (set(settings, "gamma", gamma ) )
uvc_set_gamma(devh, gamma);
if (set(settings, "brightness", brightness ) )
uvc_set_brightness(devh, brightness);
if (set(settings, "gain", gain ) )
uvc_set_contrast(devh, gain);
// Why must contrast be last???
if (set(settings, "contrast", contrast ) )
uvc_set_contrast(devh, contrast);
}
settings->deleteLater();
updateSourceCapabilities();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment