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

Adds parameters UI

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