Commit a2d349ce authored by Thiago Santini's avatar Thiago Santini

Allows for per-camera-configuration and widget-independent intrinsics parameters

parent 0fcdfaba
......@@ -176,6 +176,7 @@ void Camera::setCamera(const QCameraInfo& cameraInfo, QCameraViewfinderSettings
loadUserCameraParameters();
setValuesUI();
saveCfg();
emit cameraChanged(currentCameraInfo, currentViewfinderSettings);
qInfo() << id << msg;
}
......
......@@ -253,7 +253,7 @@ public:
signals:
void newFrame(Timestamp t, cv::Mat frame);
void cameraChanged(QCameraInfo currentCamera);
void cameraChanged(QCameraInfo currentCamera, QCameraViewfinderSettings viewFinderSettings);
void noCamera(QString msg);
public slots:
......
......@@ -66,13 +66,13 @@ void CameraCalibration::onCalibrated()
void CameraCalibration::updateCalibrationStatus(bool success)
{
if (success) {
qInfo() << id << "calibrated. RMS Error =" << rms;
qInfo() << id << "intrinsic parameters found. Calibration RMS error =" << rms;
undistortPB->setEnabled(true);
setRms(rms);
setCoverage(coverage);
sampleCountQL->setText(QString::number(sampleCount));
} else {
qInfo() << id << "calibration failed.";
qInfo() << "No intrinsic parameters found for" << id;
undistortPB->setEnabled(false);
setRms();
setCoverage();
......
......@@ -46,6 +46,8 @@ CameraWidget::CameraWidget(QString id, ImageProcessor::Type type, QWidget* paren
camera->moveToThread(cameraThread);
connect(camera, SIGNAL(noCamera(QString)),
this, SLOT(noCamera(QString)));
connect(camera, SIGNAL(cameraChanged(QCameraInfo, QCameraViewfinderSettings)),
this, SLOT(cameraChanged(QCameraInfo, QCameraViewfinderSettings)));
// debugging preview
//connect(camera, SIGNAL(newFrame(Timestamp, const cv::Mat&)),
// this, SLOT(preview(Timestamp, const cv::Mat&)) );
......@@ -55,7 +57,6 @@ CameraWidget::CameraWidget(QString id, ImageProcessor::Type type, QWidget* paren
this, SLOT(requestCameraCalibrationSample()));
connect(cameraCalibration.get(), SIGNAL(calibrationFinished(bool)),
this, SLOT(onCameraCalibrationFinished(bool)));
cameraCalibration->load(gCfgDir + "/" + id + "Calibration.xml");
// Image Processor
processorThread = new QThread();
......@@ -261,6 +262,7 @@ void CameraWidget::noCamera(QString msg)
QImage blank(ui->viewFinder->size(), QImage::Format_RGB888);
blank.fill(Qt::black);
ui->viewFinder->setPixmap(QPixmap::fromImage(blank));
intrinsicsFileName.clear();
}
void CameraWidget::options(QAction* action)
......@@ -470,37 +472,42 @@ void CameraWidget::onCameraCalibrationFinished(bool success)
{
if (!success)
return;
// TODO: at some point we might consider storing this with a unique camera ID instead of this generic one
QString fileName = gCfgDir + "/" + id + "Calibration.xml";
// Do the store here with a direct call to guarantee it will be done before the updateConfig
QMetaObject::invokeMethod(cameraCalibration.get(), "store", Qt::DirectConnection, Q_ARG(QString, fileName));
QMetaObject::invokeMethod(cameraCalibration.get(), "store", Qt::DirectConnection, Q_ARG(QString, intrinsicsFileName));
QMetaObject::invokeMethod(imageProcessor, "updateConfig", Qt::QueuedConnection);
}
void CameraWidget::updateWidgetSize(const int& width, const int& height)
{
// hard coded limitations
//if (this->type == ImageProcessor::Eye)
// this->setMaximumSize(320, 240);
//if (this->type == ImageProcessor::Field)
// this->setMaximumSize(1280, 720);
//return;
// Logic to limit the size of the camera widgets
QSize newFrameSize = { width, height };
if (frameSize == newFrameSize)
return;
frameSize = newFrameSize;
QSize minMaxSize = { 640, 480 };
QSize maxSize = { 960, 540 };
if (frameSize.width() < maxSize.width() && frameSize.height() < maxSize.height()) {
if (frameSize.width() < minMaxSize.width() && frameSize.height() < minMaxSize.height()) {
float ratio = minMaxSize.width() / static_cast<float>(frameSize.width());
frameSize.setWidth(minMaxSize.width());
frameSize.setHeight(static_cast<int>(round(ratio * minMaxSize.height())));
}
this->setMaximumSize(frameSize);
} else
this->setMaximumSize(maxSize);
// Simply limit to image sizes; no upscaling
int dx = this->width() - ui->viewFinder->width();
int dy = this->height() - ui->viewFinder->height();
setMaximumWidth(width + dx);
setMaximumHeight(height + dy);
}
void CameraWidget::cameraChanged(QCameraInfo currentCamera, QCameraViewfinderSettings viewFinderSettings)
{
QDir intrinsicsDir(QString("%1/intrinsics/").arg(gCfgDir));
if (!intrinsicsDir.exists())
intrinsicsDir.mkpath(".");
if (currentCamera.isNull()) {
intrinsicsFileName.clear();
} else {
intrinsicsFileName = intrinsicsDir.absolutePath();
intrinsicsFileName.append("/");
intrinsicsFileName.append(currentCamera.deviceName());
intrinsicsFileName.append("-");
intrinsicsFileName.append(QString::number(viewFinderSettings.resolution().width()));
intrinsicsFileName.append("x");
intrinsicsFileName.append(QString::number(viewFinderSettings.resolution().height()));
intrinsicsFileName.append(".xml");
}
cameraCalibration->load(intrinsicsFileName);
}
......@@ -5,6 +5,8 @@
#include <QAction>
#include <QCamera>
#include <QCameraInfo>
#include <QCameraViewFinderSettings>
#include <QFont>
#include <QLineF>
#include <QMainWindow>
......@@ -72,6 +74,8 @@ public slots:
void sendCameraCalibrationSample(const cv::Mat& frame);
void onCameraCalibrationFinished(bool success);
void cameraChanged(QCameraInfo currentCamera, QCameraViewfinderSettings viewFinderSettings);
private:
ImageProcessor::Type type;
......@@ -115,6 +119,8 @@ private:
std::shared_ptr<CameraCalibration> cameraCalibration;
bool cameraCalibrationSampleRequested;
QString intrinsicsFileName;
QSize frameSize = { 0, 0 };
void updateWidgetSize(const int& width, const int& height);
......
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