summaryrefslogtreecommitdiffhomepage
path: root/opentrack
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2015-07-19 16:50:41 +0200
committerStanislaw Halik <sthalik@misaki.pl>2015-07-19 16:50:41 +0200
commit4da0c0619cbf052eb87a618aba4c8de79f0d4325 (patch)
treee075b2a2601d6d2f26a8a70fb83cb682cdfb23df /opentrack
parentf9b5b72cbcf9f121e0184f9a907bbffd7e1e16a9 (diff)
parenta8165591d993a23ae71ea4e5bb7df7596688ef7b (diff)
Merge branch 'unstable' into trackhat-ui
Diffstat (limited to 'opentrack')
-rw-r--r--opentrack/camera-names.hpp28
-rw-r--r--opentrack/opencv-camera-dialog.hpp13
-rw-r--r--opentrack/plugin-api.hpp21
-rw-r--r--opentrack/simple-mat.hpp4
-rw-r--r--opentrack/thread.hpp45
-rw-r--r--opentrack/tracker.cpp3
6 files changed, 54 insertions, 60 deletions
diff --git a/opentrack/camera-names.hpp b/opentrack/camera-names.hpp
index 6f82ba34..fd869e6b 100644
--- a/opentrack/camera-names.hpp
+++ b/opentrack/camera-names.hpp
@@ -13,6 +13,13 @@
# include <unistd.h>
#endif
+#ifdef __linux
+#include <fcntl.h>
+#include <sys/ioctl.h>
+#include <linux/videodev2.h>
+#include <cerrno>
+#endif
+
template<typename = void>
QList<QString> get_camera_names() {
QList<QString> ret;
@@ -69,14 +76,29 @@ QList<QString> get_camera_names() {
qDebug() << "failed CLSID_VideoInputDeviceCategory" << hr;
pSysDevEnum->Release();
-#else
+#endif
+#ifdef __linux
for (int i = 0; i < 16; i++) {
char buf[128];
sprintf(buf, "/dev/video%d", i);
- if (access(buf, R_OK | W_OK) == 0) {
+ if (access(buf, F_OK) == 0)
ret.append(buf);
- } else {
+ else
continue;
+
+ if (access(buf, R_OK | W_OK) == 0) {
+ int fd = open(buf, O_RDONLY);
+ if (fd == -1)
+ continue;
+ struct v4l2_capability video_cap;
+ if(ioctl(fd, VIDIOC_QUERYCAP, &video_cap) == -1)
+ {
+ qDebug() << "VIDIOC_QUERYCAP" << errno;
+ close(fd);
+ continue;
+ }
+ ret[ret.size()-1] = reinterpret_cast<const char*>(video_cap.card);
+ close(fd);
}
}
#endif
diff --git a/opentrack/opencv-camera-dialog.hpp b/opentrack/opencv-camera-dialog.hpp
index 6218f125..cd3d38e7 100644
--- a/opentrack/opencv-camera-dialog.hpp
+++ b/opentrack/opencv-camera-dialog.hpp
@@ -6,9 +6,21 @@
#include <opencv2/videoio.hpp>
#include "opentrack/camera-names.hpp"
+#ifdef __linux
+#include <QProcess>
+#endif
+
template<typename tracker>
class camera_dialog
{
+#ifdef __linux
+public:
+ void open_camera_settings(cv::VideoCapture *, const QString &camera_name, QMutex *)
+ {
+ int idx = camera_name_to_index(camera_name);
+ QProcess::startDetached("qv4l2", QStringList() << "-d" << ("/dev/video" + QString::number(idx)));
+ }
+#else
cv::VideoCapture fake_capture;
QTimer t;
@@ -47,5 +59,6 @@ public:
// HACK: we're not notified when it's safe to close the capture
t.start();
}
+#endif
};
diff --git a/opentrack/plugin-api.hpp b/opentrack/plugin-api.hpp
index 714e69d9..021f5017 100644
--- a/opentrack/plugin-api.hpp
+++ b/opentrack/plugin-api.hpp
@@ -2,6 +2,7 @@
#include "export.hpp"
#include <QString>
+#include <QWidget>
#include <QFrame>
#include <QIcon>
@@ -9,6 +10,15 @@ enum Axis {
TX = 0, TY, TZ, Yaw, Pitch, Roll
};
+class BaseDialog : public QWidget
+{
+ Q_OBJECT
+public:
+ void closeEvent(QCloseEvent *) override { emit closing(); }
+signals:
+ void closing();
+};
+
#define OPENTRACK_DECLARE_PLUGIN_INTERNAL(ctor_class, ctor_ret_class, metadata_class, dialog_class, dialog_ret_class) \
extern "C" OPENTRACK_EXPORT ctor_ret_class* GetConstructor() \
{ \
@@ -24,9 +34,9 @@ enum Axis {
}
// implement this in all plugins
+// also you must link against "opentrack-api" in CMakeList.txt to avoid vtable link errors
struct Metadata
{
-public:
// plugin name to be displayed in the interface
virtual QString name() = 0;
// plugin icon, you can return an empty QIcon()
@@ -38,7 +48,6 @@ public:
// implement this in filters
struct IFilter
{
-public:
// optional destructor
virtual ~IFilter() {}
// perform filtering step.
@@ -46,7 +55,7 @@ public:
virtual void filter(const double *input, double *output) = 0;
};
-struct IFilterDialog : public QWidget
+struct IFilterDialog : public BaseDialog
{
// optional destructor
virtual ~IFilterDialog() {}
@@ -63,7 +72,6 @@ struct IFilterDialog : public QWidget
// implement this in protocols
struct IProtocol
{
-public:
// optional destructor
virtual ~IProtocol() {}
// return true if protocol was properly initialized
@@ -75,7 +83,7 @@ public:
virtual QString game_name() = 0;
};
-struct IProtocolDialog : public QWidget
+struct IProtocolDialog : public BaseDialog
{
// optional destructor
virtual ~IProtocolDialog() {}
@@ -92,7 +100,6 @@ struct IProtocolDialog : public QWidget
// implement this in trackers
struct ITracker
{
-public:
// optional destructor
virtual ~ITracker() {}
// start tracking, and grab a frame to display webcam video in, optionally
@@ -101,7 +108,7 @@ public:
virtual void data(double *data) = 0;
};
-struct ITrackerDialog : public QWidget
+struct ITrackerDialog : public BaseDialog
{
// optional destructor
virtual ~ITrackerDialog() {}
diff --git a/opentrack/simple-mat.hpp b/opentrack/simple-mat.hpp
index e111305a..7432e665 100644
--- a/opentrack/simple-mat.hpp
+++ b/opentrack/simple-mat.hpp
@@ -107,7 +107,7 @@ struct Mat
{
Mat<num, h_, w_> ret;
for (int j = 0; j < h_; j++)
- for (int i = 0; i < w; i++)
+ for (int i = 0; i < w_; i++)
ret(j, i) = this->operator ()(j, i) + other(j, i);
return ret;
}
@@ -125,7 +125,7 @@ struct Mat
{
Mat<num, h_, w_> ret;
for (int j = 0; j < h_; j++)
- for (int i = 0; i < w; i++)
+ for (int i = 0; i < w_; i++)
ret(j, i) = this->operator ()(j, i) + other;
return ret;
}
diff --git a/opentrack/thread.hpp b/opentrack/thread.hpp
deleted file mode 100644
index 946f2972..00000000
--- a/opentrack/thread.hpp
+++ /dev/null
@@ -1,45 +0,0 @@
-/* Copyright (c) 2014-2015, Stanislaw Halik <sthalik@misaki.pl>
-
- * Permission to use, copy, modify, and/or distribute this
- * software for any purpose with or without fee is hereby granted,
- * provided that the above copyright notice and this permission
- * notice appear in all copies.
- */
-
-#pragma once
-
-#include <QDebug>
-
-enum {
- CORE_WORK = 1,
- CORE_IPC = 0,
-};
-
-#ifdef _WIN32
-#include <windows.h>
-
-class Affinity {
-public:
- Affinity(int core = CORE_WORK)
- {
- DWORD_PTR ret = SetThreadAffinityMask(GetCurrentThread(), 1 << core);
- if (ret == 0)
- qDebug() << "SetThreadAffinityMask" << GetLastError();
- last = ret;
- }
- ~Affinity()
- {
- if (last)
- (void) SetThreadAffinityMask(GetCurrentThread(), last);
- }
-private:
- DWORD_PTR last;
-};
-
-#else
-class Affinity {
-public:
- Affinity(int core = CORE_WORK) {}
- ~Affinity() {}
-};
-#endif
diff --git a/opentrack/tracker.cpp b/opentrack/tracker.cpp
index 502f7a96..ce23afad 100644
--- a/opentrack/tracker.cpp
+++ b/opentrack/tracker.cpp
@@ -14,7 +14,6 @@
#include "tracker.h"
-#include "opentrack/thread.hpp"
#include <cmath>
#include <algorithm>
@@ -181,8 +180,6 @@ void Tracker::logic()
void Tracker::run() {
const int sleep_ms = 3;
- Affinity thr(CORE_IPC);
-
#if defined(_WIN32)
(void) timeBeginPeriod(1);
#endif