mainny ui improcements

This commit is contained in:
2021-06-17 18:39:47 +02:00
parent 50777fe056
commit 86ec50575b
25 changed files with 819 additions and 264 deletions

BIN
res/icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 45 KiB

View File

@ -2,5 +2,6 @@
<qresource prefix="/images">
<file>noimage.png</file>
<file>splash.png</file>
<file>icon.png</file>
</qresource>
</RCC>

View File

@ -6,7 +6,7 @@
Camera::Camera(cam::Camera::Description desc)
{
cameraId_ = desc.getHash();
cameraId_ = desc.getId();
std::function<void(cv::Mat)> cb = [this](cv::Mat image){newImage(Image(image, cameraId_));};
camera_ = new cam::Camera(cb);
camera_->openCamera(desc);

View File

@ -3,6 +3,8 @@
#include <string>
#include <functional>
#include <QDebug>
#include <unistd.h>
#include <QTimer>
Cameras::Cameras(uvosled* led): led_(led)
{
@ -46,7 +48,7 @@ std::shared_ptr<Camera> Cameras::getCamera(size_t id)
std::vector<cam::Camera::Description> desc = getCameras();
for(size_t i = 0; i < desc.size(); ++i)
{
if(desc[i].getHash() == id)
if(desc[i].getId() == id)
return cameras_[i];
}
return std::shared_ptr<Camera>(nullptr);
@ -62,14 +64,35 @@ bool Cameras::addCamera(const cam::Camera::Description& desc)
return false;
}
cameras_.back()->cam()->setTriggerMode(cam::Camera::TRIGGER_SOFTWARE);
cameras_.back()->cam()->setExposureTime(exposrueTime_*1000000);
setFree(false);
cameraAdded(cameras_.back());
qDebug()<<"Using camera"<<cameras_.back()->id();
if(desc.getVendor().find("Photonfocus") != std::string::npos)
{
qDebug()<<"Mitiagting broken PhotonFocus single shot mode";
std::shared_ptr<Camera> camera = cameras_.back();
camera->cam()->setTriggerMode(cam::Camera::TRIGGER_FREE);
camera->cam()->setAcquisitionMode(cam::Camera::MODE_FREE);
camera->cam()->setFrameRate(10);
camera->cam()->startAcquisition();
QTimer::singleShot(2000, [camera, this](){finishAddCamera(camera);});
}
else
{
finishAddCamera(cameras_.back());
}
return true;
}
void Cameras::finishAddCamera(std::shared_ptr<Camera> camera)
{
camera->cam()->setTriggerMode(cam::Camera::TRIGGER_SOFTWARE);
setFree(free_);
connect(camera.get(), &Camera::newImage, this, &Cameras::imageRecived);
qDebug()<<"Using camera"<<camera->id();
cameraAdded(camera);
}
void Cameras::trigger()
{
for(auto& camera : cameras_)
@ -108,6 +131,11 @@ bool Cameras::stop()
return ret;
}
void Cameras::disable(bool disable)
{
disable_ = disable;
}
bool Cameras::setFree(bool free)
{
stop();
@ -117,7 +145,10 @@ bool Cameras::setFree(bool free)
for(auto& camera : cameras_)
{
if(!camera->cam()->setAcquisitionMode(free ? cam::Camera::MODE_FREE : cam::Camera::MODE_SINGLE))
{
qDebug()<<"failed to set single on camera"<<camera->id();
ret = false;
}
}
return ret;
}
@ -130,34 +161,40 @@ bool Cameras::setExposureTime(double exposureTime)
for(auto& camera : cameras_)
{
if(!camera->cam()->setExposureTime(exposrueTime_*1000000))
{
qDebug()<<"failed to set exposure on camera"<<camera->id();
ret = false;
}
}
return ret;
}
void Cameras::imageRecived(Camera::Image img)
{
bool allreadyUpdated = false;
for(auto& camera : cameras_)
if(!disable_)
{
bool allreadyUpdated = false;
for(auto& image : images_)
{
if(image.cameraId == camera->id())
if(image.cameraId == img.cameraId)
{
allreadyUpdated = true;
goto FOUND;
break;;
}
}
if(!allreadyUpdated)
images_.push_back(img);
qDebug()<<"Recived"<<images_.size()<<"of"<<cameras_.size()<<"images";
if(images_.size() == cameras_.size())
{
newImages(images_);
images_.clear();
}
}
FOUND:
if(!allreadyUpdated)
images_.push_back(img);
if(images_.size() == cameras_.size())
newImages(images_);
images_.clear();
}
void Cameras::store(QSettings &settings)
@ -184,7 +221,7 @@ void Cameras::load(QSettings &settings)
size_t hash = settings.value("id", 0).toULongLong();
for(auto& camera : available)
{
if(camera.getHash() == hash)
if(camera.getId() == hash)
addCamera(camera);
}
}

View File

@ -23,6 +23,7 @@ private:
uvosled* led_;
bool free_ = false;
bool disable_ = false;
double exposrueTime_ = 1.0/60.0;
LightingSetup lighting_;
std::vector<std::shared_ptr<Camera>> cameras_;
@ -30,11 +31,12 @@ private:
private slots:
void imageRecived(Camera::Image img);
void finishAddCamera(std::shared_ptr<Camera> camera);
signals:
void cameraRemoved(std::shared_ptr<Camera> camera);
void cameraAdded(std::shared_ptr<Camera> camera);
void newImages(std::vector<Camera::Image> images_);
void newImages(std::vector<Camera::Image> images);
public slots:
@ -55,6 +57,7 @@ public:
Cameras(uvosled* led = nullptr);
void load(QSettings& settings);
void store(QSettings& settings);
void disable(bool disable);
};
#endif // CAMERAS_H

View File

@ -1,37 +1,96 @@
#include "imagepipeline.h"
#include <uvosunwrap/unwrap.h>
#include <uvosunwrap/normalize.h>
#include <uvosunwrap/curve.h>
#include <QtConcurrent/QtConcurrentRun>
#include <QFuture>
#include <QDebug>
ImagePipeline::ImagePipeline(Cameras* cameras, QObject *parent): QObject(parent), cameras_(cameras)
{
connect(cameras_, &Cameras::newImages, this, &ImagePipeline::apply);
}
cv::Mat ImagePipeline::process(const Profile profile, std::vector<Camera::Image> images)
{
qDebug()<<__FUNCTION__<<"got"<<images.size()<<"images";
std::vector<RemapedImage> remapedImages;
remapedImages.reserve(images.size());
for(Camera::Image& image : images)
try
{
for(auto& camera : profile.cameras)
if(profile.nodistort && images.size() > 0)
{
if(camera.id == image.cameraId)
for(auto& image : images)
{
if(camera.darkmap.data)
image.mat = image.mat - camera.darkmap;
remapedImages.push_back(applyRemap(image.mat, camera.remapMap));
break;
if(profile.cameras[0].id == image.cameraId)
{
RemapedImage img;
img.origin.x = 0;
img.origin.y = 0;
image.mat.copyTo(img.image);
if(profile.cameras[0].darkmap.data)
img.image = img.image - profile.cameras[0].darkmap;
remapedImages.push_back(img);
break;
}
}
}
else
{
for(Camera::Image& image : images)
{
qDebug()<<__FUNCTION__<<"image cam id"<<image.cameraId;
bool matched = false;
for(auto& camera : profile.cameras)
{
if(camera.id == image.cameraId)
{
if(camera.darkmap.data)
{
cv::Mat subtracted;
image.mat.copyTo(subtracted);
qDebug()<<"Camera"<<camera.id<<"has darkmap"<<image.mat.type()<<camera.darkmap.type();
subtracted = image.mat - camera.darkmap;
image.mat = subtracted;
}
RemapedImage remaped = applyRemap(image.mat, camera.remapMap);
qDebug()<<"Camera"<<camera.id<<"image remaped to"<<remaped.image.data<<remaped.image.rows<<remaped.image.cols
<<"at"<<remaped.origin.x<<'x'<<remaped.origin.y;
remapedImages.push_back(applyRemap(image.mat, camera.remapMap));
matched = true;
break;
}
}
if(!matched)
qWarning()<<"non matching image recived";
}
}
}
catch(cv::Exception ex)
{
qDebug()<<ex.err.c_str();
qDebug()<<"Image pipe failure";
return cv::Mat();
}
cv::Mat output = simpleStich(remapedImages);
output.convertTo(output, CV_32FC1, 1.0/255.0, 0);
if(remapedImages.size() > 0)
{
cv::Mat output = simpleStich(remapedImages);
output.convertTo(output, CV_32FC1, 1.0/255.0, 0);
if(profile.lightmap.data)
normalize(output, profile.lightmap);
return output;
if(profile.lightmap.data)
normalize(output, profile.lightmap);
if(profile.calcurve.data)
applyCurve(output, profile.calcurve);
return output;
}
else
{
qDebug()<<"Image pipe failure insufficant matched images";
return cv::Mat();
}
}
void ImagePipeline::apply(std::vector<Camera::Image> images)
@ -41,6 +100,7 @@ void ImagePipeline::apply(std::vector<Camera::Image> images)
futureImageWatchers_.push_back(new QFutureWatcher<cv::Mat>());
connect(futureImageWatchers_.back(), &QFutureWatcher<cv::Mat>::finished, this, &ImagePipeline::imageFinished);
statusMsg("Processing");
QFuture<cv::Mat> futureImage = QtConcurrent::run(&ImagePipeline::process, profile_, images);
futureImageWatchers_.back()->setFuture(futureImage);
}
@ -51,11 +111,20 @@ void ImagePipeline::setProfile(const Profile& profile)
profile_ = profile;
cameras_->setExposureTime(profile_.exposureTime);
cameras_->setLighting(profile_.lighting);
qDebug()<<"setting profile "<<profile_.getName();
for(CameraSetup& setup : profile_.cameras)
{
qDebug()<<setup.id;
//TODO: dehardcode this
setup.remapMap.outputCellSize=200;
}
invalid_ = false;
if(!profile_.camerasSufficant(cameras_->getCameras()))
{
invalid_ = true;
sigInvalidProfile("A camera required for this profile is not available");
}
statusMsg("set profile " + profile_.getName());
}
void ImagePipeline::imageFinished()
@ -65,11 +134,18 @@ void ImagePipeline::imageFinished()
if(futureImageWatchers_[i]->isFinished())
{
cv::Mat result = futureImageWatchers_[i]->result();
sigResult(Camera::Image(result, 0));
delete futureImageWatchers_[i];
futureImageWatchers_.erase(futureImageWatchers_.begin()+i);
i--;
if(result.data)
{
sigResult(Camera::Image(result, 0));
delete futureImageWatchers_[i];
futureImageWatchers_.erase(futureImageWatchers_.begin()+i);
i--;
statusMsg("Finished");
}
else
{
sigInvalidProfile("Image pipe failure");
}
}
}
}

View File

@ -30,6 +30,7 @@ private slots:
signals:
void sigInvalidProfile(QString message);
void sigResult(Camera::Image image);
void statusMsg(QString msg);
public slots:
void setProfile(const Profile& profile);

View File

@ -9,6 +9,7 @@
#include <QThread>
#include <opencv2/core/mat.hpp>
#include <unistd.h>
#include <uvosunwrap/log.h>
#include "cameras.h"
#include "./ui/cameradialog.h"
@ -17,6 +18,7 @@
#include "./ui/profiledialog.h"
#include "imagepipeline.h"
const char* organziation = "UVOS";
const char* application = "UVOS";
const char* version = "UVOS";
@ -44,13 +46,18 @@ void showProfileDialog(Cameras* cameras)
{
qDebug()<<__FUNCTION__;
cameras->stop();
cameras->disable(true);
std::vector<cam::Camera::Description> descs = cameras->getCameras();
ProfileDialog diag(cameras);
diag.show();
diag.exec();
cameras->disable(false);
}
int main(int argc, char *argv[])
{
Log::level = Log::WARN;
QApplication a(argc, argv);
QCoreApplication::setOrganizationName("UVOS");
QCoreApplication::setOrganizationDomain("uvos.xyz");
@ -61,11 +68,12 @@ int main(int argc, char *argv[])
splash.show();
QDir().mkpath(Profile::profileLocation());
QDir().mkpath(CameraSetup::camerasLocation());
qRegisterMetaType<cv::Mat>("cv::Mat");
qRegisterMetaType<size_t>("size_t");
qRegisterMetaType<Camera::Image>("Camera::Image");
qRegisterMetaType<Camera::Image>("Image");
qRegisterMetaType<std::vector<Camera::Image>>("std::vector<Camera::Image>");
QSettings settings(QSettings::IniFormat, QSettings::UserScope, QCoreApplication::organizationName(), QCoreApplication::applicationName());
@ -100,11 +108,16 @@ int main(int argc, char *argv[])
QObject::connect(&w, &MainWindow::sigEditProfiles, [&cameras, &w](){showProfileDialog(&cameras); w.refreshProfiles();});
QObject::connect(&pipe, &ImagePipeline::sigResult, w.mainImageViewer(), &CvImageViewer::setImage, Qt::QueuedConnection);
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);
});
@ -122,7 +135,17 @@ int main(int argc, char *argv[])
cameras.setCameras(showCameraSelectionDialog());
}
pipe.setProfile(w.getProfileName());
QString name = w.getProfileName();
if(!name.isEmpty())
{
Profile profile;
profile.load(w.getProfileName());
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);
}
int ret = a.exec();

View File

@ -6,63 +6,41 @@
#include <QDebug>
#include <uvosunwrap/unwrap.h>
void CameraSetup::store() const
void CameraSetup::store(const QString &filename) const
{
if(darkmap.data)
cv::imwrite(darkmapLocation(id).toStdString(), darkmap);
cv::FileStorage matf(filename.toStdString(), cv::FileStorage::APPEND);
if(remapMap.xMat.data)
saveRemapMap(remapMap, remapMapLocation(id).toStdString());
{
matf<<("_"+QString::number(id)+"_xmat").toStdString()<<remapMap.xMat<<("_"+QString::number(id)+"_ymat").toStdString()
<<remapMap.yMat<<("_"+QString::number(id)+"_origin").toStdString()<<remapMap.topLeftCoordinate;
}
if(darkmap.data)
{
matf<<("_"+QString::number(id)+"_darkmap").toStdString()<<darkmap;
}
if(bgmask.data)
{
cv::FileStorage matf(bgmaskLocation(id).toStdString(), cv::FileStorage::WRITE);
matf<<"bgmask"<<bgmask;
matf.release();
matf<<("_"+QString::number(id)+"_bgmask").toStdString()<<bgmask;
}
}
void CameraSetup::loadDarkMap(const QString &filename)
{
darkmap = cv::imread(filename.toStdString());
}
void CameraSetup::loadBgMask(const QString &filename)
{
cv::FileStorage matf(filename.toStdString(), cv::FileStorage::READ);
matf["bgmask"]>>bgmask;
matf.release();
}
void CameraSetup::loadRemapMaps(const QString &filename)
{
remapMap = loadRemapMap(filename.toStdString());
}
void CameraSetup::load(size_t cameraId)
void CameraSetup::load(const QString &filename, size_t cameraId)
{
id = cameraId;
loadDarkMap(darkmapLocation(id));
loadRemapMaps(remapMapLocation(id));
loadBgMask(bgmaskLocation(id));
}
QString CameraSetup::camerasLocation()
{
return QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + "/cameras/";
}
QString CameraSetup::darkmapLocation(size_t cameraId)
{
return camerasLocation() + QString::number(cameraId) + ".darkmap.png";
}
QString CameraSetup::bgmaskLocation(size_t cameraId)
{
return camerasLocation() + QString::number(cameraId) + "bgmask.mat";
}
QString CameraSetup::remapMapLocation(size_t cameraId)
{
return camerasLocation() + QString::number(cameraId) + "remap.mat";
cv::FileStorage matf(filename.toStdString(), cv::FileStorage::READ);
if (matf.isOpened())
{
matf[("_"+QString::number(id)+"_darkmap").toStdString()]>>darkmap;
matf[("_"+QString::number(id)+"_bgmask").toStdString()]>>bgmask;
matf[("_"+QString::number(id)+"_xmat").toStdString()]>>remapMap.xMat;
matf[("_"+QString::number(id)+"_ymat").toStdString()]>>remapMap.yMat;
matf[("_"+QString::number(id)+"_origin").toStdString()]>>remapMap.topLeftCoordinate;
}
else
{
qDebug()<<"could not open file"<<filename;
}
}
void LightingSetup::store(QSettings& settings) const
@ -84,6 +62,7 @@ void Profile::store(QSettings& settings) const
settings.setValue(GROUP + QString("/id"), static_cast<unsigned long long>(id));
settings.setValue(GROUP + QString("/exposureTime"), exposureTime);
settings.setValue(GROUP + QString("/name"), name_);
settings.setValue(GROUP + QString("/nodistort"), nodistort);
if(lightmap.data)
cv::imwrite((profileLocation() + QString::number(id) + ".lightmap.png").toStdString(), lightmap);
@ -93,10 +72,18 @@ void Profile::store(QSettings& settings) const
{
const CameraSetup& camera = cameras[i];
settings.setArrayIndex(i);
camera.store();
camera.store(profileLocation() + name_ + ".profile.mat");
settings.setValue("id", static_cast<unsigned long long>(camera.id));
}
settings.endArray();
cv::FileStorage matf((profileLocation() + name_ + ".calcurve.mat").toStdString(), cv::FileStorage::WRITE);
matf<<"cal"<<calcurve;
matf.release();
cv::FileStorage matfl((profileLocation() + name_ + ".lightmap.mat").toStdString(), cv::FileStorage::WRITE);
matfl<<"cal"<<lightmap;
matfl.release();
}
void Profile::load(QSettings &settings)
@ -105,6 +92,7 @@ void Profile::load(QSettings &settings)
id = settings.value(GROUP + QString("/id")).toULongLong();
exposureTime = settings.value(GROUP + QString("/exposureTime"), 1.0/60.0).toDouble();
name_ = settings.value(GROUP + QString("/name"), "NULL").toString();
nodistort = settings.value(GROUP + QString("/nodistort"), "NULL").toBool();
lightmap = cv::imread((profileLocation() + QString::number(id) + ".lightmap.png").toStdString());
@ -113,9 +101,20 @@ void Profile::load(QSettings &settings)
{
settings.setArrayIndex(i);
cameras.push_back(CameraSetup());
cameras.back().load(settings.value("id", 0).toULongLong());
cameras.back().load(profileLocation() + name_ + ".profile.mat", settings.value("id", 0).toULongLong());
}
settings.endArray();
cv::FileStorage matf((profileLocation() + name_ + ".calcurve.mat").toStdString(), cv::FileStorage::READ);
matf["cal"]>>calcurve;
matf.release();
if(calcurve.data && (calcurve.type() != CV_32FC1 || calcurve.rows != 2))
calcurve.release();
cv::FileStorage matfl((profileLocation() + name_ + ".lightmap.mat").toStdString(), cv::FileStorage::READ);
matfl["cal"]>>lightmap;
matfl.release();
}
void Profile::load(const QString& name)
@ -164,15 +163,43 @@ QList<QString> Profile::avaiableProfiles()
return ret;
}
void Profile::setCamerasSetupsFromDescription(const std::vector<cam::Camera::Description>& desc)
void Profile::setCamerasSetupsFromDescription(const std::vector<cam::Camera::Description>& descs)
{
cameras.clear();
cameras.reserve(desc.size());
for(size_t i = 0; i < desc.size(); ++i)
for(size_t i = 0; i < cameras.size(); ++i)
{
CameraSetup tmp;
tmp.load(desc[i].getHash());
cameras.push_back(tmp);
bool found = false;
for(auto& cameraDesc : descs)
{
if(cameras[i].id == cameraDesc.getId())
{
found = true;
break;
}
}
if(!found)
{
cameras.erase(cameras.begin()+i);
--i;
}
}
for(size_t i = 0; i < descs.size(); ++i)
{
bool found = false;
for(auto& camera : cameras)
{
if(camera.id == descs[i].getId())
{
found = true;
break;
}
}
if(!found)
{
CameraSetup tmp;
tmp.load(profileLocation() + name_ + ".profile.mat", descs[i].getId());
cameras.push_back(tmp);
}
}
}
@ -184,7 +211,7 @@ bool Profile::camerasSufficant(const std::vector<cam::Camera::Description>& desc
bool found = false;
for(auto& camera : desc)
{
if(camera.getHash() == cameraProfile.id)
if(camera.getId() == cameraProfile.id)
{
found = true;
break;

View File

@ -16,15 +16,8 @@ public:
RemapMap remapMap;
cv::Mat darkmap;
cv::Mat bgmask;
void store() const;
void load(size_t cameraId);
void loadBgMask(const QString& filename);
void loadDarkMap(const QString& filename);
void loadRemapMaps(const QString& filename);
static QString camerasLocation();
static QString remapMapLocation(size_t cameraId);
static QString bgmaskLocation(size_t cameraId);
static QString darkmapLocation(size_t cameraId);
void store(const QString& filename) const;
void load(const QString& name, size_t cameraId);
};
class LightingSetup
@ -50,7 +43,9 @@ public:
LightingSetup lighting;
double exposureTime = 1.0/60.0;
cv::Mat lightmap;
cv::Mat calcurve;
std::vector<CameraSetup> cameras;
bool nodistort = false;
Profile(const QString& name = "Unamed");
void store(QSettings& settings) const;

View File

@ -16,6 +16,10 @@
<property name="windowTitle">
<string>Select Cameras</string>
</property>
<property name="windowIcon">
<iconset resource="../../res/resources.qrc">
<normaloff>:/images/icon.png</normaloff>:/images/icon.png</iconset>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="label">
@ -46,7 +50,9 @@
<header location="global">./src/ui/cameralistwidget.h</header>
</customwidget>
</customwidgets>
<resources/>
<resources>
<include location="../../res/resources.qrc"/>
</resources>
<connections>
<connection>
<sender>buttonBox</sender>

View File

@ -20,7 +20,7 @@ void CameraListWidget::setConfigured(std::vector<bool> configured)
setHorizontalHeaderItem(1, new QTableWidgetItem("Configured"));
for(size_t i = 0; i < desc_.size() && i < configured.size(); ++i)
{
setItem(static_cast<int>(i), 1, new QTableWidgetItem("No"));
setItem(static_cast<int>(i), 1, new QTableWidgetItem(configured[i] ? "Yes" : "No"));
qDebug()<<"Set item "<<i<<1;
}
}
@ -32,7 +32,7 @@ void CameraListWidget::setCameras(const std::vector<cam::Camera::Description>& d
setRowCount(static_cast<int>(desc_.size()));
for(size_t i = 0; i < desc_.size(); ++i)
{
setItem(static_cast<int>(i), 0, new QTableWidgetItem((desc_[i].vendor + " " + desc_[i].model).c_str()));
setItem(static_cast<int>(i), 0, new QTableWidgetItem((desc_[i].getVendor() + " " + desc_[i].getModel()).c_str()));
}
}

View File

@ -7,20 +7,26 @@
#include <uvosunwrap/charuco.h>
#include <uvosunwrap/unwrap.h>
#include <opencv2/imgproc.hpp>
#include <QDebug>
ConfigureCameraDialog::ConfigureCameraDialog(const CameraSetup& setup, std::shared_ptr<Camera> camera, double exposureTime, QWidget *parent):
QDialog(parent),
setup_(setup),
camera_(camera),
profileExposure_(exposureTime),
ui(new Ui::ConfigureCameraDialog)
{
ui->setupUi(this);
qDebug()<<"profileExposure_"<<profileExposure_;
ui->doubleSpinBox->setValue(profileExposure_);
setExposure(profileExposure_);
ui->doubleSpinBox->setValue(exposureTime);
uint64_t min, max;
camera_->cam()->getExposureTimeLimits(min, max);
ui->doubleSpinBox->setMaximum(max/1000000.0);
ui->doubleSpinBox->setMinimum(min/1000000.0);
connect(ui->pushButtonBgLoad, &QPushButton::clicked, this, &ConfigureCameraDialog::loadBg);
connect(ui->pushButtonRemapLoad, &QPushButton::clicked, this, &ConfigureCameraDialog::loadRemap);
connect(ui->pushButtonDarkImageLoad, &QPushButton::clicked, this, &ConfigureCameraDialog::loadDark);
connect(ui->doubleSpinBox, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, &ConfigureCameraDialog::setExposure);
connect(ui->pushButtonBgClear, &QPushButton::clicked, [this](){setup_.bgmask.release(); checkConfig();});
connect(ui->pushButtonRemapClear, &QPushButton::clicked, [this](){setup_.remapMap = RemapMap(); checkConfig();});
connect(ui->pushButtonDarkImageClear, &QPushButton::clicked, [this](){setup_.darkmap.release(); checkConfig();});
@ -38,45 +44,12 @@ ConfigureCameraDialog::~ConfigureCameraDialog()
delete ui;
}
void ConfigureCameraDialog::loadBg()
void ConfigureCameraDialog::setExposure(double value)
{
QString filename = QFileDialog::getOpenFileName(this, tr("Open Background Mask"), CameraSetup::camerasLocation(), "OpenCV Mat (*.mat)");
if(!filename.isEmpty())
{
setup_.loadBgMask(filename);
if(!setup_.bgmask.data)
QMessageBox::warning(this, "Warning", "Could not load " + filename);
checkConfig();
}
}
void ConfigureCameraDialog::loadRemap()
{
QString filename = QFileDialog::getOpenFileName(this, tr("Open Background Mask"), CameraSetup::camerasLocation(), "OpenCV Mat (*.mat)");
if(!filename.isEmpty())
{
setup_.loadRemapMaps(filename);
if(!setup_.remapMap.xMat.data || !setup_.remapMap.yMat.data)
{
QMessageBox::warning(this, "Warning", "Could not load " + filename);
setup_.remapMap = RemapMap();
}
checkConfig();
}
}
void ConfigureCameraDialog::loadDark()
{
QString filename = QFileDialog::getOpenFileName(this, tr("Open Background Mask"), CameraSetup::camerasLocation(), "Image (*.png)");
if(!filename.isEmpty())
{
setup_.loadDarkMap(filename);
if(!setup_.darkmap.data)
QMessageBox::warning(this, "Warning", "Could not load " + filename);
checkConfig();
}
if(!camera_->cam()->setExposureTime(value*1000000.0))
QMessageBox::warning(this, "Warning", "Failed to set exposure");
else
qDebug()<<"set exposure to "<<value*1000000.0;
}
void ConfigureCameraDialog::gotImage(Camera::Image img)
@ -109,6 +82,11 @@ void ConfigureCameraDialog::gotImage(Camera::Image img)
mode_ = MODE_IDLE;
break;
case MODE_REMAP_GET:
cv::Mat masked;
if(setup_.bgmask.data)
img.mat.copyTo(masked, setup_.bgmask);
else
masked = img.mat;
std::vector<DetectedPoint> points = detectCharucoPoints(img.mat, false);
if(points.size() < 8)
{
@ -117,13 +95,13 @@ void ConfigureCameraDialog::gotImage(Camera::Image img)
break;
}
RemapMap map;
if(createRemapMap(img.mat, map, points))
if(createRemapMap(masked, map, points))
setup_.remapMap = map;
else
QMessageBox::warning(this, "Failed", "Error creating map");
for(size_t i = 0; i < points.size(); ++i)
cv::circle(img.mat, points[i].point, 5, cv::Scalar(0,255,0), 1);
ui->widget_4->setImage(Camera::Image(setup_.bgmask, camera_->id()));
cv::circle(img.mat, points[i].point, img.mat.cols/50, cv::Scalar(255,255,255), img.mat.cols/200);
ui->widget_4->setImage(Camera::Image(img.mat, camera_->id()));
mode_ = MODE_IDLE;
break;
}
@ -157,6 +135,8 @@ void ConfigureCameraDialog::captureDark()
{
QMessageBox::information(this, "Cover lense", "Please cover the lense of the camera.");
mode_ = MODE_DARK_GET;
ui->doubleSpinBox->setValue(profileExposure_);
setExposure(profileExposure_);
takeImage();
}
@ -165,7 +145,7 @@ void ConfigureCameraDialog::accept()
if(checkConfig())
QDialog::accept();
else
QMessageBox::warning(this, "Unfinished", "Can not accept unfinished camera setup");
QMessageBox::information(this, "Unfinished", "Can not accept unfinished camera setup");
}
bool ConfigureCameraDialog::checkConfig()
@ -182,5 +162,5 @@ bool ConfigureCameraDialog::checkConfig()
ui->ledDark->setLit(darkMapOK);
ui->ledRemap->setLit(remapMapOk);
return bgOk && remapMapOk && darkMapOK;
return remapMapOk;
}

View File

@ -22,25 +22,27 @@ class ConfigureCameraDialog : public QDialog
std::shared_ptr<Camera> camera_;
int mode_ = MODE_IDLE;
cv::Mat fgImage;
double profileExposure_;
private:
bool checkConfig();
void gotImage(Camera::Image img);
private slots:
void loadBg();
void loadRemap();
void loadDark();
void captureBg();
void captureRemap();
void captureDark();
void takeImage();
void setExposure(double value);
public slots:
void accept() override;
public:
explicit ConfigureCameraDialog(const CameraSetup& setup, const std::shared_ptr<Camera> camera, double exposureTime = 1.0/60, QWidget *parent = nullptr);
~ConfigureCameraDialog();
CameraSetup getCameraSetup(){return setup_;}
void accept() override;
private:
Ui::ConfigureCameraDialog *ui;

View File

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>466</width>
<height>438</height>
<width>545</width>
<height>614</height>
</rect>
</property>
<property name="windowTitle">
@ -31,6 +31,29 @@
<property name="horizontalSpacing">
<number>6</number>
</property>
<item row="3" column="1">
<widget class="Led" name="ledBg" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>40</width>
<height>40</height>
</size>
</property>
</widget>
</item>
<item row="3" column="3">
<widget class="QPushButton" name="pushButtonBgCreate">
<property name="text">
<string>Create</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label">
<property name="text">
@ -48,13 +71,6 @@
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Background image</string>
</property>
</widget>
</item>
<item row="2" column="3">
<widget class="QPushButton" name="pushButtonDarkImageCreate">
<property name="text">
@ -62,32 +78,6 @@
</property>
</widget>
</item>
<item row="3" column="4">
<widget class="QPushButton" name="pushButtonBgClear">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Clear</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="Led" name="ledRemap" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</widget>
</item>
<item row="1" column="4">
<widget class="QPushButton" name="pushButtonRemapClear">
<property name="enabled">
@ -98,57 +88,40 @@
</property>
</widget>
</item>
<item row="3" column="3">
<widget class="QPushButton" name="pushButtonBgCreate">
<item row="3" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Create</string>
<string>Background image</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="Led" name="ledBg" native="true"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<item row="2" column="2">
<widget class="QPushButton" name="pushButtonDarkImageShow">
<property name="text">
<string>Remap Map</string>
<string>Show</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QPushButton" name="pushButtonRemapLoad">
<property name="text">
<string>Load</string>
</property>
</widget>
</item>
<item row="3" column="2">
<widget class="QPushButton" name="pushButtonBgLoad">
<property name="text">
<string>Load</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="Led" name="ledDark" native="true">
<item row="1" column="1">
<widget class="Led" name="ledRemap" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
<width>40</width>
<height>40</height>
</size>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QPushButton" name="pushButtonDarkImageLoad">
<item row="3" column="2">
<widget class="QPushButton" name="pushButtonBgShow">
<property name="text">
<string>Load</string>
<string>Show</string>
</property>
</widget>
</item>
@ -159,10 +132,36 @@
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_4">
<item row="2" column="1">
<widget class="Led" name="ledDark" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>40</width>
<height>40</height>
</size>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string/>
<string>Remap Map (required)</string>
</property>
</widget>
</item>
<item row="3" column="4">
<widget class="QPushButton" name="pushButtonBgClear">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Clear</string>
</property>
</widget>
</item>
@ -182,11 +181,14 @@
</item>
<item>
<widget class="QDoubleSpinBox" name="doubleSpinBox">
<property name="decimals">
<number>5</number>
</property>
<property name="maximum">
<double>1.000000000000000</double>
</property>
<property name="singleStep">
<double>0.100000000000000</double>
<double>0.001000000000000</double>
</property>
</widget>
</item>
@ -219,18 +221,18 @@
</layout>
</widget>
<customwidgets>
<customwidget>
<class>Led</class>
<extends>QWidget</extends>
<header location="global">./src/ui/led.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>CvImageViewer</class>
<extends>QWidget</extends>
<header location="global">./src/ui/cvimageviewer.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>Led</class>
<extends>QWidget</extends>
<header location="global">./src/ui/led.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections>

View File

@ -1,21 +1,60 @@
#include "cvimageviewer.h"
#include <QPicture>
#include <QDebug>
#include <QMouseEvent>
#include <QFileDialog>
#include <opencv2/imgcodecs.hpp>
CvImageViewer::CvImageViewer(QWidget *parent, size_t lastId) :
QWidget(parent),
lastId_(lastId)
lastId_(lastId),
saveAction_("Save Image", nullptr)
{
connect(&saveAction_, &QAction::triggered, this, &CvImageViewer::saveImage);
qimage_.load(":/images/noimage.png");
imageContextMenu_.addAction(&saveAction_);
}
CvImageViewer::~CvImageViewer()
{
}
void CvImageViewer::saveImage()
{
QString fileName;
if(origImage_.type() == CV_8UC3 || origImage_.type() == CV_8SC3 || origImage_.type() == CV_8UC1 || origImage_.type() == CV_8SC1)
{
fileName = QFileDialog::getSaveFileName(this, "Save Image", "./", "*.mat *.png" );
}
else
{
fileName = QFileDialog::getSaveFileName(this, "Save Image", "./", "*.mat" );
}
if(!fileName.isEmpty())
{
QStringList tokens = fileName.split('.');
if(tokens.back() != "mat" && tokens.back() != "png")
fileName.append(".mat");
tokens = fileName.split('.');
if(tokens.back() == "png")
{
imwrite(fileName.toStdString(), origImage_);
}
else
{
cv::FileStorage matf(fileName.toStdString(), cv::FileStorage::WRITE);
matf<<"image"<<origImage_;
matf.release();
}
}
}
void CvImageViewer::setImage(Camera::Image img)
{
image_ = img.mat;
origImage_=img.mat;
qDebug()<<"viwer got"<<image_.rows<<'x'<<image_.cols<<" type "<<image_.type()<<"image from camera"<<img.cameraId;
if(image_.type() == CV_8UC3 || image_.type() == CV_8SC3)
{
qimage_ = QImage(image_.data, image_.cols, image_.rows, image_.step, QImage::Format_RGB888);
@ -37,19 +76,41 @@ void CvImageViewer::setImage(Camera::Image img)
update();
}
void CvImageViewer::mousePressEvent(QMouseEvent *event)
{
if(event->button() == Qt::RightButton)
{
saveAction_.setEnabled(origImage_.data);
imageContextMenu_.popup(event->globalPos());
}
else if(origImage_.data && event->x() > imgrect_.x() && event->y() > imgrect_.y() && event->x() < imgrect_.x()+imgrect_.width() && event->y() < imgrect_.y()+imgrect_.height())
{
int x = (event->x()-imgrect_.x())/static_cast<double>(imgrect_.width())*origImage_.cols;
int y = (event->y()-imgrect_.y())/static_cast<double>(imgrect_.height())*origImage_.rows;
qDebug()<<x<<y;
if(origImage_.type() == CV_32FC1)
{
if(x >= 0 && y >= 0 && x <= origImage_.cols && y < origImage_.rows)
sigValue(x, y, origImage_.at<float>(y,x));
}
else
{
sigValue(x, y, 0);
}
}
QWidget::mousePressEvent(event);
}
void CvImageViewer::paintEvent(QPaintEvent* event)
{
Q_UNUSED(event)
QPainter painter(this);
if(!fixedOnWidth_)
{
double ratio = qimage_.size().width() / qimage_.size().height();
painter.drawImage(QRect((rect().width()-rect().height())/2, rect().y(), rect().height()*ratio, rect().height()), qimage_);
}
double ratio = qimage_.size().height() / (double)qimage_.size().width();
if(rect().width()*ratio <= rect().height())
imgrect_.setRect(0, (rect().height()-rect().width()*ratio)/2, rect().width(), rect().width()*ratio);
else
{
double ratio = qimage_.size().height() / qimage_.size().width();
painter.drawImage(QRect(rect().x(), (rect().height()-rect().width())/2, rect().width(), rect().width()*ratio), qimage_);
}
imgrect_.setRect((rect().width()-rect().height()/ratio)/2, 0, rect().height()/ratio, rect().height());
painter.drawImage(imgrect_, qimage_);
}

View File

@ -3,19 +3,32 @@
#include <QWidget>
#include <QPainter>
#include <QMenu>
#include "../cameras.h"
class CvImageViewer : public QWidget
{
Q_OBJECT
private:
cv::Mat origImage_;
cv::Mat image_;
QImage qimage_;
bool fixedOnWidth_ = false;
size_t lastId_;
QMenu imageContextMenu_;
QAction saveAction_;
QRect imgrect_;
private slots:
void saveImage();
protected:
virtual void paintEvent(QPaintEvent* event) override;
virtual void mousePressEvent(QMouseEvent *event) override;
signals:
void sigValue(size_t x, size_t y, double value);
public slots:
void setImage(Camera::Image img);
@ -23,6 +36,8 @@ public slots:
public:
explicit CvImageViewer(QWidget *parent = nullptr, size_t lastId = 0);
void setFixedOnWidth(bool in){fixedOnWidth_ = in;}
cv::Mat getImage(){return origImage_;}
size_t lastId(){return lastId_;}
~CvImageViewer();
};

View File

@ -2,6 +2,8 @@
#include "ui_editprofiledialog.h"
#include <uvosled.h>
#include <QDebug>
#include <QMessageBox>
#include <QFileDialog>
#include "configurecameradialog.h"
@ -24,26 +26,91 @@ EditProfileDialog::EditProfileDialog(Cameras* cameras, const Profile profile, QW
ui->checkBoxCh3->setChecked(profile_.lighting.mask & CHANNEL_C);
ui->checkBoxCh4->setChecked(profile_.lighting.mask & CHANNEL_D);
if(profile_.cameras.size() == 0)
profile_.setCamerasSetupsFromDescription(cameras_->getCameras());
ui->checkBoxNodistort->setChecked(profile_.nodistort);
std::vector<cam::Camera::Description> descs = cameras_->getCameras();
profile_.setCamerasSetupsFromDescription(descs);
if(profile_.cameras.size() > 0)
{
uint64_t min, max;
std::shared_ptr<Camera> cam = cameras_->getCamera(profile_.cameras[0].id);
if(cam)
{
cam->cam()->getExposureTimeLimits(min, max);
ui->doubleSpinBoxExposure->setMaximum(max/1000000.0);
ui->doubleSpinBoxExposure->setMinimum(min/1000000.0);
}
}
ui->calLed->setLit(profile_.calcurve.data);
connect(ui->doubleSpinBoxBrightness, QOverload<double>::of(&QDoubleSpinBox::valueChanged), [this](double in){profile_.lighting.brightness = in/100.0;});
connect(ui->doubleSpinBoxExposure, QOverload<double>::of(&QDoubleSpinBox::valueChanged), [this](double in){profile_.exposureTime = in;});
connect(ui->doubleSpinBoxExposure, QOverload<double>::of(&QDoubleSpinBox::valueChanged), [this](double in){profile_.exposureTime = in; invalidateCameras();});
connect(ui->lineEditName, &QLineEdit::textChanged, [this](QString in){profile_.setName(in);});
connect(ui->checkBoxCh1, &QCheckBox::clicked, this, &EditProfileDialog::setMask);
connect(ui->checkBoxCh2, &QCheckBox::clicked, this, &EditProfileDialog::setMask);
connect(ui->checkBoxCh3, &QCheckBox::clicked, this, &EditProfileDialog::setMask);
connect(ui->checkBoxCh4, &QCheckBox::clicked, this, &EditProfileDialog::setMask);
connect(ui->pushButton, &QPushButton::clicked, this, &EditProfileDialog::configureCamera);
connect(ui->checkBoxNodistort, &QCheckBox::stateChanged, [this](int state){profile_.nodistort = state == Qt::Checked ?: false; setConfigured();});
connect(ui->pushButtonCalLoad, &QPushButton::clicked, this, &EditProfileDialog::loadCalcurve);
connect(ui->pushButtonLightmapLoad, &QPushButton::clicked, this, &EditProfileDialog::loadCalcurve);
ui->listView->setCameras(cameras_->getCameras());
ui->listView->setSelectionMode(QAbstractItemView::SingleSelection);
setConfigured();
}
void EditProfileDialog::setConfigured()
void EditProfileDialog::loadLightmap()
{
QString fileName = QFileDialog::getOpenFileName(this, "Open Lightmap", "./", "*.mat");
if(!fileName.isEmpty())
{
profile_.calcurve.release();
cv::FileStorage matf(fileName.toStdString(), cv::FileStorage::READ);
matf["image"]>>profile_.lightmap;
if(matf.isOpened() && (!profile_.calcurve.data || profile_.calcurve.type() != CV_32FC1))
{
profile_.lightmap.release();
QMessageBox::warning(this, "Invalid file", "File selected dose not contain a valid lightmap");
}
else if(!profile_.calcurve.data)
{
QMessageBox::warning(this, "Can no open", "Can not open file selected");
}
matf.release();
ui->ledLightmap->setLit(profile_.lightmap.data);
}
}
void EditProfileDialog::loadCalcurve()
{
QString fileName = QFileDialog::getOpenFileName(this, "Open Cal Curve", "./", "*.mat");
if(!fileName.isEmpty())
{
profile_.calcurve.release();
cv::FileStorage matf(fileName.toStdString(), cv::FileStorage::READ);
matf["cal"]>>profile_.calcurve;
if(matf.isOpened() && (!profile_.calcurve.data || profile_.calcurve.type() != CV_32FC1 || profile_.calcurve.rows != 2))
{
profile_.calcurve.release();
QMessageBox::warning(this, "Invalid file", "File selected dose not contain a valid cal curve");
}
else if(!profile_.calcurve.data)
{
QMessageBox::warning(this, "Can no open", "Can not open file selected");
}
matf.release();
ui->calLed->setLit(profile_.calcurve.data);
}
}
bool EditProfileDialog::setConfigured()
{
std::vector<cam::Camera::Description> descs = cameras_->getCameras();
std::vector<bool> configured(descs.size(), false);
std::vector<bool> configured(descs.size(), profile_.nodistort);
for(size_t i = 0; i< profile_.cameras.size(); ++i)
{
@ -52,12 +119,19 @@ void EditProfileDialog::setConfigured()
{
for(auto& camera : descs)
{
if(camera.getHash() == profileCamera.id)
if(camera.getId() == profileCamera.id)
configured[i] = true;
}
}
}
ui->listView->setConfigured(configured);
bool fullyConfigured = true;
for(bool config : configured)
{
if(!config)
fullyConfigured = false;
}
return fullyConfigured;
}
void EditProfileDialog::invalidateCameras()
@ -78,10 +152,12 @@ void EditProfileDialog::configureCamera()
qDebug()<<"descs"<<descs.size();
if(!descs.empty())
{
qDebug()<<"want to edit id"<<descs[0].getId();
size_t i = 0;
for(; i < profile_.cameras.size(); ++i)
{
if(profile_.cameras[i].id == descs[0].getHash())
qDebug()<<"test"<<profile_.cameras[i].id ;
if(profile_.cameras[i].id == descs[0].getId())
{
std::shared_ptr<Camera> camera = cameras_->getCamera(profile_.cameras[i].id);
if(camera)
@ -94,9 +170,18 @@ void EditProfileDialog::configureCamera()
}
}
}
setConfigured();
}
}
void EditProfileDialog::accept()
{
if(!setConfigured())
QMessageBox::information(this, "Unfinished", "Can not accept with unconfigured cameras");
else
QDialog::accept();
}
void EditProfileDialog::setMask()
{
uint8_t mask = (ui->checkBoxCh1->isChecked() ? CHANNEL_A : 0) |

View File

@ -15,13 +15,17 @@ class EditProfileDialog : public QDialog
Profile profile_;
Cameras* cameras_;
void setConfigured();
bool setConfigured();
void invalidateCameras();
private slots:
void setMask();
void configureCamera();
void loadCalcurve();
void loadLightmap();
public slots:
virtual void accept() override;
public:
explicit EditProfileDialog(Cameras* cameras, const Profile profile = Profile(), QWidget *parent = nullptr);

View File

@ -7,11 +7,11 @@
<x>0</x>
<y>0</y>
<width>539</width>
<height>485</height>
<height>652</height>
</rect>
</property>
<property name="windowTitle">
<string>Profile</string>
<string>Edit Profile</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
@ -153,6 +153,9 @@
</item>
<item>
<widget class="QDoubleSpinBox" name="doubleSpinBoxExposure">
<property name="decimals">
<number>5</number>
</property>
<property name="maximum">
<double>1.000000000000000</double>
</property>
@ -176,9 +179,89 @@
</item>
</layout>
</item>
<item>
<widget class="QCheckBox" name="checkBoxNodistort">
<property name="text">
<string>Don't undisort camera image </string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<layout class="QGridLayout" name="gridLayout">
<property name="topMargin">
<number>10</number>
</property>
<item row="0" column="0">
<widget class="QLabel" name="label_7">
<property name="text">
<string>Calibration curve:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="Led" name="calLed" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>40</width>
<height>40</height>
</size>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QPushButton" name="pushButtonCalLoad">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Load</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_8">
<property name="text">
<string>Lightmap:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="Led" name="ledLightmap" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>40</width>
<height>40</height>
</size>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QPushButton" name="pushButtonLightmapLoad">
<property name="text">
<string>Load</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
@ -192,6 +275,12 @@
</layout>
</widget>
<customwidgets>
<customwidget>
<class>Led</class>
<extends>QWidget</extends>
<header location="global">./src/ui/led.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>CameraListWidget</class>
<extends>QListView</extends>

View File

@ -3,6 +3,7 @@
#include <QDebug>
#include <QMessageBox>
#include <uvosled.h>
#include <QFileDialog>
#include "../profile.h"
@ -17,9 +18,62 @@ MainWindow::MainWindow(QWidget *parent)
connect(ui->actionProfile, &QAction::triggered, [this](bool checked){(void)checked; sigEditProfiles();});
connect(ui->comboBox, &QComboBox::currentTextChanged, this, &MainWindow::sigProfile);
connect(ui->pushButtonCapture, &QPushButton::clicked, this, &MainWindow::sigCapture);
connect(ui->mainViewer, &CvImageViewer::sigValue, this, &MainWindow::setImageValue);
connect(ui->actionOpen, &QAction::triggered, [this](bool checked){(void)checked; openImage();});
connect(ui->actionSave_2, &QAction::triggered, [this](bool checked){(void)checked; saveImage();});
refreshProfiles();
}
void MainWindow::setImageValue(size_t x, size_t y, double value)
{
ui->lcdNumber_3->display((double)x);
ui->lcdNumber_2->display((double)y);
ui->lcdNumber->display(value);
}
void MainWindow::saveImage()
{
if(!ui->mainViewer->getImage().data)
{
QMessageBox::warning(this, "No image", "There is no image to save");
return;
}
QString fileName = QFileDialog::getSaveFileName(this, "Save Image", "./", "*.mat");
if(!fileName.isEmpty())
{
QStringList tokens = fileName.split('.');
if(tokens.back() != "mat")
fileName.append(".mat");
cv::FileStorage matf(fileName.toStdString(), cv::FileStorage::WRITE);
matf<<"image"<<ui->mainViewer->getImage();
matf.release();
}
}
void MainWindow::openImage()
{
QString fileName = QFileDialog::getOpenFileName(this, "Open Image", "./", "*.mat");
if(!fileName.isEmpty())
{
cv::Mat image;
cv::FileStorage matf(fileName.toStdString(), cv::FileStorage::READ);
matf["image"]>>image;
if(matf.isOpened() && (!image.data || image.type() != CV_32FC1))
{
image.release();
QMessageBox::warning(this, "Invalid file", "File selected dose not contain a valid lightmap");
}
else if(!image.data)
{
QMessageBox::warning(this, "Can no open", "Can not open file selected");
}
matf.release();
ui->mainViewer->setImage(Camera::Image(image, 0));
}
}
void MainWindow::addCamera(std::shared_ptr<Camera> camera)
{
viewers_.push_back(new CvImageViewer(this, camera->id()));
@ -28,6 +82,11 @@ void MainWindow::addCamera(std::shared_ptr<Camera> camera)
ui->viewerLayout->addWidget(viewers_.back());
}
void MainWindow::statusMsg(QString msg)
{
ui->statusbar->showMessage(msg);
}
void MainWindow::removeCamera(std::shared_ptr<Camera> camera)
{
for(size_t i = 0; i < viewers_.size(); ++i)
@ -93,4 +152,3 @@ MainWindow::~MainWindow()
delete viewer;
delete ui;
}

View File

@ -16,6 +16,11 @@ class MainWindow : public QMainWindow
private:
std::vector<CvImageViewer*> viewers_;
private slots:
void setImageValue(size_t x, size_t y, double value);
void saveImage();
void openImage();
signals:
void sigCapture();
void sigProfile(QString profileName);
@ -30,6 +35,7 @@ public slots:
void removeCamera(std::shared_ptr<Camera> camera);
bool setProfile(const QString& profileName);
QString getProfileName();
void statusMsg(QString msg);
public:
MainWindow(QWidget *parent = nullptr);

View File

@ -11,7 +11,11 @@
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
<string>Lubricant Detector</string>
</property>
<property name="windowIcon">
<iconset resource="../../res/resources.qrc">
<normaloff>:/images/icon.png</normaloff>:/images/icon.png</iconset>
</property>
<widget class="QWidget" name="centralwidget">
<layout class="QVBoxLayout" name="verticalLayout_4">
@ -27,6 +31,9 @@
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QScrollArea" name="scrollArea">
<property name="verticalScrollBarPolicy">
<enum>Qt::ScrollBarAsNeeded</enum>
</property>
<property name="widgetResizable">
<bool>true</bool>
</property>
@ -68,7 +75,7 @@
<x>0</x>
<y>0</y>
<width>467</width>
<height>353</height>
<height>313</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_6">
@ -79,6 +86,55 @@
</widget>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="topMargin">
<number>10</number>
</property>
<item>
<widget class="QLabel" name="label_2">
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
</property>
<property name="text">
<string>X</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QLCDNumber" name="lcdNumber_3"/>
</item>
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>Y</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QLCDNumber" name="lcdNumber_2"/>
</item>
<item>
<widget class="QLabel" name="label_4">
<property name="text">
<string>Value</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QLCDNumber" name="lcdNumber"/>
</item>
</layout>
</item>
</layout>
</widget>
</item>
@ -146,7 +202,8 @@
<property name="title">
<string>File</string>
</property>
<addaction name="actionSave"/>
<addaction name="actionOpen"/>
<addaction name="actionSave_2"/>
<addaction name="actionQuit"/>
</widget>
<widget class="QMenu" name="menuSetup">
@ -164,6 +221,9 @@
<property name="text">
<string>Quit</string>
</property>
<property name="shortcut">
<string>Ctrl+Q</string>
</property>
</action>
<action name="actionCameras">
<property name="text">
@ -180,6 +240,22 @@
<string>Save</string>
</property>
</action>
<action name="actionSave_2">
<property name="text">
<string>Save</string>
</property>
<property name="shortcut">
<string>Ctrl+S</string>
</property>
</action>
<action name="actionOpen">
<property name="text">
<string>Open</string>
</property>
<property name="shortcut">
<string>Ctrl+O</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>
@ -189,6 +265,8 @@
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<resources>
<include location="../../res/resources.qrc"/>
</resources>
<connections/>
</ui>

View File

@ -34,7 +34,7 @@ void ProfileDialog::editProfile()
QMessageBox::critical(this, "Profile Incompatible", "Not all cameras need for this profile are available");
return;
}
EditProfileDialog dialog(cameras_, profile);
EditProfileDialog dialog(cameras_, profile, this);
dialog.show();
int ret = dialog.exec();
if(ret == QDialog::Accepted)

View File

@ -13,6 +13,10 @@
<property name="windowTitle">
<string>Profiles</string>
</property>
<property name="windowIcon">
<iconset resource="../../res/resources.qrc">
<normaloff>:/images/icon.png</normaloff>:/images/icon.png</iconset>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="label">
@ -61,7 +65,9 @@
</item>
</layout>
</widget>
<resources/>
<resources>
<include location="../../res/resources.qrc"/>
</resources>
<connections>
<connection>
<sender>buttonBox</sender>