root / trunk / tbeta / Linux / addons / ofxNCore / src / Tracking / Blob.h @ 164

View | Annotate | Download (3.1 KB)

1
/*
2
* Blob.h
3
*
4
*
5
* A blob is a homogenous patch represented by a polygonal contour.
6
* Typically a blob tracker uses the contour to figure out the blob's
7
* persistence and "upgrades" it with ids and other temporal
8
* information.
9
*
10
*/
11
12
#ifndef BLOB_H
13
#define BLOB_H
14
15
#include <vector>
16
17
class Blob {
18
19
    public: 
20
21
        vector <ofPoint>    pts;     // the contour of the blob
22
        int                 nPts;    // number of pts;
23
                int                                        id;
24
            float               area;
25
        float               length;
26
                float               angle;
27
                float                                maccel;  //distance traveled since last frame
28
                float                                age;     //how long the blob has been at war
29
                float                                sitting; //how long hes been sitting in the same place
30
                float                                downTime;
31
            ofRectangle         boundingRect;
32
                ofRectangle         angleBoundingRect;
33
                ofPoint             centroid, lastCentroid, D;
34
                bool                                simulated;
35
                bool                hole;
36
                int                                        color;                                
37
38
        //----------------------------------------
39
        Blob() {
40
            area                 = 0.0f;
41
            length                 = 0.0f;
42
            hole                 = false;
43
            nPts        = 0;
44
                        simulated        = false;
45
                        age                        = 0.0f;
46
                        sitting                = 0.0f;
47
                        color                = 0xFFFFFF;
48
        }
49
50
        //----------------------------------------
51
        void drawContours(float x = 0, float y = 0, float inputWidth = ofGetWidth(), float inputHeight = ofGetHeight(), float outputWidth = ofGetWidth(), float outputHeight = ofGetHeight()) {
52
            
53
            glPushMatrix();
54
                glTranslatef(x + angleBoundingRect.x/inputWidth * outputWidth, y + angleBoundingRect.y/inputHeight * outputHeight, 0.0f);
55
                glRotatef(-angle, 0.0f, 0.0f, 1.0f);
56
                glTranslatef(-(x + angleBoundingRect.x/inputWidth * outputWidth), -(y + angleBoundingRect.y/inputHeight * outputHeight), 0.0f);                
57
                                
58
                                //draw box
59
//                                ofSetColor(0xFFFFFF);
60
//                                ofRect(x + (angleBoundingRect.x - angleBoundingRect.width/2)/inputWidth * outputWidth, y + (angleBoundingRect.y - angleBoundingRect.height/2)/inputHeight * outputHeight, angleBoundingRect.width/inputWidth * outputWidth, angleBoundingRect.height/inputHeight * outputHeight);
61
62
                                //draw cross-hairs        
63
                                ofSetColor(0x0099FF);
64
                ofRect(x + (angleBoundingRect.x/inputWidth) * outputWidth, y + ((angleBoundingRect.y - angleBoundingRect.height)/inputHeight) * outputHeight, 1, (angleBoundingRect.height * 2)/inputHeight * outputHeight); //Vertical Plus
65
                ofRect(x + ((angleBoundingRect.x - angleBoundingRect.width)/inputWidth) * outputWidth, y + (angleBoundingRect.y/inputHeight) * outputHeight, (angleBoundingRect.width * 2)/inputWidth * outputWidth, 1); //Horizontal Plus
66
            glPopMatrix();
67
68
                        //draw contours
69
                        ofNoFill();
70
            ofSetColor(0xFF0099);
71
            ofBeginShape();
72
            for (int i = 0; i < nPts; i++){
73
                   ofVertex(x + pts[i].x/inputWidth * outputWidth, y + pts[i].y/(inputHeight) * outputHeight);
74
            }
75
            ofEndShape(true);        
76
        }
77
};
78
#endif
79
80