-
Notifications
You must be signed in to change notification settings - Fork 0
/
testApp.cpp
172 lines (124 loc) · 4.14 KB
/
testApp.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
166
167
168
169
170
171
172
#include "testApp.h"
#define NUM_COL 21
unsigned char testApp::colors[] = {
0x7c, 0x9f, 0xb0, 0x56, 0x98, 0xc4, 0x9a, 0xbf, 0x88,
0x91, 0x63, 0xb6, 0xe2, 0x79, 0xa3, 0xe0, 0x59, 0x8b,
0x99, 0x37, 0x67, 0x65, 0x38, 0x7d, 0x4e, 0x24, 0x72,
0xc9, 0x4a, 0x53, 0xbe, 0x51, 0x68, 0xa3, 0x49, 0x74,
0xe2, 0x97, 0x5d, 0xf1, 0x96, 0x70, 0xe1, 0x65, 0x52,
0x8e, 0x8c, 0x6d, 0xe4, 0xbf, 0x80, 0xe9, 0xd7, 0x8e,
0x51, 0x57, 0x4a, 0x44, 0x7c, 0x69, 0x74, 0xc4, 0x93,
};
//--------------------------------------------------------------
void testApp::setup(){
oclx1 = ofGetWidth()* 4/16;
oclx2 = ofGetWidth()*11/16;
oclw = ofGetWidth() /16;
ofBackground(0);
ofEnableAlphaBlending();
ofSetCircleResolution(36);
}
//--------------------------------------------------------------
void testApp::update(){
if(!B.size() || (B.size() < 10 && ofRandom(0.0, 100.0) > 99.0)) {
B.push_back(ofRectangle(
ofRandom(ofGetWidth()),
ofRandom(ofGetHeight()),
ofRandom(40.0, 80.0),
ofRandom(40.0, 80.0)));
T.push_back(ofPoint(
ofRandom(ofGetWidth()),
ofRandom(ofGetHeight())));
V.push_back(0);
int c = ofRandom(18);
C.push_back(ofColor(colors[c*3], colors[c*3+1], colors[c*3+2]));
}
// random kill first
if(B.size() >= 5 && ofRandom(0.0, 100.0) > 99.0) {
B.erase(B.begin());
T.erase(T.begin());
V.erase(V.begin());
C.erase(C.begin());
}
for (int i=0; i<B.size(); i++) {
float dx = B[i].x + B[i].width /2 - T[i].x;
float dy = B[i].y + B[i].height/2 - T[i].y;
float ln = sqrt(dx*dx + dy*dy);
float v = 20.0;
V[i].x += (-dx/ln*v- V[i].x)/50;
V[i].y += (-dy/ln*v- V[i].y)/50;
B[i] = B[i]+V[i];
T[i].x +=dy/ln/ln*1e2*v;
T[i].y -=dx/ln/ln*1e2*v;
//T[i].x +=dy/ln*v;
//T[i].y -=dx/ln*v;
if(ofRandom(0.0, 100.0) > 99.5)
T[i] = ofPoint( ofRandom(ofGetWidth()), ofRandom(ofGetHeight()));
}
vector<ofRectangle> b;
// occlude blobs
for (int i=0; i< B.size(); i++) {
float x = B[i].getCenter().x;
if((x<oclx1 || x>oclx1+oclw) && (x<oclx2 || x>oclx2+oclw)) {
b.push_back(B[i]);
}
}
random_shuffle(b.begin(), b.end());
tracker.trackFaces(b);
}
//--------------------------------------------------------------
void testApp::draw() {
ofNoFill();
for (int i=0; i<B.size(); i++) {
ofSetColor(C[i]);
ofRect(B[i]);
ofCircle(T[i],5);
ofDrawBitmapString(ofToString(i), B[i].x , B[i].y-2);
ofDrawBitmapString(ofToString(i), T[i].x - 3, T[i].y-6);
ofSetColor(C[i], 80);
ofLine(B[i].getCenter(), T[i]);
}
ofFill();
for (int i=0; i<tracker.trackedFaces.size(); i++) {
ofRectangle& f = tracker.trackedFaces[i];
ofPoint c = f.getCenter();
ofSetColor(colors[i%21*3], colors[i%21*3+1], colors[i%21*3+2], 80);
//ofRect(f.x+2, f.y+2, f.width-4, f.height-4);
ofCircle(c, 20);
ofSetColor(colors[i%21*3], colors[i%21*3+1], colors[i%21*3+2]);
ofDrawBitmapString(ofToString(i)+"-"+ofToString(tracker.trackedFacesCounter[i]/10), f.x + 10 , f.y-2);
}
// occlusions
ofSetColor(40, 200);
ofRect(oclx1, 0, oclw, ofGetHeight());
ofRect(oclx2, 0, oclw, ofGetHeight());
ofSetColor(255);
ofDrawBitmapString(tracker.debug, 10 , 20);
}
//--------------------------------------------------------------
void testApp::keyPressed(int key){
}
//--------------------------------------------------------------
void testApp::keyReleased(int key){
}
//--------------------------------------------------------------
void testApp::mouseMoved(int x, int y ){
}
//--------------------------------------------------------------
void testApp::mouseDragged(int x, int y, int button){
}
//--------------------------------------------------------------
void testApp::mousePressed(int x, int y, int button){
}
//--------------------------------------------------------------
void testApp::mouseReleased(int x, int y, int button){
}
//--------------------------------------------------------------
void testApp::windowResized(int w, int h){
}
//--------------------------------------------------------------
void testApp::gotMessage(ofMessage msg){
}
//--------------------------------------------------------------
void testApp::dragEvent(ofDragInfo dragInfo){
}