This repository has been archived by the owner on Sep 19, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
GuiController.cpp
121 lines (102 loc) · 3.45 KB
/
GuiController.cpp
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/**
* This file is part of the rgbdemo project.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Author: Nicolas Burrus <[email protected]>, (C) 2010, 2011
*/
#include "GuiController.h"
#include "ui_RawImagesWindow.h"
#include "RawImagesWindow.h"
//#include "PoseRecognizer.h"
#include <ntk/ntk.h>
#include <ntk/camera/rgbd_frame_recorder.h>
#include <QMainWindow>
#include <QImage>
#include <QApplication>
using namespace cv;
using namespace ntk;
GuiController :: GuiController(ntk::RGBDGrabber& producer,
ntk::RGBDProcessor& processor)
: m_grabber(producer),
m_processor(processor),
m_frame_recorder(0),
m_last_tick(cv::getTickCount()),
m_frame_counter(0),
m_frame_rate(0),
m_raw_window_grabber("/tmp/demo3d/raw"),
m_screen_capture_mode(false),
m_grab_frames(false),
m_paused(false),
m_process_one_frame(false)
{
m_raw_images_window = new RawImagesWindow(*this);
m_raw_images_window->show();
}
GuiController :: ~GuiController()
{
delete m_raw_images_window;
}
void GuiController :: quit()
{
m_grabber.setShouldExit();
m_grabber.newEvent();
m_grabber.wait();
QApplication::quit();
}
void GuiController :: setFrameRecorder(ntk::RGBDFrameRecorder& frame_recorder)
{
m_frame_recorder = &frame_recorder;
m_raw_images_window->ui->outputDirText->setText(m_frame_recorder->directory().path());
}
void GuiController :: onRGBDDataUpdated()
{
if (m_paused && !m_process_one_frame)
return;
m_process_one_frame = false;
++m_frame_counter;
if (m_frame_counter == 10)
{
double current_tick = cv::getTickCount();
m_frame_rate = m_frame_counter / ((current_tick - m_last_tick)/cv::getTickFrequency());
m_last_tick = current_tick;
m_frame_counter = 0;
}
m_grabber.copyImageTo(m_last_image);
TimeCount tc_rgbd_process("m_processor.processImage", 2);
m_processor.processImage(m_last_image);
tc_rgbd_process.stop();
if (m_raw_images_window->isVisible())
m_raw_images_window->update(m_last_image);
if (m_frame_recorder && (m_screen_capture_mode || m_grab_frames))
m_frame_recorder->saveCurrentFrame(m_last_image);
if (m_screen_capture_mode)
m_raw_window_grabber.saveFrame(QPixmap::grabWindow(m_raw_images_window->winId()));
QString status = QString("Final fps = %1 Fps GRABBER = %2")
.arg(m_frame_rate, 0, 'f', 1)
.arg(m_grabber.frameRate(), 0, 'f', 1);
if (m_grab_frames)
status += " [GRABBING]";
m_raw_images_window->ui->statusbar->showMessage(status);
if (!m_paused)
m_grabber.newEvent();
}
void GuiController :: on_depth_mouse_moved(int x, int y)
{
if (!m_last_image.depth().data || x < 0 || y < 0)
return;
QString s = QString("Distance at (%1,%2) = %3 m")
.arg(x).arg(y).arg(m_last_image.depth()(y,x), 0, 'f', 3);
m_raw_images_window->ui->distanceLabel->setText(s);
}