add support for chaning cvimage scaleing in ui

cahnge .desktop exec params
This commit is contained in:
2021-07-16 14:11:04 +02:00
parent 07e6b6611d
commit feceb3287c
8 changed files with 83 additions and 16 deletions

View File

@ -6,7 +6,7 @@ Version=1.0
# The name of the application # The name of the application
Name=Lubricant Thickness Detector Name=Lubricant Thickness Detector
# A comment which can/will be used as a tooltip # A comment which can/will be used as a tooltip
Comment=MAClient Comment=MAClient -sd 0 -t 30
# The executable of the application, possibly with arguments. # The executable of the application, possibly with arguments.
Exec=MAClient Exec=MAClient
# The name of the icon that will be used to display this entry # The name of the icon that will be used to display this entry

View File

@ -84,6 +84,8 @@ int main(int argc, char *argv[])
parser.addOption(quirkDurationOption); parser.addOption(quirkDurationOption);
QCommandLineOption cameraBootDurationOption(QStringList() << "t" << "boot-duration", QCoreApplication::translate("main", "Camera boot time"), QCoreApplication::translate("main", "time")); QCommandLineOption cameraBootDurationOption(QStringList() << "t" << "boot-duration", QCoreApplication::translate("main", "Camera boot time"), QCoreApplication::translate("main", "time"));
parser.addOption(cameraBootDurationOption); parser.addOption(cameraBootDurationOption);
QCommandLineOption viewerOption(QStringList() << "c" << "viewer", QCoreApplication::translate("main", "Open app as viewer"));
parser.addOption(viewerOption);
parser.process(a); parser.process(a);
QSplashScreen splash(QPixmap(":/images/splash.png")); QSplashScreen splash(QPixmap(":/images/splash.png"));
@ -99,7 +101,7 @@ int main(int argc, char *argv[])
QSettings settings(QSettings::IniFormat, QSettings::UserScope, QCoreApplication::organizationName(), QCoreApplication::applicationName()); QSettings settings(QSettings::IniFormat, QSettings::UserScope, QCoreApplication::organizationName(), QCoreApplication::applicationName());
if(uvosledRet >= 0) if(uvosledRet >= 0 && !parser.isSet(viewerOption))
{ {
qDebug()<<"uvosled_poweron"; qDebug()<<"uvosled_poweron";
uvosled_poweron(&led); uvosled_poweron(&led);
@ -118,7 +120,7 @@ int main(int argc, char *argv[])
if(parser.isSet(quirkDurationOption)) if(parser.isSet(quirkDurationOption))
cameras.quirkTime = parser.value(quirkDurationOption).toDouble(); cameras.quirkTime = parser.value(quirkDurationOption).toDouble();
MainWindow w; MainWindow w(parser.isSet(viewerOption));
QObject::connect(&cameras, &Cameras::cameraAdded, &w, &MainWindow::addCamera); QObject::connect(&cameras, &Cameras::cameraAdded, &w, &MainWindow::addCamera);
QObject::connect(&cameras, &Cameras::cameraRemoved, &w, &MainWindow::removeCamera); QObject::connect(&cameras, &Cameras::cameraRemoved, &w, &MainWindow::removeCamera);
@ -159,10 +161,10 @@ int main(int argc, char *argv[])
splash.hide(); splash.hide();
w.show(); w.show();
if(uvosledRet < 0) if(uvosledRet < 0 && !parser.isSet(viewerOption))
QMessageBox::warning(&w, "UVOS LED", "Can not connect to the UVOS LED device"); QMessageBox::warning(&w, "UVOS LED", "Can not connect to the UVOS LED device");
if(cameras.getCameras().empty()) if(!parser.isSet(viewerOption) && cameras.getCameras().empty())
{ {
QMessageBox::information(&w, "Cameras", "No cameras configured, please choose at least one camera."); QMessageBox::information(&w, "Cameras", "No cameras configured, please choose at least one camera.");
cameras.setCameras(showCameraSelectionDialog()); cameras.setCameras(showCameraSelectionDialog());

View File

@ -95,10 +95,10 @@ void ConfigureCameraDialog::bayerIndexChanged(int index)
setup_.bayerMode = cam::Camera::BAYER_BLUE; setup_.bayerMode = cam::Camera::BAYER_BLUE;
break; break;
case 1: case 1:
setup_.bayerMode = cam::Camera::BAYER_RED; setup_.bayerMode = cam::Camera::BAYER_GREEN;
break; break;
case 2: case 2:
setup_.bayerMode = cam::Camera::BAYER_GREEN; setup_.bayerMode = cam::Camera::BAYER_RED;
break; break;
case 3: case 3:
setup_.bayerMode = cam::Camera::BAYER_PASSTHOUGH; setup_.bayerMode = cam::Camera::BAYER_PASSTHOUGH;

View File

@ -90,6 +90,14 @@ void CvImageViewer::showSatDiag()
diag.exec(); diag.exec();
} }
void CvImageViewer::setClamp(double max)
{
clamp_ = max;
convertImage(origImage_);
update();
roi_ = cv::Rect(0, 0, image_.size().width, image_.size().height);
}
void CvImageViewer::convertImage(cv::Mat image) void CvImageViewer::convertImage(cv::Mat image)
{ {
image_ = image; image_ = image;
@ -107,6 +115,13 @@ void CvImageViewer::convertImage(cv::Mat image)
{ {
double min, max; double min, max;
cv::minMaxIdx(image_, &min, &max); cv::minMaxIdx(image_, &min, &max);
sigMax(max);
if(max > clamp_)
{
max = clamp_;
qDebug()<<"clamped to"<<clamp_;
}
double a = 255.0/(max - min); double a = 255.0/(max - min);
double b = 0-(min*a); double b = 0-(min*a);
qDebug()<<min<<max<<a<<b; qDebug()<<min<<max<<a<<b;
@ -118,6 +133,9 @@ void CvImageViewer::convertImage(cv::Mat image)
{ {
double min, max; double min, max;
cv::minMaxIdx(image_, &min, &max); cv::minMaxIdx(image_, &min, &max);
sigMax(max);
if(max > clamp_)
max = clamp_;
double a = 255.0/(max - min); double a = 255.0/(max - min);
double b = 0-(min*a); double b = 0-(min*a);
qDebug()<<min<<max<<a<<b; qDebug()<<min<<max<<a<<b;

View File

@ -4,6 +4,8 @@
#include <QWidget> #include <QWidget>
#include <QPainter> #include <QPainter>
#include <QMenu> #include <QMenu>
#include <QSlider>
#include <limits>
#include "../cameras.h" #include "../cameras.h"
class CvImageViewer : public QWidget class CvImageViewer : public QWidget
@ -25,6 +27,7 @@ private:
cv::Rect roi_; cv::Rect roi_;
QRect selectionRect_; QRect selectionRect_;
bool selectionStarted_ = false; bool selectionStarted_ = false;
double clamp_ = std::numeric_limits<double>::max();
void transfromToSourceCoordinates(int inX, int inY, int& outX, int& outY); void transfromToSourceCoordinates(int inX, int inY, int& outX, int& outY);
void convertImage(cv::Mat image); void convertImage(cv::Mat image);
@ -44,9 +47,11 @@ protected:
signals: signals:
void sigValue(size_t x, size_t y, double value); void sigValue(size_t x, size_t y, double value);
void sigMax(double max);
public slots: public slots:
void setImage(Camera::Image img); void setImage(Camera::Image img);
void setClamp(double max);
public: public:
explicit CvImageViewer(QWidget *parent = nullptr, size_t lastId = 0); explicit CvImageViewer(QWidget *parent = nullptr, size_t lastId = 0);

View File

@ -7,7 +7,7 @@
#include "../profile.h" #include "../profile.h"
MainWindow::MainWindow(QWidget *parent) MainWindow::MainWindow(bool viewer, QWidget *parent)
: QMainWindow(parent) : QMainWindow(parent)
, about_(this) , about_(this)
, ui(new Ui::MainWindow) , ui(new Ui::MainWindow)
@ -24,8 +24,17 @@ MainWindow::MainWindow(QWidget *parent)
connect(ui->actionOpen, &QAction::triggered, [this](bool checked){(void)checked; openImage();}); connect(ui->actionOpen, &QAction::triggered, [this](bool checked){(void)checked; openImage();});
connect(ui->actionSave_2, &QAction::triggered, [this](bool checked){(void)checked; saveImage();}); connect(ui->actionSave_2, &QAction::triggered, [this](bool checked){(void)checked; saveImage();});
connect(ui->actionAbout, &QAction::triggered, [this](bool checked){(void)checked; about_.show();}); connect(ui->actionAbout, &QAction::triggered, [this](bool checked){(void)checked; about_.show();});
connect(ui->horizontalSlider_max, &QSlider::sliderMoved, [this](double value){ui->mainViewer->setClamp(value/10.0);});
connect(ui->mainViewer, &CvImageViewer::sigMax, [this](double max){ui->horizontalSlider_max->setMaximum(max*10.0);});
refreshProfiles(); refreshProfiles();
if(viewer)
{
ui->groupBoxCameras->setVisible(false);
ui->groupBox_3->setVisible(false);
} }
}
void MainWindow::setImageValue(size_t x, size_t y, double value) void MainWindow::setImageValue(size_t x, size_t y, double value)
{ {
ui->lcdNumber_3->display((double)x); ui->lcdNumber_3->display((double)x);

View File

@ -42,7 +42,7 @@ public slots:
void setTemperature(double temp); void setTemperature(double temp);
public: public:
MainWindow(QWidget *parent = nullptr); MainWindow(bool viewer = false, QWidget *parent = nullptr);
~MainWindow(); ~MainWindow();
CvImageViewer* mainImageViewer(); CvImageViewer* mainImageViewer();

View File

@ -6,8 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>800</width> <width>1042</width>
<height>600</height> <height>635</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -42,8 +42,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>182</width> <width>244</width>
<height>483</height> <height>518</height>
</rect> </rect>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_7"> <layout class="QVBoxLayout" name="verticalLayout_7">
@ -74,8 +74,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>563</width> <width>743</width>
<height>282</height> <height>289</height>
</rect> </rect>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_6"> <layout class="QVBoxLayout" name="verticalLayout_6">
@ -135,6 +135,39 @@
</item> </item>
</layout> </layout>
</item> </item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label_5">
<property name="text">
<string>Render scale</string>
</property>
</widget>
</item>
<item>
<widget class="QSlider" name="horizontalSlider_max">
<property name="maximum">
<number>100</number>
</property>
<property name="pageStep">
<number>1</number>
</property>
<property name="value">
<number>100</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
</layout>
</item>
</layout> </layout>
</widget> </widget>
</item> </item>
@ -227,7 +260,7 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>800</width> <width>1042</width>
<height>32</height> <height>32</height>
</rect> </rect>
</property> </property>