forked from chickenjohn/Video_power_workshop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmaindialog.cpp
165 lines (146 loc) · 4.31 KB
/
maindialog.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
//------------------------------------------------------------------------------------------------------------------
//Copyright (C) 2015 chickenjohn
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 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 General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
// Attached below is the contact of chickenjohn:
// Email: chickenjohn93@outlook.com
//------------------------------------------------------------------------------------------------------------------
#include "maindialog.h"
int INIT_MOUSE=1;
CvCapture *capture;
IplImage *frame;
QTimer *mouse_timer;
QTimer *timer;
int state=4;
int pen_not_found_counter=0;
int finger_not_found_counter=0;
CascadeClassifier cascade,ncascade;//创建级联分类器对象
//String cascadeName = "./lbpcascade_frontalface.xml";
String cascadeName = "./haarcascade_frontalface_alt2.xml";
String NosecascadeName = "./haarcascade_mcs_nose.xml";
MainDialog::MainDialog(QWidget *parent)
: QDialog(parent)
{
mouse_timer = new QTimer;
mouse_timer->start(6000);
//layout
this->resize(640,480);
setWindowTitle(tr("Video Power Workshop--fantastic video based workshop"));
headctrl = new Headctrl;
drawer = new Drawer;
tab = new QTabWidget;
state_label = new QLabel;
tab ->addTab(headctrl, tr("Head Controller"));
tab -> addTab(drawer, tr("Power Drawer"));
state_label->setText(tr("None"));
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addWidget(tab);
mainLayout->addWidget(state_label);
setLayout(mainLayout);
cascade.load( cascadeName );
ncascade.load( NosecascadeName );
timer = new QTimer;
capture = cvCaptureFromCAM(0);
if(capture==NULL)
{
qDebug()<<"error!";
}
connect(timer,SIGNAL(timeout()),this,SLOT(startcapture()));
connect(tab,SIGNAL(currentChanged(int)),this,SLOT(pagechange(int)));
connect(this,SIGNAL(draw_end_sig()),drawer,SLOT(enddraw()));
connect(mouse_timer,SIGNAL(timeout()),this, SLOT(changeclick()));
timer->start(110);
}
void MainDialog::startcapture()
{
int finger_init_success=-1;
frame = cvQueryFrame(capture);
extern bool object_found;
extern bool isWritting;
extern QLabel * number_rec;
switch(state)
{
case 0:
state_label->setText(tr("Mouse"));
if(INIT_MOUSE)
{
finger_init_success = initdirect();
if(finger_init_success<0)
{
INIT_MOUSE=1;
}
else
INIT_MOUSE=0;
}
else
mouse_ctrl();
break;
case 1:
state_label->setText(tr("Head"));
getframe();
break;
case 2:
state_label->setText(tr("Drawer"));
startdraw();
system("clear");
printf("objf=%d\n",object_found);
if(!object_found)
pen_not_found_counter++;
else
pen_not_found_counter=0;
if(!isWritting)
number_rec->setText(tr("Not Writting"));
else
number_rec->setText(tr("Writting"));
//mouse_ctrl();
break;
case 3:
break;
default:
state_label->setText(tr("None"));
break;
}
if(pen_not_found_counter>25)
{
pen_not_found_counter=0;
state=0;
emit draw_end_sig();
}
if(finger_not_found_counter>20)
{
finger_not_found_counter=0;
state=2;
}
}
void MainDialog::pagechange(int index)
{
pen_not_found_counter=0;
finger_not_found_counter=0;
if(index==1)
{
timer->start(60);
state = 2;
}
else if(index == 0)
{
timer->start(110);
state = 4;
}
}
void MainDialog::changeclick()
{
extern bool mouse_btn;
mouse_btn=true;
}
MainDialog::~MainDialog()
{
}