summaryrefslogtreecommitdiffhomepage
path: root/ftnoir_tracker_aruco/ftnoir_tracker_aruco.h
blob: 0cb8fd8f8bb008b50070c0415077535157722eef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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
/* Copyright (c) 2013 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 "ui_aruco-trackercontrols.h"
#include "ar_video_widget.h"
#include <QObject>
#include <QThread>
#include <QMutex>
#include <QHBoxLayout>
#include <QDialog>
#include <QTimer>
#include "opentrack/options.hpp"
#include "ftnoir_tracker_aruco/trans_calib.h"
#include "opentrack/plugin-api.hpp"

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>

using namespace options;

struct settings : opts {
    value<double> fov, headpos_x, headpos_y, headpos_z;
    value<int> camera_index, force_fps, resolution;
    settings() :
        opts("aruco-tracker"),
        fov(b, "field-of-view", 56),
        headpos_x(b, "headpos-x", 0),
        headpos_y(b, "headpos-y", 0),
        headpos_z(b, "headpos-z", 0),
        camera_index(b, "camera-index", 0),
        force_fps(b, "force-fps", 0),
        resolution(b, "force-resolution", 0)
    {}
};

class Tracker : protected QThread, public ITracker
{
    Q_OBJECT
    static constexpr double c_search_window = 2.65;
public:
    Tracker();
    ~Tracker() override;
    void start_tracker(QFrame* frame);
    void data(double *data);
    void run();
    void getRT(cv::Matx33d &r, cv::Vec3d &t);
private:
    QMutex mtx;
    volatile bool stop;
    QHBoxLayout* layout;
    ArucoVideoWidget* videoWidget;
    settings s;
    double pose[6];
    cv::Mat frame;
    cv::VideoCapture camera;
    cv::Matx33d r;
    cv::Vec3d t;
};

class TrackerControls : public ITrackerDialog
{
    Q_OBJECT
public:
    TrackerControls();
    void register_tracker(ITracker * x) { tracker = static_cast<Tracker*>(x); }
    void unregister_tracker() { tracker = nullptr; }
private:
    Ui::Form ui;
    Tracker* tracker;
    settings s;
    TranslationCalibrator calibrator;
    QTimer calib_timer;
private slots:
    void doOK();
    void doCancel();
    void toggleCalibrate();
    void cleanupCalib();
    void update_tracker_calibration();
};