Commit 5e6d0a7c authored by Thiago Santini's avatar Thiago Santini

Adds parametetrization and default values

parent 96f94e6b
......@@ -20,6 +20,72 @@ UVCCameraSession::UVCCameraSession(QObject *parent)
dev(NULL),
devh(NULL)
{
DefaultParameters tmp;
// Pupil Cam1 Eye
tmp.bandwidthFactor = 1.3;
tmp.brightness = 0.5;
tmp.contrast = 0.5;
tmp.saturation = 0;
tmp.white_balance = 0.486486;
tmp.sharpness = 0.333333;
tmp.backlight_compensation = 1.0;
tmp.gamma = 0.0654206;
tmp.gain = 0;
tmp.exposure_abs = 0.0124025;
tmp.hue = 0.5;
tmp.ae_mode = 1;
tmp.ae_priority = 0;
tmp.contrast_auto = 0;
tmp.focus_auto = 0;
tmp.white_balance_component_auto = 0;
tmp.white_balance_temperature_auto = 1;
tmp.hue_auto = 0;
defaults["Pupil Cam1 ID0"] = tmp;
defaults["Pupil Cam1 ID1"] = tmp;
// Pupil Cam1 Field
tmp.bandwidthFactor = 2.0;
tmp.brightness = 0.5;
tmp.contrast = 0.5;
tmp.saturation = 0.46875;
tmp.white_balance = 0.486486;
tmp.sharpness = 0.333333;
tmp.backlight_compensation = 0.5;
tmp.gamma = 0.0654206;
tmp.gain = 0;
tmp.exposure_abs = 0.0312062;
tmp.hue = 0.5;
tmp.ae_mode = 8;
tmp.ae_priority = 1;
tmp.contrast_auto = 0;
tmp.focus_auto = 0;
tmp.white_balance_component_auto = 0;
tmp.white_balance_temperature_auto = 1;
tmp.hue_auto = 0;
defaults["Pupil Cam1 ID2"] = tmp;
// Pupil Cam2 Eye
tmp.bandwidthFactor = 1.3;
tmp.brightness = 0.5;
tmp.contrast = 0.5;
tmp.saturation = 0;
tmp.white_balance = 0.486486;
tmp.sharpness = 0.166667;
tmp.backlight_compensation = 40.3333;
tmp.gamma = 0.5;
tmp.gain = 0;
tmp.exposure_abs = 1;
tmp.hue = 0.5;
tmp.ae_mode = 1;
tmp.ae_priority = 0;
tmp.contrast_auto = 0;
tmp.focus_auto = 0;
tmp.white_balance_component_auto = 0;
tmp.white_balance_temperature_auto = 1;
tmp.hue_auto = 0;
defaults["Pupil Cam2 ID0"] = tmp;
defaults["Pupil Cam2 ID1"] = tmp;
}
UVCCameraSession::~UVCCameraSession()
......@@ -153,129 +219,7 @@ bool UVCCameraSession::load()
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);
}
*/
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);
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;
/*
// 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();
setDefaultParameters();
updateSourceCapabilities();
......@@ -555,16 +499,19 @@ QVariant UVCCameraSession::actualExposureValue(QCameraExposureControl::ExposureP
default:
qWarning() << parameter << "not supported";
return QVariant();
}
}
bool UVCCameraSession::isExposureParameterSupported(QCameraExposureControl::ExposureParameter parameter) const
{
Q_UNUSED(parameter);
return false;
}
QVariant UVCCameraSession::requestedExposureValue(QCameraExposureControl::ExposureParameter parameter) const
{
Q_UNUSED(parameter);
return QVariant();
}
......@@ -576,11 +523,9 @@ bool UVCCameraSession::setExposureValue(QCameraExposureControl::ExposureParamete
switch (mode) {
case QCameraExposure::ExposureManual:
uvc_set_ae_mode(devh, 1);
uvc_set_ae_priority(devh, 0);
break;
case QCameraExposure::ExposureAuto:
uvc_set_ae_mode(devh, 2);
uvc_set_ae_priority(devh, 0);
break;
default:
qWarning() << mode << "not supported";
......@@ -604,5 +549,102 @@ bool UVCCameraSession::setExposureValue(QCameraExposureControl::ExposureParamete
QVariantList UVCCameraSession::supportedExposureParameterRange(QCameraExposureControl::ExposureParameter parameter, bool *continuous) const
{
Q_UNUSED(parameter);
Q_UNUSED(continuous);
return QVariantList();
}
void UVCCameraSession::setDefaultParameters()
{
if (false) {
qDebug() << uvc_get(devh, uvc_get_brightness);
qDebug() << uvc_get(devh, uvc_get_contrast);
qDebug() << uvc_get(devh, uvc_get_saturation);
qDebug() << uvc_get(devh, uvc_get_white_balance_temperature);
qDebug() << uvc_get(devh, uvc_get_sharpness);
qDebug() << uvc_get(devh, uvc_get_backlight_compensation);
qDebug() << uvc_get(devh, uvc_get_gamma);
qDebug() << uvc_get(devh, uvc_get_gain);
qDebug() << uvc_get(devh, uvc_get_exposure_abs);
qDebug() << uvc_get(devh, uvc_get_hue);
qDebug() << uvc_get_mode(devh, uvc_get_ae_mode);
qDebug() << uvc_get_mode(devh, uvc_get_ae_priority);
qDebug() << uvc_get_mode(devh, uvc_get_contrast_auto);
qDebug() << uvc_get_mode(devh, uvc_get_focus_auto);
qDebug() << uvc_get_mode(devh, uvc_get_white_balance_component_auto);
qDebug() << uvc_get_mode(devh, uvc_get_white_balance_temperature_auto);
qDebug() << uvc_get_mode(devh, uvc_get_hue_auto);
}
// This allows us to change defaults without recompiling the uvcengine; EyeRec can do its own thing later
QFileInfo uvcSettingsFile( QString("%1/cfg/camera-parameters/defaults/%2.ini").arg(QCoreApplication::applicationDirPath()).arg(deviceName) );
bool hasFileParameters = uvcSettingsFile.exists();
QSettings settings(uvcSettingsFile.absoluteFilePath(), QSettings::IniFormat);
DefaultParameters par;
if (hasFileParameters) {
par.bandwidthFactor = settings.value("bandwidthFactor").toDouble();
par.brightness = settings.value("brightness").toDouble();
par.contrast = settings.value("contrast").toDouble();
par.saturation = settings.value("saturation").toDouble();
par.white_balance = settings.value("white_balance").toDouble();
par.sharpness = settings.value("sharpness").toDouble();
par.backlight_compensation = settings.value("backlight_compensation").toDouble();
par.gamma = settings.value("gamma").toDouble();
par.gain = settings.value("gain").toDouble();
par.exposure_abs = settings.value("exposure_abs").toDouble();
par.hue = settings.value("hue").toDouble();
par.ae_mode = settings.value("ae_mode").toInt();
par.ae_priority = settings.value("ae_priority").toInt();
par.contrast_auto = settings.value("contrast_auto").toInt();
par.focus_auto = settings.value("focus_auto").toInt();
par.white_balance_component_auto = settings.value("white_balance_component_auto").toInt();
par.white_balance_temperature_auto = settings.value("white_balance_temperature_auto").toInt();
par.hue_auto = settings.value("hue_auto").toInt();
} else {
if ( defaults.count(deviceName) <= 0) // We don't have anything to set, return
return;
par = defaults[deviceName];
}
// Now save the settings
settings.setValue("bandwidthFactor", par.bandwidthFactor);
settings.setValue("brightness", par.brightness);
settings.setValue("contrast", par.contrast);
settings.setValue("saturation", par.saturation);
settings.setValue("white_balance", par.white_balance);
settings.setValue("sharpness", par.sharpness);
settings.setValue("backlight_compensation", par.backlight_compensation);
settings.setValue("gamma", par.gamma);
settings.setValue("gain", par.gain);
settings.setValue("exposure_abs", par.exposure_abs);
settings.setValue("hue", par.hue);
settings.setValue("ae_mode", par.ae_mode);
settings.setValue("ae_priority", par.ae_priority);
settings.setValue("contrast_auto", par.contrast_auto);
settings.setValue("focus_auto", par.focus_auto);
settings.setValue("white_balance_component_auto", par.white_balance_component_auto);
settings.setValue("white_balance_temperature_auto", par.white_balance_temperature_auto);
settings.setValue("hue_auto", par.hue_auto);
// and set them to the device
uvc_set(devh, uvc_set_brightness, par.brightness, uvc_get_brightness);
uvc_set(devh, uvc_set_contrast, par.contrast, uvc_get_contrast);
uvc_set(devh, uvc_set_saturation, par.saturation, uvc_get_saturation);
uvc_set(devh, uvc_set_white_balance_temperature, par.white_balance, uvc_get_white_balance_temperature);
uvc_set(devh, uvc_set_sharpness, par.sharpness, uvc_get_sharpness);
uvc_set(devh, uvc_set_backlight_compensation, par.backlight_compensation, uvc_get_backlight_compensation);
uvc_set(devh, uvc_set_gamma, par.gamma, uvc_get_gamma);
uvc_set(devh, uvc_set_gain, par.gain, uvc_get_gain);
uvc_set(devh, uvc_set_exposure_abs, par.exposure_abs, uvc_get_exposure_abs);
uvc_set(devh, uvc_set_hue, par.hue, uvc_get_hue);
uvc_set_mode(devh, uvc_set_ae_mode, par.ae_mode);
uvc_set_mode(devh, uvc_set_ae_priority, par.ae_priority);
uvc_set_mode(devh, uvc_set_contrast_auto, par.contrast_auto);
uvc_set_mode(devh, uvc_set_focus_auto, par.focus_auto);
uvc_set_mode(devh, uvc_set_white_balance_component_auto, par.white_balance_component_auto);
uvc_set_mode(devh, uvc_set_white_balance_temperature_auto, par.white_balance_temperature_auto);
uvc_set_mode(devh, uvc_set_hue_auto, par.hue_auto);
bandwidthFactor = par.bandwidthFactor;
}
......@@ -19,6 +19,7 @@
#include <vector>
#include <atomic>
#include <map>
#include "libuvc/libuvc.h"
......@@ -27,6 +28,27 @@ QT_BEGIN_NAMESPACE
// Maximum acceptable latency for calling the surface present method
#define MAX_LATENCY_MS 1.0e3/25
struct DefaultParameters {
double bandwidthFactor;
double brightness;
double contrast;
double saturation;
double white_balance;
double sharpness;
double backlight_compensation;
double gamma;
double gain;
double exposure_abs;
double hue;
int ae_mode;
int ae_priority;
int contrast_auto;
int focus_auto;
int white_balance_component_auto;
int white_balance_temperature_auto;
int hue_auto;
};
class UVCCameraSession : public QObject
{
Q_OBJECT
......@@ -56,6 +78,8 @@ public:
double interval;
// Image Processing
// TODO: we don't check if the camera supports the parameters since some
// cameras underreport their capabilities; is this safe?
template<typename T>
QVariant uvc_get( uvc_device_handle_t *devh,
uvc_error_t (*get)( uvc_device_handle_t *, T *, enum uvc_req_code)
......@@ -64,10 +88,17 @@ public:
get(devh, &mn, UVC_GET_MIN);
get(devh, &val, UVC_GET_CUR);
get(devh, &mx, UVC_GET_MAX);
//qDebug() << mn << val << mx;
return (val - mn) / (double) (mx - mn) ;
}
template<typename T>
QVariant uvc_get_mode( uvc_device_handle_t *devh,
uvc_error_t (*get)( uvc_device_handle_t *, T *, enum uvc_req_code)
) const {
T val;
get(devh, &val, UVC_GET_CUR);
return val;
}
template<typename T>
void uvc_set( uvc_device_handle_t *devh,
uvc_error_t (*set)( uvc_device_handle_t *, T),
QVariant val,
......@@ -78,9 +109,15 @@ public:
get(devh, &mx, UVC_GET_MAX);
double value = val.toDouble();
value = value * (mx - mn ) + mn;
//qDebug() << val;
set(devh, static_cast<T>(value));
}
template<typename T>
void uvc_set_mode( uvc_device_handle_t *devh,
uvc_error_t (*set)( uvc_device_handle_t *, T),
QVariant val
) {
set(devh, static_cast<T>(val.toInt()));
}
// Image Processing
bool isImageProcessingParameterSupported(QCameraImageProcessingControl::ProcessingParameter parameter) const;
......@@ -101,7 +138,7 @@ private Q_SLOTS:
void presentFrame(QVideoFrame frame, const qreal t);
private:
float bandwidthFactor;
double bandwidthFactor;
QCamera::Status m_status;
QAbstractVideoSurface *m_surface;
QMutex surfaceMutex;
......@@ -132,6 +169,9 @@ private:
static QMutex UVCCameraSession::devicesMutex;
bool acquire(const QString &device);
void release(const QString &device);
std::map<QString,DefaultParameters> defaults;
void setDefaultParameters();
};
QT_END_NAMESPACE
......
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