Change lighting length to be based on when cameras report finished

Fix viewer handling when cammeras are available
This commit is contained in:
uvos
2021-07-19 11:12:23 +02:00
parent 65cdc7b78f
commit a9f263b22d
21 changed files with 67 additions and 36 deletions

View File

@ -6,9 +6,9 @@ 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 -sd 0 -t 30 Comment=MAClient
# The executable of the application, possibly with arguments. # The executable of the application, possibly with arguments.
Exec=MAClient Exec=MAClient -sd 0 -t 30
# 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
Icon=MAClient Icon=MAClient
# Describes whether this application needs to be run in a terminal or not # Describes whether this application needs to be run in a terminal or not

View File

@ -157,13 +157,20 @@ void Cameras::trigger()
if(serial_) if(serial_)
{ {
if(captureingCamera == 0) if(captureingCamera == 0)
lightFor(lighting_, exposrueTime_*1.5*cameras_.size()); {
lightFor(lighting_, 10000);
qDebug()<<__func__<<"started";
std::this_thread::sleep_for(std::chrono::microseconds(static_cast<long>(exposrueTime_)));
}
cameras_[captureingCamera]->cam()->trigger(); cameras_[captureingCamera]->cam()->trigger();
++captureingCamera; ++captureingCamera;
if(captureingCamera < cameras_.size()) if(captureingCamera < cameras_.size())
QTimer::singleShot(exposrueTime_*1000, this, &Cameras::trigger); QTimer::singleShot(exposrueTime_*1000, this, &Cameras::trigger);
else else
{
captureingCamera = 0; captureingCamera = 0;
qDebug()<<__func__<<"finished";
}
} }
else else
{ {
@ -271,6 +278,7 @@ void Cameras::imageRecived(Camera::Image img)
if(images_.size() == cameras_.size()) if(images_.size() == cameras_.size())
{ {
lightOff();
cameraFailureTimer.stop(); cameraFailureTimer.stop();
newImages(images_); newImages(images_);
images_.clear(); images_.clear();

View File

@ -7,6 +7,7 @@
#include <QDebug> #include <QDebug>
#include <algorithm> #include <algorithm>
#include <opencv2/highgui.hpp> #include <opencv2/highgui.hpp>
#include <math.h>
ImagePipeline::ImagePipeline(Cameras* cameras, bool simpleStichingAlg, QObject *parent): ImagePipeline::ImagePipeline(Cameras* cameras, bool simpleStichingAlg, QObject *parent):
QObject(parent), cameras_(cameras), simpleStichingAlg_(simpleStichingAlg) QObject(parent), cameras_(cameras), simpleStichingAlg_(simpleStichingAlg)
@ -43,6 +44,19 @@ void ImagePipeline::applyDarkMap(cv::Mat& image, const cv::Mat& darkmap)
image = subtracted; image = subtracted;
} }
void ImagePipeline::sanityCheckMap(cv::Mat& mat)
{
for(int y = 0; y < mat.rows; y++)
{
float* col = mat.ptr<float>(y);
for(int x = 0; x < mat.cols; ++x)
{
if(isnan(col[x]) || isinf(col[x]))
col[x] = 0.5;
}
}
}
cv::Mat ImagePipeline::process(const Profile profile, std::vector<Camera::Image> images, bool simpleStichingAlg) cv::Mat ImagePipeline::process(const Profile profile, std::vector<Camera::Image> images, bool simpleStichingAlg)
{ {
qDebug()<<__func__<<"got"<<images.size()<<"images"; qDebug()<<__func__<<"got"<<images.size()<<"images";
@ -136,6 +150,9 @@ cv::Mat ImagePipeline::process(const Profile profile, std::vector<Camera::Image>
if(profile.calcurve.data) if(profile.calcurve.data)
applyCurve(output, profile.calcurve); applyCurve(output, profile.calcurve);
sanityCheckMap(output);
return output; return output;
} }
else else

View File

@ -23,6 +23,7 @@ private:
static cv::Mat process(const Profile profile, std::vector<Camera::Image> images, bool simpleStich); static cv::Mat process(const Profile profile, std::vector<Camera::Image> images, bool simpleStich);
static void applyDarkMap(cv::Mat& image, const cv::Mat &darkmap); static void applyDarkMap(cv::Mat& image, const cv::Mat &darkmap);
static void sanityCheckMap(cv::Mat& mat);
private slots: private slots:

View File

@ -122,41 +122,44 @@ int main(int argc, char *argv[])
MainWindow w(parser.isSet(viewerOption)); MainWindow w(parser.isSet(viewerOption));
QObject::connect(&cameras, &Cameras::cameraAdded, &w, &MainWindow::addCamera); if(!parser.isSet(viewerOption))
QObject::connect(&cameras, &Cameras::cameraRemoved, &w, &MainWindow::removeCamera);
QObject::connect(&cameras, &Cameras::enableCapture, &w, &MainWindow::enableCapture);
QObject::connect(&w, &MainWindow::sigCapture, [&cameras](){cameras.start(); cameras.trigger();});
QTimer temperatureTimer;
temperatureTimer.setSingleShot(false);
QObject::connect(&temperatureTimer, &QTimer::timeout, [&cameras, &w](){w.setTemperature(cameras.getMeanTemp());});
temperatureTimer.start(1000);
QObject::connect(&w, &MainWindow::sigChooseCameras, [&cameras, &w]()
{ {
bool accepted; QObject::connect(&cameras, &Cameras::cameraAdded, &w, &MainWindow::addCamera);
std::vector<cam::Camera::Description> descs = showCameraSelectionDialog(&accepted, &w); QObject::connect(&cameras, &Cameras::cameraRemoved, &w, &MainWindow::removeCamera);
if(accepted) QObject::connect(&cameras, &Cameras::enableCapture, &w, &MainWindow::enableCapture);
cameras.setCameras(descs); QObject::connect(&w, &MainWindow::sigCapture, [&cameras](){cameras.start(); cameras.trigger();});
});
QObject::connect(&w, &MainWindow::sigEditProfiles, [&cameras, &w](){showProfileDialog(&cameras, &w); w.refreshProfiles();}); QTimer temperatureTimer;
QObject::connect(&pipe, &ImagePipeline::sigResult, w.mainImageViewer(), &CvImageViewer::setImage, Qt::QueuedConnection); temperatureTimer.setSingleShot(false);
QObject::connect(&pipe, &ImagePipeline::sigResult, [&w](){w.statusMsg("idle");}); QObject::connect(&temperatureTimer, &QTimer::timeout, [&cameras, &w](){w.setTemperature(cameras.getMeanTemp());});
QObject::connect(&pipe, &ImagePipeline::sigInvalidProfile, &w, &MainWindow::profileInconpatible); temperatureTimer.start(1000);
QObject::connect(&w, &MainWindow::sigProfile, [&pipe](QString name) QObject::connect(&w, &MainWindow::sigChooseCameras, [&cameras, &w]()
{ {
Profile profile; bool accepted;
profile.load(name); std::vector<cam::Camera::Description> descs = showCameraSelectionDialog(&accepted, &w);
if(profile.cameras.size() != 0) if(accepted)
qDebug()<<"loading profile"<<name<<"with"<<profile.cameras.size()<<"cameras and first camera"<<profile.cameras.at(0).id; cameras.setCameras(descs);
else });
qDebug()<<"empty profile!!";
pipe.setProfile(profile);
});
cameras.load(settings); QObject::connect(&w, &MainWindow::sigEditProfiles, [&cameras, &w](){showProfileDialog(&cameras, &w); w.refreshProfiles();});
QObject::connect(&pipe, &ImagePipeline::sigResult, w.mainImageViewer(), &CvImageViewer::setImage, Qt::QueuedConnection);
QObject::connect(&pipe, &ImagePipeline::sigResult, [&w](){w.statusMsg("idle");});
QObject::connect(&pipe, &ImagePipeline::sigInvalidProfile, &w, &MainWindow::profileInconpatible);
QObject::connect(&w, &MainWindow::sigProfile, [&pipe](QString name)
{
Profile profile;
profile.load(name);
if(profile.cameras.size() != 0)
qDebug()<<"loading profile"<<name<<"with"<<profile.cameras.size()<<"cameras and first camera"<<profile.cameras.at(0).id;
else
qDebug()<<"empty profile!!";
pipe.setProfile(profile);
});
cameras.load(settings);
}
splash.hide(); splash.hide();
w.show(); w.show();
@ -184,7 +187,8 @@ int main(int argc, char *argv[])
ret = a.exec(); ret = a.exec();
cameras.store(settings); if(!parser.isSet(viewerOption))
cameras.store(settings);
} }
if(uvosledRet >= 0) if(uvosledRet >= 0)

0
src/regessioncalculator.cpp Executable file → Normal file
View File

0
src/regessioncalculator.h Executable file → Normal file
View File

0
src/ui/aboutdiag.cpp Executable file → Normal file
View File

0
src/ui/aboutdiag.h Executable file → Normal file
View File

0
src/ui/aboutdiag.ui Executable file → Normal file
View File

View File

@ -186,6 +186,7 @@ void CvImageViewer::convertImage(cv::Mat image)
void CvImageViewer::setImage(Camera::Image img) void CvImageViewer::setImage(Camera::Image img)
{ {
origImage_=img.mat; origImage_=img.mat;
clamp_ = std::numeric_limits<double>::max();
qDebug()<<"viwer got"<<image_.rows<<'x'<<image_.cols<<" type "<<image_.type()<<"image from camera"<<img.cameraId; qDebug()<<"viwer got"<<image_.rows<<'x'<<image_.cols<<" type "<<image_.type()<<"image from camera"<<img.cameraId;
convertImage(img.mat); convertImage(img.mat);
update(); update();

0
src/ui/plot.cpp Executable file → Normal file
View File

0
src/ui/plot.h Executable file → Normal file
View File

0
src/ui/regressiondiag.cpp Executable file → Normal file
View File

0
src/ui/regressiondiag.h Executable file → Normal file
View File

0
src/ui/regressiondiag.ui Executable file → Normal file
View File

0
src/ui/statisticsdialog.cpp Executable file → Normal file
View File

0
src/ui/statisticsdialog.h Executable file → Normal file
View File

0
src/ui/statisticsdialog.ui Executable file → Normal file
View File

0
src/utilites.cpp Executable file → Normal file
View File

0
src/utilites.h Executable file → Normal file
View File