utils.h 2.69 KB
Newer Older
Thiago Santini's avatar
Thiago Santini committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#ifndef UTILS_H
#define UTILS_H

#include <iostream>
#include <atomic>

#ifndef M_PI
#define M_PI 	 3.14159265358979323846
#endif

#include <QElapsedTimer>
#include <QDebug>
#include <QDateTime>
#include <QFile>
#include <QTextStream>
#include <QMutex>
#include <QCameraViewfinderSettings>
18

Thiago Santini's avatar
Thiago Santini committed
19
#include <QCameraInfo>
20 21
Q_DECLARE_METATYPE(QCameraInfo)

Thiago Santini's avatar
Thiago Santini committed
22 23
#include <QWidget>
#include <QSettings>
24
#include <QSoundEffect>
Thiago Santini's avatar
Thiago Santini committed
25 26

#include <opencv/cv.h>
27 28 29
Q_DECLARE_METATYPE(cv::Rect);
Q_DECLARE_METATYPE(cv::Mat);

Thiago Santini's avatar
Thiago Santini committed
30 31 32
#include <opencv2/imgproc.hpp>
#include <opencv2/calib3d.hpp>

Thiago Santini's avatar
Thiago Santini committed
33 34
#include "LogWidget.h"

35 36
#include "PerformanceMonitor.h"

Thiago Santini's avatar
Thiago Santini committed
37 38 39 40 41 42 43
/*
 * Global variables
 */
extern QElapsedTimer gTimer;

typedef qint64 Timestamp;
extern Timestamp maxTimestamp;
44
Q_DECLARE_METATYPE(Timestamp)
Thiago Santini's avatar
Thiago Santini committed
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95

extern QString gExeDir;
extern QString gCfgDir;
extern char gDataSeparator;
extern char gDataNewline;

extern QList<QPair<QString, QString> > gReferenceList;

/*
 * Utility functions
 */

QDebug operator<<(QDebug dbg, const cv::Point &p);

QDebug operator<<(QDebug dbg, const cv::Point2f &p);

QDebug operator<<(QDebug dbg, const cv::Point3f &p);

QDebug operator<<(QDebug dbg, const QCameraViewfinderSettings &p);

template<typename T> double ED(T p1, T p2) { return sqrt( (p1.x-p2.x) * (p1.x-p2.x) + (p1.y-p2.y) * (p1.y-p2.y) ); }


cv::Point3f estimateMarkerCenter(const std::vector<cv::Point2f> corners);

void logInitBanner();
void logExitBanner();
void logMessages(QtMsgType type, const QMessageLogContext &context, const QString &msg);

// Converstion
cv::Point2f to2D(const cv::Point3f p);
cv::Point3f to3D(const cv::Point2f p);

QString toQString(QVideoFrame::PixelFormat format);
QString toQString(QCameraViewfinderSettings setting);

QString iniStr(QString str);

void delay(int thMs);

enum CVFlip { CV_FLIP_BOTH = -1, CV_FLIP_VERTICAL = 0, CV_FLIP_HORIZONTAL = 1, CV_FLIP_NONE = 2};
Q_DECLARE_METATYPE(enum CVFlip)

#define CV_BLUE 	cv::Scalar(0xff,0xb0,0x00)
#define CV_GREEN 	cv::Scalar(0x03,0xff,0x76)
#define CV_RED 		cv::Scalar(0x00,0x3d,0xff)
#define CV_YELLOW	cv::Scalar(0x00,0xea,0xff)
#define CV_CYAN		cv::Scalar(0xff,0xff,0x18)
#define CV_MAGENT   cv::Scalar(0x81,0x40,0xff)
#define CV_WHITE	cv::Scalar(0xff,0xff,0xff)
#define CV_BLACK	cv::Scalar(0x00,0x00,0x00)
Thiago Santini's avatar
Thiago Santini committed
96
#define CV_ALMOST_BLACK	cv::Scalar(0x01,0x01,0x01)
Thiago Santini's avatar
Thiago Santini committed
97 98 99 100 101 102 103 104 105 106

template<typename T> void set(const QSettings *settings, const QString key, T &v)
{
    if (!settings)
        return;
    QVariant variant = settings->value(key);
    if (variant.isValid())
        v = qvariant_cast<T>(variant);
}

107 108
void loadSoundEffect(QSoundEffect &effect, QString fileName);

Thiago Santini's avatar
Thiago Santini committed
109 110 111
extern LogWidget *gLogWidget;
extern std::vector<QString> gLogBuffer;

112 113
extern PerformanceMonitor gPerformanceMonitor;

114
extern bool gCalibrating;
115

Thiago Santini's avatar
Thiago Santini committed
116
#endif // UTILS_H