Commit 5ab9dc14 authored by Thiago Santini's avatar Thiago Santini

Normalizing strings

parent 2e736c6d
......@@ -7,6 +7,7 @@ using namespace cv;
CameraWidget::CameraWidget(QString id, ImageProcessor::Type type, QWidget* parent)
: ERWidget(id, parent)
, type(type)
, ui(new Ui::CameraWidget)
, sROI(QPoint(0, 0))
, eROI(QPoint(0, 0))
, settingROI(false)
......@@ -14,7 +15,6 @@ CameraWidget::CameraWidget(QString id, ImageProcessor::Type type, QWidget* paren
, updateIntervalMs(80)
, maxAgeMs(300)
, cameraCalibrationSampleRequested(false)
, ui(new Ui::CameraWidget)
{
ui->setupUi(this);
ui->viewFinder->setScaledContents(false);
......@@ -28,8 +28,6 @@ CameraWidget::CameraWidget(QString id, ImageProcessor::Type type, QWidget* paren
case ImageProcessor::Field:
ui->viewFinder->setToolTip("After starting the collection you can select points by clicking in this view with the left mouse button.");
break;
default:
break;
}
// Early enrollment of stages so they are listed in order :-)
......@@ -187,11 +185,11 @@ void CameraWidget::preview(EyeData data)
};
QRectF coarseROI = {
QPointF(
ui->viewFinder->width() * data.coarseROI.tl().x / (float)data.input.cols,
ui->viewFinder->height() * data.coarseROI.tl().y / (float)data.input.rows),
ui->viewFinder->width() * data.coarseROI.tl().x / static_cast<double>(data.input.cols),
ui->viewFinder->height() * data.coarseROI.tl().y / static_cast<double>(data.input.rows)),
QPointF(
ui->viewFinder->width() * data.coarseROI.br().x / (float)data.input.cols,
ui->viewFinder->height() * data.coarseROI.br().y / (float)data.input.rows)
ui->viewFinder->width() * data.coarseROI.br().x / static_cast<double>(data.input.cols),
ui->viewFinder->height() * data.coarseROI.br().y / static_cast<double>(data.input.rows))
};
eyeOverlay.drawOverlay(data, userROI, coarseROI, scaled);
......@@ -433,7 +431,7 @@ QImage CameraWidget::previewImage(const cv::Mat& frame)
* option with QImages, according to http://doc.qt.io/qt-5/qimage.html
*
*/
return QImage(resized.data, resized.cols, resized.rows, (int)resized.step, QImage::Format_RGB888);
return QImage(resized.data, resized.cols, resized.rows, static_cast<int>(resized.step), QImage::Format_RGB888);
}
void CameraWidget::sendCameraCalibrationSample(const cv::Mat& frame)
......@@ -458,11 +456,12 @@ void CameraWidget::onCameraCalibrationFinished(bool success)
void CameraWidget::updateWidgetSize(const int& width, const int& height)
{
if (this->type == ImageProcessor::Eye)
this->setMaximumSize(320, 240);
if (this->type == ImageProcessor::Field)
this->setMaximumSize(640, 360);
return;
// 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 };
......@@ -474,9 +473,9 @@ void CameraWidget::updateWidgetSize(const int& width, const int& height)
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() / (float)frameSize.width();
float ratio = minMaxSize.width() / static_cast<float>(frameSize.width());
frameSize.setWidth(minMaxSize.width());
frameSize.setHeight(ratio * minMaxSize.height());
frameSize.setHeight(static_cast<int>(round(ratio * minMaxSize.height())));
}
this->setMaximumSize(frameSize);
} else
......
......@@ -60,46 +60,28 @@ public:
// to avoid placing things in the wrong order / with the wrong string
QString header(QString prefix = "") const override
{
return prefix % "timestamp"
% Token::Delimiter
% prefix % "pupil.x"
% Token::Delimiter
% prefix % "pupil.y"
% Token::Delimiter
% prefix % "pupil.width"
% Token::Delimiter
% prefix % "pupil.height"
% Token::Delimiter
% prefix % "pupil.angle"
% Token::Delimiter
% prefix % "pupil.confidence"
% Token::Delimiter
% prefix % "pupil.valid"
% Token::Delimiter
% prefix % "processingTime"
% Token::Delimiter;
return prefix % journalField(QStringLiteral("timestamp"))
% prefix % journalField(QStringLiteral("pupil.x"))
% prefix % journalField(QStringLiteral("pupil.y"))
% prefix % journalField(QStringLiteral("pupil.width"))
% prefix % journalField(QStringLiteral("pupil.height"))
% prefix % journalField(QStringLiteral("pupil.angle"))
% prefix % journalField(QStringLiteral("pupil.confidence"))
% prefix % journalField(QStringLiteral("pupil.valid"))
% prefix % journalField(QStringLiteral("processingTime"));
}
void toQStringImpl(QString& str) const override
{
str.append(QString::number(timestamp));
str.append(Token::Delimiter);
str.append(QString::number(pupil.center.x));
str.append(Token::Delimiter);
str.append(QString::number(pupil.center.y));
str.append(Token::Delimiter);
str.append(QString::number(pupil.size.width));
str.append(Token::Delimiter);
str.append(QString::number(pupil.size.height));
str.append(Token::Delimiter);
str.append(QString::number(pupil.angle));
str.append(Token::Delimiter);
str.append(QString::number(pupil.confidence));
str.append(Token::Delimiter);
str.append(QString::number(validPupil));
str.append(Token::Delimiter);
str.append(QString::number(processingTimestamp));
str.append(Token::Delimiter);
str.append(journalField(timestamp));
str.append(journalField(pupil.center.x));
str.append(journalField(pupil.center.y));
str.append(journalField(pupil.size.width));
str.append(journalField(pupil.size.height));
str.append(journalField(pupil.angle));
str.append(journalField(pupil.confidence));
str.append(journalField(validPupil));
str.append(journalField(processingTimestamp));
}
};
Q_DECLARE_METATYPE(EyeData)
......
......@@ -6,6 +6,7 @@ using namespace cv;
using namespace aruco;
static int gFieldDataId = qRegisterMetaType<FieldData>("FieldData");
int Marker::cachedStrSize = 0;
FieldImageProcessor::FieldImageProcessor(QString id, QObject* parent)
: id(id)
......
......@@ -39,7 +39,7 @@ public:
, tv(cv::Mat())
{
}
explicit Marker(std::vector<cv::Point2f> corners, int id)
Marker(std::vector<cv::Point2f> corners, int id)
: corners(corners)
, center(cv::Point3f(0, 0, 0))
, id(id)
......@@ -47,12 +47,32 @@ public:
, tv(cv::Mat())
{
}
QString str() const
{
QString tmp;
tmp.reserve(cachedStrSize);
tmp.append(idStr());
tmp.append(valueStr());
tmp.append(Token::MarkerEnd);
tmp.squeeze();
cachedStrSize = std::max(cachedStrSize, tmp.size());
return tmp;
}
std::vector<cv::Point2f> corners;
cv::Point3f center;
// Not exported atm
int id;
cv::Mat rv;
cv::Mat tv;
private:
static int cachedStrSize;
QString idStr() const { return QString("%1%2").arg(id).arg(Token::MarkerIdDelimiter); }
QString strWithPrecision(const double v) const { return QString::number(v, 'g', Token::Precision); }
QString strWithPrecision(const float v) const { return strWithPrecision(static_cast<double>(v)); }
QString valueStr() const { return QString("%2%1%3%1%4").arg(Token::MarkerValueDelimiter).arg(strWithPrecision(center.x)).arg(strWithPrecision(center.y)).arg(strWithPrecision(center.z)); }
};
class FieldData : public InputData {
......@@ -81,76 +101,42 @@ public:
unsigned int height;
std::shared_ptr<CameraCalibration> cameraCalibration;
QString header(QString prefix = "") const override
QString
header(QString prefix = "") const override
{
return prefix % "timestamp"
% Token::Delimiter
% prefix % "gaze.x"
% Token::Delimiter
% prefix % "gaze.y"
% Token::Delimiter
% prefix % "gaze.z"
% Token::Delimiter
% prefix % "gaze.valid"
% Token::Delimiter
% prefix % "collectionMarker.id"
% Token::Delimiter
% prefix % "collectionMarker.x"
% Token::Delimiter
% prefix % "collectionMarker.y"
% Token::Delimiter
% prefix % "collectionMarker.z"
% Token::Delimiter
% prefix % "undistorted"
% Token::Delimiter
% prefix % "width"
% Token::Delimiter
% prefix % "height"
% Token::Delimiter
% prefix % "markers"
% Token::Delimiter
% prefix % "processingTime"
% Token::Delimiter;
return prefix % journalField(QStringLiteral("timestamp"))
% prefix % journalField(QStringLiteral("gaze.x"))
% prefix % journalField(QStringLiteral("gaze.y"))
% prefix % journalField(QStringLiteral("gaze.z"))
% prefix % journalField(QStringLiteral("gaze.valid"))
% prefix % journalField(QStringLiteral("collectionMarker.id"))
% prefix % journalField(QStringLiteral("collectionMarker.x"))
% prefix % journalField(QStringLiteral("collectionMarker.y"))
% prefix % journalField(QStringLiteral("collectionMarker.z"))
% prefix % journalField(QStringLiteral("undistorted"))
% prefix % journalField(QStringLiteral("width"))
% prefix % journalField(QStringLiteral("height"))
% prefix % journalField(QStringLiteral("markers"))
% prefix % journalField(QStringLiteral("processingTime"));
}
void toQStringImpl(QString& str) const override
{
str.append(QString::number(timestamp));
str.append(Token::Delimiter);
str.append(QString::number(gazeEstimate.x));
str.append(Token::Delimiter);
str.append(QString::number(gazeEstimate.y));
str.append(Token::Delimiter);
str.append(QString::number(gazeEstimate.z));
str.append(Token::Delimiter);
str.append(QString::number(validGazeEstimate));
str.append(Token::Delimiter);
str.append(QString::number(collectionMarker.id));
str.append(Token::Delimiter);
str.append(QString::number(collectionMarker.center.x));
str.append(Token::Delimiter);
str.append(QString::number(collectionMarker.center.y));
str.append(Token::Delimiter);
str.append(QString::number(collectionMarker.center.z));
str.append(Token::Delimiter);
str.append(QString::number(undistorted));
str.append(Token::Delimiter);
str.append(QString::number(width));
str.append(Token::Delimiter);
str.append(QString::number(height));
str.append(Token::Delimiter);
for (unsigned int i = 0; i < markers.size(); i++) {
str.append(QString::number(markers[i].id));
str.append(":");
str.append(QString::number(markers[i].center.x));
str.append("x");
str.append(QString::number(markers[i].center.y));
str.append("x");
str.append(QString::number(markers[i].center.z));
str.append(";");
}
str.append(Token::Delimiter);
str.append(QString::number(processingTimestamp));
str.append(journalField(timestamp));
str.append(journalField(gazeEstimate.x));
str.append(journalField(gazeEstimate.y));
str.append(journalField(gazeEstimate.z));
str.append(journalField(validGazeEstimate));
str.append(journalField(collectionMarker.id));
str.append(journalField(collectionMarker.center.x));
str.append(journalField(collectionMarker.center.y));
str.append(journalField(collectionMarker.center.z));
str.append(journalField(undistorted));
str.append(journalField(width));
str.append(journalField(height));
for (unsigned int i = 0; i < markers.size(); i++)
str.append(markers[i].str());
str.append(Token::Delimiter);
}
};
......
......@@ -74,7 +74,7 @@ void FieldOverlay::drawGaze()
painter.scale(scale.width(), scale.height());
painter.setPen(QPen(QColor(0, 255, 0, alpha), 2 * refPx, Qt::SolidLine));
double radius = 5 * refPx; // TODO: change based on evaluation error :-)
double radius = 4 * refPx; // TODO: change based on evaluation error :-)
if (radius > 0) {
painter.drawEllipse(dataTuple->field.gazeEstimate.x - radius, dataTuple->field.gazeEstimate.y - radius, 2 * radius, 2 * radius);
//painter.drawEllipse(dataTuple->field.gazeEstimate.x - radius, dataTuple->field.gazeEstimate.y - radius , 2*radius, 2*radius);
......
......@@ -37,11 +37,11 @@ public:
bool showGazeEstimationVisualization;
static QString header()
{
return QString("sync.timestamp") % Token::Delimiter % FieldData().header("field.") % EyeData().header("left.") % EyeData().header("right.");
return journalField(QStringLiteral("sync.timestamp")) % FieldData().header(QStringLiteral("field.")) % EyeData().header(QStringLiteral("left.")) % EyeData().header(QStringLiteral("right."));
}
QString toQString()
{
return QString::number(timestamp) % Token::Delimiter % field.toQString() % lEye.toQString() % rEye.toQString();
return journalField(timestamp) % field.toQString() % lEye.toQString() % rEye.toQString();
}
};
......@@ -49,7 +49,7 @@ class Synchronizer : public QObject {
Q_OBJECT
public:
explicit Synchronizer(QObject* parent = 0);
explicit Synchronizer(QObject* parent = nullptr);
~Synchronizer();
signals:
......
......@@ -4,6 +4,10 @@ const char Token::Delimiter = '\t';
const char Token::Newline = '\n';
const char Token::JournalEntry = 'J';
const char Token::HeaderEntry = 'H';
const char Token::MarkerIdDelimiter = ':';
const char Token::MarkerValueDelimiter = 'x';
const char Token::MarkerEnd = ';';
const int Token::Precision = 6;
const Timestamp maxTimestamp = std::numeric_limits<Timestamp>::max();
......@@ -103,7 +107,7 @@ QString toQString(QCameraViewfinderSettings setting)
+ " "
+ toQString(setting.pixelFormat())
+ " @ "
+ QString::number((int)setting.maximumFrameRate()) + " FPS";
+ QString::number(static_cast<int>(setting.maximumFrameRate())) + " FPS";
}
QString iniStr(QString str)
......
......@@ -32,13 +32,34 @@ public:
static const char Newline;
static const char JournalEntry;
static const char HeaderEntry;
static const char MarkerIdDelimiter;
static const char MarkerValueDelimiter;
static const char MarkerEnd;
static const int Precision;
};
template <typename T>
inline QString journalField(const T& v)
{
return QString("%1%2").arg(v).arg(Token::Delimiter);
}
template <>
inline QString journalField<double>(const double& v)
{
return QString("%1%2").arg(v, 0, 'g', Token::Precision).arg(Token::Delimiter);
}
template <>
inline QString journalField<float>(const float& v)
{
return journalField(static_cast<double>(v));
}
/*
* Utility functions
*/
QDebug operator<<(QDebug dbg, const QCameraViewfinderSettings& p);
QDebug
operator<<(QDebug dbg, const QCameraViewfinderSettings& p);
void logInitBanner();
void logExitBanner();
......
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