Commit 22897a30 authored by Thiago Santini's avatar Thiago Santini

Adds parameters UI

parent cddf1351
#include "Camera.h"
#include <QFileInfo>
static int gQCameraInfoMetaTypeId = qRegisterMetaType<QCameraInfo>("QCameraInfo");
static int gMatMetaTypeId = qRegisterMetaType<cv::Mat>("cv::Mat");
......@@ -187,6 +188,8 @@ void Camera::setCamera(const QCameraInfo &cameraInfo, QCameraViewfinderSettings
retriesLeft = maxRetries;
}
loadUserCameraParameters();
setValuesUI();
saveCfg();
qInfo() << id << msg;
QMetaObject::invokeMethod(ui, "updateSettings", Q_ARG(QList<QCameraViewfinderSettings>, settingsList), Q_ARG(QCameraViewfinderSettings, currentViewfinderSettings) );
......@@ -201,31 +204,31 @@ void Camera::setColorCode(int code)
void Camera::setParameter(QString what, float value)
{
//qDebug() << what << value;
if (!camera)
return;
QCameraImageProcessing *ip = camera->imageProcessing();
QCameraExposure *exp = camera->exposure();
QString parameter = what.toLower();
qDebug() << what << value;
QString parameter = what;
if ( ip->isAvailable() ) {
if (parameter == "brightness")
ip->setBrightness(value);
if (parameter == "contrast")
ip->setContrast(value);
if (parameter == "white balance")
if (parameter == "white_balance")
ip->setManualWhiteBalance(value);
if (parameter == "saturation")
ip->setSaturation(value);
if (parameter == "sharpening level")
if (parameter == "sharpening_level")
ip->setSharpeningLevel(value);
}
if ( exp->isAvailable() ) {
if (parameter == "exposure mode") {
if (parameter == "exposure_time")
exp->setManualAperture(value);
if (parameter == "exposure_mode") {
switch ( (int) value ) {
case 1:
exp->setExposureMode(QCameraExposure::ExposureManual);
......@@ -235,10 +238,38 @@ void Camera::setParameter(QString what, float value)
break;
}
}
if (parameter == "exposure time")
exp->setManualAperture(value);
}
saveCameraParameter(parameter, value);
}
void Camera::setValuesUI()
{
if (!camera)
return;
QCameraImageProcessing *ip = camera->imageProcessing();
QCameraExposure *exp = camera->exposure();
if ( ip->isAvailable() ) {
ui->setValue( ui->findChild<QDoubleSpinBox*>("brightness"), ip->brightness() );
ui->setValue( ui->findChild<QDoubleSpinBox*>("contrast"), ip->contrast() );
ui->setValue( ui->findChild<QDoubleSpinBox*>("white_balance"), ip->manualWhiteBalance() );
ui->setValue( ui->findChild<QDoubleSpinBox*>("saturation"), ip->saturation() );
ui->setValue( ui->findChild<QDoubleSpinBox*>("sharpening_level"), ip->sharpeningLevel() );
}
if ( exp->isAvailable() ) {
ui->setValue( ui->findChild<QDoubleSpinBox*>("exposure_time"), exp->aperture() );
switch ( (int) exp->exposureMode() ) {
case QCameraExposure::ExposureManual:
ui->setValue( ui->findChild<QComboBox*>("exposure_mode"), 1 );
break;
case QCameraExposure::ExposureAuto:
ui->setValue( ui->findChild<QComboBox*>("exposure_mode"), 2 );
break;
}
}
}
void Camera::showOptions()
......@@ -363,3 +394,18 @@ void Camera::searchDefaultCamera()
}
}
void Camera::loadUserCameraParameters()
{
QFileInfo cameraSettingsFile( makeSettingsFileName() );
if ( ! cameraSettingsFile.exists() )
return;
QSettings settings(cameraSettingsFile.absoluteFilePath(), QSettings::IniFormat);
loadAndSet(settings, "brightness");
loadAndSet(settings, "contrast");
loadAndSet(settings, "white_balance");
loadAndSet(settings, "saturation");
loadAndSet(settings, "sharpening_level");
loadAndSet(settings, "exposure_time");
loadAndSet(settings, "exposure_mode");
}
......@@ -15,6 +15,7 @@
#include <QRegularExpression>
#include <QFormLayout>
#include <QDoubleSpinBox>
#include <QFileInfo>
#include "opencv/cv.h"
......@@ -100,7 +101,29 @@ public:
this, SLOT(settingsChanged(int)) );
connect(colorBox, SIGNAL(currentIndexChanged(int)),
this, SLOT(colorChanged(int)) );
}
}
void setValue(QDoubleSpinBox *sb, double val) {
if (!sb)
return;
sb->blockSignals(true);
sb->setValue(100*val);
sb->blockSignals(false);
}
void setValue(QSlider *s, double val) {
if (!s)
return;
s->blockSignals(true);
s->setValue(100*val);
s->blockSignals(false);
}
void setValue(QComboBox *cb, QVariant val) {
if (!cb)
return;
cb->blockSignals(true);
cb->setCurrentIndex(cb->findData(val));
cb->blockSignals(false);
}
public slots:
void update(QCameraInfo current, int colorCode)
......@@ -178,14 +201,13 @@ private:
QComboBox *devicesBox;
QComboBox *settingsBox;
QComboBox *colorBox;
QSlider *brightnessSlider;
void addSlider(QFormLayout *formLayout, QString label ) {
QSlider *slider = new QSlider( Qt::Horizontal );
slider->setMinimum(0);
slider->setMaximum(100);
slider->setSingleStep(1);
slider->setObjectName(label);
slider->setObjectName(label.toLower().replace(" ", "_"));
formLayout->addRow(new QLabel(label), slider);
connect(slider, SIGNAL(sliderReleased()), this, SLOT(sliderReleased()) );
}
......@@ -196,7 +218,7 @@ private:
sb->setMaximum(100);
sb->setSingleStep(0.5);
sb->setDecimals(1);
sb->setObjectName(label);
sb->setObjectName(label.toLower().replace(" ", "_"));
sb->setSuffix("%");
formLayout->addRow(new QLabel(label), sb);
connect(sb, SIGNAL(valueChanged(double)), this, SLOT(spinBoxChanged(double)) );
......@@ -204,7 +226,7 @@ private:
QComboBox* addComboBox(QFormLayout *formLayout, QString label ) {
QComboBox *box = new QComboBox();
box->setObjectName(label);
box->setObjectName(label.toLower().replace(" ", "_"));
formLayout->addRow(new QLabel(label), box);
connect(box, SIGNAL(currentIndexChanged(int)), this, SLOT(comboBoxChanged()) );
return box;
......@@ -234,11 +256,12 @@ public slots:
void setCamera(const QCameraInfo &cameraInfo, QCameraViewfinderSettings settings);
void setColorCode(int code);
void setParameter(QString what, float value);
void showOptions();
void setValuesUI();
void showOptions();
void saveCfg();
void loadCfg();
void timedout();
void retry();
void retry();
private:
QString id;
......@@ -256,6 +279,36 @@ private:
static QMutex setCameraMutex;
void searchDefaultCamera();
QString makeSettingsFileName() { return QString("%1/cfg/camera-parameters/%2.ini").arg(QCoreApplication::applicationDirPath()).arg(currentCameraInfo.deviceName()); }
bool loadCameraParameter(const QSettings &settings, const QString &parameter, double &value)
{
if ( ! settings.contains(parameter) )
return false;
value = settings.value(parameter).toDouble();
return true;
}
bool loadCameraParameter(const QString &parameter, double &value)
{
QFileInfo cameraSettingsFile( makeSettingsFileName() );
if ( ! cameraSettingsFile.exists() )
return false;
QSettings settings(cameraSettingsFile.absoluteFilePath(), QSettings::IniFormat);
return loadCameraParameter(settings, parameter, value);
}
void saveCameraParameter(const QString &parameter, const double &value)
{
QFileInfo cameraSettingsFile( makeSettingsFileName() );
QSettings s(cameraSettingsFile.absoluteFilePath(), QSettings::IniFormat);
s.setValue(parameter, value);
}
void loadAndSet(const QSettings &settings, QString key) {
double value;
if ( loadCameraParameter(settings, key, value) )
setParameter(key, value);
}
void loadUserCameraParameters();
private slots:
void reset();
};
......
......@@ -7,9 +7,6 @@ using namespace aruco;
static int gFieldDataId = qRegisterMetaType<FieldData>("FieldData");
static int markerDetectionCounter = 0;
static int redetectMarkerCounter = 1;
FieldImageProcessor::FieldImageProcessor(QString id, QObject *parent)
: id(id),
sROI(QPointF(0,0)),
......@@ -94,20 +91,6 @@ void FieldImageProcessor::process(Timestamp timestamp, const Mat &frame)
}
if (cfg.markerDetectionMethod == "aruco" || gCalibrating) {
#define LIMIT_MARKER_DETECTION
#ifdef LIMIT_MARKER_DETECTION
if ( markerDetectionCounter == redetectMarkerCounter ) {
detectMarkers(downscaled, dict, corners, ids, detectorParameters);
if (cfg.processingDownscalingFactor > 1) { // Upscale if necessary
for (unsigned int i=0; i<ids.size(); i++)
for (unsigned int j=0; j<corners[i].size(); j++)
corners[i][j] = cfg.processingDownscalingFactor*corners[i][j];
}
markerDetectionCounter = 0;
} else
markerDetectionCounter++;
#else
detectMarkers(downscaled, dict, corners, ids, detectorParameters);
if (cfg.processingDownscalingFactor > 1) { // Upscale if necessary
......@@ -115,7 +98,6 @@ void FieldImageProcessor::process(Timestamp timestamp, const Mat &frame)
for (unsigned int j=0; j<corners[i].size(); j++)
corners[i][j] = cfg.processingDownscalingFactor*corners[i][j];
}
#endif
}
// Filling the marker data
......
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