forked from situkangsayur/MouseHandTrackingLK
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyCameraWindow.cpp
More file actions
executable file
·149 lines (107 loc) · 3.31 KB
/
MyCameraWindow.cpp
File metadata and controls
executable file
·149 lines (107 loc) · 3.31 KB
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
/**
* MouseHandTracking is an application to control mouse pointer of the computer with hand gesture via camera
* Copyright (C) 2011 Hendri Karisma
*
* 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 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* contact author at situkangsayur[at]gmail[dot]com
*/
#include "MyCameraWindow.h"
MyCameraWindow::MyCameraWindow( QWidget *parent) : QWidget(parent) {
camera = cvCreateCameraCapture(1);
if (!camera) {
camera= cvCaptureFromCAM(0);
//cout << "hhheeeaarrrr...\n";
}
if (!camera) {
cout << "Could not initialize capturing...\n";
return;
}
assert(camera);
image = 0;
black = 0;
state = 0;
histogram = 0;
countur = 0;
cont = new ConContour();
QVBoxLayout *layout = new QVBoxLayout;
cvwidget = new QOpenCVWidget(this);
layout->addWidget(cvwidget);
setLayout(layout);
resize(640, 480);
startTimer(100); // 0.1-second timer
}
void MyCameraWindow::timerEvent(QTimerEvent*) {
image = cvQueryFrame(camera);
if(black == 0){
black = cvCreateImage(cvSize(image->width,image->height),image->depth,image->nChannels);
}
if(gray == 0){
gray = cvCreateImage(cvSize(image->width,image->height),image->depth,1);
}
if(state == 1){
cont->setCurrentFrame(image);
cont->frameGrabber();
model->setState(cont->getFingerNum()
);
model->setPoint(cont->getp1());
model->setSingkronisasiMouse();
image=cont->getCurrentFrame();
model->setImage(image);
cvCvtColor(cont->getSkin(),black,CV_GRAY2BGR);
model->setCountur(black);
if(countur == 1){
model->loadCountur();
}
if(histogram == 1){
cout<<"masuk histogram 1"<<endl;
model->singkronisasiHis();
}
}else{
cvFlip(image,0,1);
cvCvtColor(image,gray,CV_RGB2GRAY);
cvCvtColor(gray,black,CV_GRAY2BGR);
model->setImage(image);
model->setCountur(black);
if(countur == 1){
model->loadCountur();
}
if(histogram == 1){
cout<<"masuk histogram 1"<<endl;
model->singkronisasiHis();
}
}
cvwidget->putImage(image);
}
void MyCameraWindow::setModel(SistemModel *model){
this->model = model;
}
void MyCameraWindow::setState(int state){
this->state = state;
}
void MyCameraWindow::setHistogram(int histogram){
this->histogram = histogram;
}
void MyCameraWindow::setContour(int contour){
this->countur = contour;
}
int MyCameraWindow::getState(){
return state;
}
int MyCameraWindow::getHistogram(){
return histogram;
}
int MyCameraWindow::getContour(){
return countur;
}