-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbrightestBlob.pde
59 lines (47 loc) · 1.16 KB
/
brightestBlob.pde
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
// ==================================================
// drawBlobsAndEdges()
// ==================================================
PVector getBrightestBlobCenter()
{
Blob b;
EdgeVertex eA, eB;
float brightestBlobValue = 0;
int brightestBlobIdx = -1;
for (int n=0; n<theBlobDetection.getBlobNb(); n++)
{
float blobBright = getBlobBrightness(n);
if(blobBright > brightestBlobValue) {
brightestBlobIdx = n;
}
}
if(brightestBlobIdx == -1) {
return new PVector(0,0);
} else {
return getBlobCenter(brightestBlobIdx);
}
}
float getBlobBrightness(int n) {
Blob b;
EdgeVertex eA, eB;
b=theBlobDetection.getBlob(n);
if (b == null) {
return 0;
}
float brightness = 0;
for (int m=0; m<b.getEdgeNb(); m++)
{
eA = b.getEdgeVertexA(m);
eB = b.getEdgeVertexB(m);
if (eA !=null && eB !=null)
//line(
// eA.x*width, eA.y*height,
// eB.x*width, eB.y*height
// );
brightness++;
}
return brightness;
}
PVector getBlobCenter(int n) {
Blob b=theBlobDetection.getBlob(n);
return new PVector(b.xMin*width + (b.w*width/2), b.yMin*height + (b.h*height/2));
}