diff --git a/src/cameras.cpp b/src/cameras.cpp index 67e3e99..18150d7 100644 --- a/src/cameras.cpp +++ b/src/cameras.cpp @@ -308,9 +308,16 @@ double Cameras::getMeanTemp() void Cameras::setSetup(const std::vector& setups) { for(auto& camera : cameras_) + { for(auto& setup : setups) + { if(camera->id() == setup.id) + { camera->cam()->setBayerMode(setup.bayerMode); + camera->cam()->setGain(setup.gain); + } + } + } } void Cameras::store(QSettings &settings) diff --git a/src/imagepipeline.cpp b/src/imagepipeline.cpp index 9cfc8ba..e09781c 100644 --- a/src/imagepipeline.cpp +++ b/src/imagepipeline.cpp @@ -101,7 +101,7 @@ cv::Mat ImagePipeline::process(const Profile profile, std::vector <<"at"<>remapMap.yMat; matf[("_"+QString::number(id)+"_origin").toStdString()]>>remapMap.topLeftCoordinate; matf[("_"+QString::number(id)+"_bayermode").toStdString()]>>bayerMode; + try + { + matf[("_"+QString::number(id)+"_gain").toStdString()]>>gain; + } + catch(cv::Exception& e) + { + qWarning()<<"Profile dose not have gain"; + gain = 1.0; + } } else { diff --git a/src/profile.h b/src/profile.h index 1ce2e00..a0cbbb2 100644 --- a/src/profile.h +++ b/src/profile.h @@ -18,6 +18,7 @@ public: cv::Mat darkmap; cv::Mat bgmask; cam::Camera::BayerMode bayerMode = cam::Camera::BAYER_BLUE; + double gain = 1.0; void store(const QString& filename) const; void load(const QString& name, size_t cameraId); }; diff --git a/src/ui/configurecameradialog.cpp b/src/ui/configurecameradialog.cpp index eee19f4..4195cf8 100644 --- a/src/ui/configurecameradialog.cpp +++ b/src/ui/configurecameradialog.cpp @@ -51,6 +51,9 @@ ConfigureCameraDialog::ConfigureCameraDialog(const CameraSetup& setup, std::shar break; } + ui->doubleSpinBoxGain->setValue(setup_.gain); + + camera_->cam()->setGain(setup_.gain); camera_->cam()->setBayerMode(setup_.bayerMode); uint64_t min, max; @@ -70,6 +73,7 @@ ConfigureCameraDialog::ConfigureCameraDialog(const CameraSetup& setup, std::shar connect(ui->pushButtonBgShow, &QPushButton::clicked, [this](){if(setup_.bgmask.data) ui->widget_4->setImage(Camera::Image(setup_.bgmask, 0));}); connect(ui->pushButtonDarkImageShow, &QPushButton::clicked, [this](){if(setup_.darkmap.data) ui->widget_4->setImage(Camera::Image(setup_.darkmap, 0));}); connect(ui->comboBox_bayer, QOverload::of(&QComboBox::currentIndexChanged), this, &ConfigureCameraDialog::bayerIndexChanged); + connect(ui->doubleSpinBoxGain, QOverload::of(&QDoubleSpinBox::valueChanged), this, &ConfigureCameraDialog::setExposure); checkConfig(); } @@ -87,6 +91,15 @@ void ConfigureCameraDialog::setExposure(double value) qDebug()<<"set exposure to "<cam()->setGain(value)) + QMessageBox::warning(this, "Warning", "Failed to set exposure"); + else + qDebug()<<"set gain to "< 6 - - - - false - + + - Clear + Create @@ -57,6 +54,33 @@ + + + + Create + + + + + + + false + + + Clear + + + + + + + false + + + Show + + + @@ -67,6 +91,27 @@ + + + + Dark image + + + + + + + Remap Map (required) + + + + + + + Create + + + @@ -83,58 +128,6 @@ - - - - Background image - - - - - - - Create - - - - - - - Create - - - - - - - Dark image - - - - - - - false - - - Show - - - - - - - Remap Map (required) - - - - - - - Create - - - @@ -151,16 +144,6 @@ - - - - false - - - Show - - - @@ -171,6 +154,33 @@ + + + + false + + + Show + + + + + + + Background image + + + + + + + Gain + + + + + + diff --git a/src/ui/cvimageviewer.cpp b/src/ui/cvimageviewer.cpp index 1abbdc5..b8e0c29 100644 --- a/src/ui/cvimageviewer.cpp +++ b/src/ui/cvimageviewer.cpp @@ -35,6 +35,8 @@ CvImageViewer::CvImageViewer(QWidget *parent, size_t lastId) : plot.setMinimumWidth(800); plot.setMinimumHeight(600); + plot.setWindowIcon(windowIcon()); + plot.setWindowTitle(windowTitle()); setMouseTracking(true); } @@ -133,6 +135,8 @@ void CvImageViewer::convertImage(cv::Mat image) { qimage_ = QImage(image_.data, image_.cols, image_.rows, image_.step, QImage::Format_Grayscale8); statisticsAction_.setDisabled(false); + xPlotAction_.setDisabled(false); + yPlotAction_.setDisabled(false); } else if(image_.type() == CV_32FC1 || image_.type() == CV_64FC1) { @@ -221,22 +225,27 @@ void CvImageViewer::zoomToSelection() void CvImageViewer::plotOnX() { - if(!xLine_.isNull() && origImage_.data && (origImage_.type() == CV_32FC1 || origImage_.type() == CV_64FC1)) + if(!xLine_.isNull() && origImage_.data && (origImage_.type() == CV_32FC1 || origImage_.type() == CV_64FC1 || origImage_.type() == CV_8UC1)) { + cv::Mat plotImage; + if(origImage_.type() == CV_8UC1) + origImage_.convertTo(plotImage, CV_32FC1); + else + plotImage = origImage_; plot.clear(); QVector keys; QVector values; int x, y; transfromToSourceCoordinates(xLine_.p1().x(), xLine_.p1().y(), x, y); double max = 0; - for(int i = 0; i < origImage_.cols; ++i) + for(int i = 0; i < plotImage.cols; ++i) { keys.push_back(i); double value; - if(origImage_.type() == CV_32FC1) - value = origImage_.at(y, i); + if(plotImage.type() == CV_32FC1) + value = plotImage.at(y, i); else - value = origImage_.at(y, i); + value = plotImage.at(y, i); if(max < value) max = value; values.push_back(value); @@ -252,22 +261,27 @@ void CvImageViewer::plotOnX() void CvImageViewer::plotOnY() { - if(!xLine_.isNull() && origImage_.data && (origImage_.type() == CV_32FC1 || origImage_.type() == CV_64FC1)) + if(!xLine_.isNull() && origImage_.data && (origImage_.type() == CV_32FC1 || origImage_.type() == CV_64FC1 || origImage_.type() == CV_8UC1)) { + cv::Mat plotImage; + if(origImage_.type() == CV_8UC1) + origImage_.convertTo(plotImage, CV_32FC1); + else + plotImage = origImage_; plot.clear(); QVector keys; QVector values; int x, y; transfromToSourceCoordinates(yLine_.p1().x(), yLine_.p1().y(), x, y); double max = 0; - for(int i = 0; i < origImage_.rows; ++i) + for(int i = 0; i < plotImage.rows; ++i) { keys.push_back(i); double value; - if(origImage_.type() == CV_32FC1) - value = origImage_.at(i, x); + if(plotImage.type() == CV_32FC1) + value = plotImage.at(i, x); else - value = origImage_.at(i, x); + value = plotImage.at(i, x); if(max < value) max = value; values.push_back(value); diff --git a/src/ui/cvimageviewer.h b/src/ui/cvimageviewer.h index 2166e91..c6a9282 100644 --- a/src/ui/cvimageviewer.h +++ b/src/ui/cvimageviewer.h @@ -74,3 +74,4 @@ public: }; #endif // CVIMAGEVIEWER_H + diff --git a/src/ui/editprofiledialog.cpp b/src/ui/editprofiledialog.cpp index 40490c3..b986a70 100644 --- a/src/ui/editprofiledialog.cpp +++ b/src/ui/editprofiledialog.cpp @@ -20,6 +20,7 @@ EditProfileDialog::EditProfileDialog(Cameras* cameras, const Profile profile, QW ui->lineEditName->setText(name); ui->doubleSpinBoxBrightness->setValue(profile_.lighting.brightness*100.0); ui->doubleSpinBoxExposure->setValue(profile_.exposureTime); + ui->doubleSpinBox_kFactor->setValue(profile_.kFactor); qDebug()<<"Mask: "<setLabel("Coordinate"); yAxis->setLabel("Counts"); @@ -50,12 +51,14 @@ Plot::Plot(QWidget* parent): connect(&actionDelete_Regression, &QAction::triggered, this, &Plot::deleteRegression); connect(&actionExport_Selection, &QAction::triggered, this, &Plot::saveCsvDiag); connect(&actionSetValueString, &QAction::triggered, this, &Plot::askForValueString); + connect(&savePdfAction, &QAction::triggered, this, &Plot::savePdf); graphContextMenu.addAction(&actionStatistics); graphContextMenu.addAction(&actionAdd_Regression); graphContextMenu.addAction(&actionDelete_Regression); graphContextMenu.addAction(&actionExport_Selection); graphContextMenu.addAction(&actionSetValueString); + graphContextMenu.addAction(&savePdfAction); } Plot::~Plot() @@ -63,6 +66,14 @@ Plot::~Plot() } +void Plot::savePdf() +{ + QString fileName = QFileDialog::getSaveFileName(this, "Save graph as PDF", "./", "*.pdf" ); + + if(!fileName.isEmpty()) + QCustomPlot::savePdf(fileName); +} + bool Plot::event(QEvent *event) { if(event->type()==QEvent::Gesture) graphContextMenu.show(); @@ -78,9 +89,11 @@ void Plot::addMainGraph() { addGraph(); graph(graphCount()-1)->setSelectable(QCP::stDataRange); + graph(graphCount()-1)->setPen(QPen(QBrush(QColor(0,0,255,255)),2,Qt::SolidLine)); QPen selectionPen = graph(graphCount()-1)->pen(); selectionPen.setColor(QColor(255,0,0)); graph(graphCount()-1)->selectionDecorator()->setPen(selectionPen); + } void Plot::clear() @@ -197,7 +210,7 @@ void Plot::deleteRegression() void Plot::showStatistics() { - if(graphCount() > 0 && !graph(0)->selection().dataRanges().at(0).isEmpty()) + if(graphCount() > 0 && !graph(0)->selection().dataRanges().isEmpty() && !graph(0)->selection().dataRanges().at(0).isEmpty()) { QCPDataRange dataRange = graph(0)->selection().dataRanges().at(0); QCPGraphDataContainer::const_iterator begin = graph(0)->data()->at(dataRange.begin()); @@ -210,10 +223,10 @@ void Plot::showStatistics() statDiag.show(); statDiag.exec(); } - else if(graphCount() > 0 && selectedGraphs().size() > 1 && selectedGraphs().at(1) != graph(0)) + else if(graphCount() > 0 && selectedGraphs().size() > 0 && selectedGraphs().at(0) != graph(0)) { unsigned i = 0; - while(selectedGraphs().at(1) != graph(i)) i++; + while(selectedGraphs().at(0) != graph(i)) i++; RegressionDiag regDiag(regressions.at(i-1), this); regDiag.show(); regDiag.exec(); diff --git a/src/ui/plot.h b/src/ui/plot.h index e097671..bad9071 100644 --- a/src/ui/plot.h +++ b/src/ui/plot.h @@ -13,51 +13,55 @@ class Plot : public QCustomPlot { private: - std::vector regressions; + std::vector regressions; - QMenu graphContextMenu; + QMenu graphContextMenu; int graphPointLimit = 10000; - QAction actionStatistics; - QAction actionAdd_Regression; - QAction actionDelete_Regression; - QAction actionExport_Selection; - QAction actionSetValueString; + QAction actionStatistics; + QAction actionAdd_Regression; + QAction actionDelete_Regression; + QAction actionExport_Selection; + QAction actionSetValueString; + QAction savePdfAction; + +private slots: + void savePdf(); public: - Plot(QWidget* parent = nullptr); - ~Plot(); + Plot(QWidget* parent = nullptr); + ~Plot(); - void setLabel(QString label); + void setLabel(QString label); - void clear(); + void clear(); void setLimit(int graphPointLimit); int getLimit(); - void setMaxValue(double maxVal); + void setMaxValue(double maxVal); signals: - void sigSaveCsv(); + void sigSaveCsv(); -public slots: - void addPoints(QVector keys, QVector values); - void saveCsv(QString fileName); - void saveCsvDiag(); - void showStatistics(); - void deleteRegression(); - void addRegression(); - void askForValueString(); + public slots: + void addPoints(QVector keys, QVector values); + void saveCsv(QString fileName); + void saveCsvDiag(); + void showStatistics(); + void deleteRegression(); + void addRegression(); + void askForValueString(); - void addData(QVector keys, QVector values, bool inOrder = false, bool ignoreLimit = false); - void addData(double key, double value, bool ignoreLimit = false); + void addData(QVector keys, QVector values, bool inOrder = false, bool ignoreLimit = false); + void addData(double key, double value, bool ignoreLimit = false); protected: - virtual void mousePressEvent(QMouseEvent *event); - virtual void mouseReleaseEvent(QMouseEvent *event); - virtual bool event(QEvent *event); + virtual void mousePressEvent(QMouseEvent *event); + virtual void mouseReleaseEvent(QMouseEvent *event); + virtual bool event(QEvent *event); private: - void addMainGraph(); + void addMainGraph(); }; #endif // PLOT_H