-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocess.cpp
More file actions
126 lines (112 loc) · 2.92 KB
/
process.cpp
File metadata and controls
126 lines (112 loc) · 2.92 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
#include"process.h"
//#include"sound.h"
//#include"alsa.h"
void setNoise(cam& camera, blob blobs[], int num_blobs){
int finished = 0;
int arr[num_blobs] ={0};
unsigned int width = 213;
unsigned int len = 21300;
int swtch = 0;
while(finished < num_blobs){
camera.dq1(swtch);
char* frame = (char*)camera.getstart(swtch);
for(int i = 0; i < num_blobs; i++){
int index = 640 * 100 + blobs[i].offset;
unsigned int clean = 0;
for(unsigned int k = 0; k < len; k+=width){
for(unsigned int x = 0; x < width; x++){
if( /*frame1[index] > (ref[index]+ref[index] *0.2) &&*/
frame[index] > (blobs[i].ref[k + x]+(blobs[i].noise_mask[k + x]))
){
blobs[i].noise_mask[k + x] += 10;
//blobs[i].weight++;
}else{
clean++;
}
index++;
}
index += (640 - width);
}
if(clean == len){
arr[i]++;
}
if(arr[i] > 2){
finished ++;
}
}
camera.q1(swtch);
swtch = !swtch;
}
if(swtch){
camera.dq1(swtch);
camera.q1(swtch);
}
}
void setRef(cam& camera, blob blobs[], int num_blobs){
unsigned int len = 21300;
unsigned int width = 213;
camera.dq1(0);
char* frame = (char*)camera.getstart(0);
for(int i = 0; i < num_blobs; i ++){
int index = 640 * 100 + blobs[i].offset;
for(unsigned int k = 0; k < len; k+=width){
for(unsigned int x = 0; x < width; x++){
blobs[i].ref[k + x] = frame[index];
index++;
}
index += (640-width);
}
}
camera.q1(0);
}
void process(cam& camera, int flag, blob blobs[], int num_blobs, midi& mid){
// unsigned int width = 213;
//unsigned int len = 21300;
char* frame;
if(flag){
camera.dq1(0);
frame = (char*)camera.getstart(0);
// camera.dq1(1);
}else{
camera.dq1(1);
frame = (char*)camera.getstart(1);
// camera.dq1(2);
// camera.dq1(3);
}
int count = 0;
for(int i = 0; i < num_blobs; i ++){
int index = 640 * 100 + blobs[i].offset;
unsigned int width = 213;
unsigned int len = 21300;
for(unsigned int k = 0; k < len; k+=width){
for(unsigned int x = 0; x < width; x++){
if(frame[index] > (blobs[i].ref[k + x] + blobs[i].noise_mask[k + x])){
count++;
// frame[index] = 200;
//blobs[i].weight++;
}else{
// frame[index] = 0;
if(count > 0){
count --;
}
}
if(count > 20){
blobs[i].weight++;
}
index++;
}
index +=(640-width);
}
if(blobs[i].weight > 50 && blobs[i].debounce == 0){
// std::cout<<"bloby boi"<<i<<std::endl;
blobs[i].debounce = 8;
mid.play(i);
}else{
if(blobs[i].debounce > 0){
blobs[i].debounce--;
}
mid.stop(i);
}
blobs[i].weight = 0;
}
}