Revision 198

branches/tbeta/Windows-PS3EyeMuticam/apps/addonsExamples/VS2008/src/testApp.cpp (revision 198)
7 7
	ccv = new ofxNCoreVision;
8 8
}
9 9

  
10

  
11 10
//--------------------------------------------------------------
12
void testApp::update()
13
{
14
}
11
void testApp::update(){}
15 12

  
16 13
//--------------------------------------------------------------
17 14
void testApp::draw()
......
36 33
}
37 34

  
38 35
//--------------------------------------------------------------
39
void testApp::keyPressed  (int key)
40
{
41
}
36
void testApp::keyPressed  (int key){}
42 37

  
43 38
//--------------------------------------------------------------
44
void testApp::keyReleased  (int key)
45
{
46
}
39
void testApp::keyReleased  (int key){}
47 40

  
48 41
//--------------------------------------------------------------
49
void testApp::mouseMoved(int x, int y )
50
{
51
}
42
void testApp::mouseMoved(int x, int y ){}
52 43

  
53 44
//--------------------------------------------------------------
54
void testApp::mouseDragged(int x, int y, int button)
55
{
56
}
45
void testApp::mouseDragged(int x, int y, int button){}
57 46

  
58 47
//--------------------------------------------------------------
59
void testApp::mousePressed(int x, int y, int button)
60
{
61
}
48
void testApp::mousePressed(int x, int y, int button){}
62 49

  
63 50
//--------------------------------------------------------------
64
void testApp::mouseReleased()
65
{
66
}
51
void testApp::mouseReleased(){}
67 52

  
68 53
/*****************************************************************************
69 54
 *	TOUCH EVENTS
70 55
 *****************************************************************************/
71
void testApp::TouchDown( Blob b)
72
{
73
}
56
void testApp::TouchDown(Blob b){}
74 57

  
75
void testApp::TouchUp( Blob b)
76
{	
77
}
58
void testApp::TouchUp(Blob b){}
78 59

  
79
void testApp::TouchMoved( Blob b)
80
{
81
}
60
void testApp::TouchMoved( Blob b){}
82 61

  
83 62

  
branches/tbeta/Windows-PS3EyeMuticam/apps/addonsExamples/VS2008/bin/data/config.xml (revision 198)
7 7
    ///////////////////////////////////////////// -->
8 8
    <!--// CAMERA SETTINGS // -->
9 9
    <CAMERA_0>
10
        <USECAMERA>0</USECAMERA>
10
        <USECAMERA>1</USECAMERA>
11 11
        <DEVICE>0</DEVICE>
12 12
        <WIDTH>320</WIDTH>
13 13
        <HEIGHT>240</HEIGHT>
......
17 17
    <NETWORK>
18 18
        <LOCALHOST>127.0.0.1</LOCALHOST>
19 19
        <TUIO>0</TUIO>
20
        <TUIOPORT_OUT>7000</TUIOPORT_OUT>
20
        <TUIOPORT_OUT>3333</TUIOPORT_OUT>
21 21
        <TUIOFLASHPORT_OUT>3000</TUIOFLASHPORT_OUT>
22 22
    </NETWORK>
23 23
    <!--// VIDEO SETTINGS // -->
......
46 46
        <LABELS>1</LABELS>
47 47
        <OUTLINES>1</OUTLINES>
48 48
        <LEARNBG>0</LEARNBG>
49
        <TUIO>0</TUIO>
49
        <TUIO>1</TUIO>
50 50
        <VMIRROR>0</VMIRROR>
51 51
        <HMIRROR>0</HMIRROR>
52 52
        <HIGHPASS>1</HIGHPASS>
53 53
        <AMPLIFY>1</AMPLIFY>
54
        <SMOOTH>1</SMOOTH>
54
        <SMOOTH>0</SMOOTH>
55 55
        <GPU>0</GPU>
56 56
        <DYNAMICBG>0</DYNAMICBG>
57 57
        <SNAPSHOT>0</SNAPSHOT>
58
        <MINIMODE>1</MINIMODE>
58
        <MINIMODE>0</MINIMODE>
59 59
        <HEIGHTWIDTH>0</HEIGHTWIDTH>
60
        <OSCMODE>0</OSCMODE>
60
        <OSCMODE>1</OSCMODE>
61 61
        <TCPMODE>0</TCPMODE>
62 62
        <TRACKDARK>0</TRACKDARK>
63 63
    </BOOLEAN>
64 64
    <INT>
65
        <MINMOVEMENT>0</MINMOVEMENT>
66
        <MINBLOBSIZE>1</MINBLOBSIZE>
67
        <MAXBLOBSIZE>343</MAXBLOBSIZE>
65
        <MINMOVEMENT>3</MINMOVEMENT>
66
        <MINBLOBSIZE>4</MINBLOBSIZE>
67
        <MAXBLOBSIZE>1000</MAXBLOBSIZE>
68 68
        <!--// FILTERS SETTERS //-->
69
        <THRESHOLD>76</THRESHOLD>
70
        <HIGHPASSBLUR>58</HIGHPASSBLUR>
71
        <HIGHPASSNOISE>3</HIGHPASSNOISE>
72
        <HIGHPASSAMP>35</HIGHPASSAMP>
73
        <SMOOTH>2</SMOOTH>
69
        <THRESHOLD>12</THRESHOLD>
70
        <HIGHPASSBLUR>32</HIGHPASSBLUR>
71
        <HIGHPASSNOISE>7</HIGHPASSNOISE>
72
        <HIGHPASSAMP>54</HIGHPASSAMP>
73
        <SMOOTH>5</SMOOTH>
74 74
        <BGLEARNRATE>118.945450</BGLEARNRATE>
75 75
    </INT>
76 76
</CONFIG>
branches/tbeta/Windows-PS3EyeMuticam/apps/addonsExamples/VS2008/bin/data/calibration.xml (revision 198)
4 4
        <GRIDY>1</GRIDY>
5 5
    </GRIDMESH>
6 6
    <BOUNDINGBOX>
7
        <ulx>0.080000</ulx>
8
        <uly>0.066000</uly>
9
        <lrx>0.956001</lrx>
10
        <lry>0.941001</lry>
7
        <ulx>0.000000</ulx>
8
        <uly>0.000000</uly>
9
        <lrx>1.000000</lrx>
10
        <lry>1.000000</lry>
11 11
    </BOUNDINGBOX>
12 12
    <POINT>
13
        <X>227.000000</X>
14
        <Y>147.000000</Y>
13
        <X>129.000000</X>
14
        <Y>157.000000</Y>
15 15
    </POINT>
16 16
    <POINT>
17
        <X>239.000000</X>
18
        <Y>3.000000</Y>
17
        <X>207.000000</X>
18
        <Y>164.000000</Y>
19 19
    </POINT>
20 20
    <POINT>
21
        <X>66.000000</X>
22
        <Y>217.000000</Y>
21
        <X>113.000000</X>
22
        <Y>219.000000</Y>
23 23
    </POINT>
24 24
    <POINT>
25
        <X>55.000000</X>
26
        <Y>3.000000</Y>
25
        <X>203.000000</X>
26
        <Y>209.000000</Y>
27 27
    </POINT>
28 28
</SCREEN>
29 29
<WARP>
branches/tbeta/Windows-PS3EyeMuticam/apps/addonsExamples/VS2008/bin/data/cameras.xml (revision 198)
50 50
<section name="stitching">
51 51
    <subsection name="cameras">
52 52
        <item name="position" value="1" />
53
        <item name="overlap" value="27" />
53
        <item name="overlap" value="207" />
54 54
    </subsection>
55 55
</section>
branches/tbeta/Windows-PS3EyeMuticam/addons/ofxPS3/src/ofxPS3.cpp (revision 198)
10 10

  
11 11
void ofxPS3::listDevices()
12 12
{
13
	// Enumerate the cameras on the USB bus
13
	// Enumerate the cameras on the bus.
14 14
	camNum = PS3EyeMulticamGetCameraCount();
15 15
 	printf("\nFound %d PS3Eye camera(s)...\n", camNum);
16 16
}
......
25 25
	return PS3EyeMulticamGetFrame(pBuffer);
26 26
}
27 27

  
28
void ofxPS3::initPS3(int width,int height, int framerate)
28
void ofxPS3::initPS3(int width, int height, int framerate)
29 29
{
30
	PS3EyeMulticamOpen(camNum, height==480?VGA:QVGA, framerate);
30
	printf("selecting format...\n");
31
	PS3EyeMulticamOpen(camNum, (height==480) ? VGA:QVGA, framerate);
31 32
	PS3EyeMulticamLoadSettings(".\\data\\cameras.xml");
32 33
	// get stitched image width
33 34
	PS3EyeMulticamGetFrameDimensions(camWidth, camHeight);
......
64 65
	PS3EyeMulticamStop();
65 66
	Sleep(50);
66 67
	PS3EyeMulticamSaveSettings(".\\data\\cameras.xml");
67
	PS3EyeMulticamClose();
68
	PS3EyeMulticamClose();	
68 69
	delete [] pBuffer;
70

  
69 71
	// this delete the temp settings.xml which is saved to data/cameras.xml
70 72
	remove("settings.xml");
71 73
}
branches/tbeta/Windows-PS3EyeMuticam/addons/ofxNCore/src/Tracking/ContourFinder.cpp (revision 198)
10 10
#include "ContourFinder.h"
11 11

  
12 12
//--------------------------------------------------------------------------------
13
static int qsort_carea_compare( const void* _a, const void* _b) {
13
static int qsort_carea_compare( const void* _a, const void* _b) 
14
{
14 15
	int out = 0;
15 16
	// pointers, ugh.... sorry about this
16 17
	CvSeq* a = *((CvSeq **)_a);
......
20 21
	float areab = fabs(cvContourArea(b, CV_WHOLE_SEQ));
21 22
	// note, based on the -1 / 1 flip
22 23
	// we sort biggest to smallest, not smallest to biggest
23
	if( areaa > areab ) { out = -1; }
24
	else {                out =  1; }
24
	if( areaa > areab )		out = -1;
25
	else					out =  1;
25 26
	return out;
26 27
}
27 28

  
28 29
//--------------------------------------------------------------------------------
29
ContourFinder::ContourFinder() {
30
ContourFinder::ContourFinder()
31
{
30 32
	myMoments = (CvMoments*)malloc( sizeof(CvMoments) );
31 33
	reset();
32 34
}
33 35

  
34 36
//--------------------------------------------------------------------------------
35
ContourFinder::~ContourFinder() {
37
ContourFinder::~ContourFinder() 
38
{
36 39
	free( myMoments );
37 40
}
38 41

  
39 42
//--------------------------------------------------------------------------------
40
void ContourFinder::reset() {
43
void ContourFinder::reset() 
44
{
41 45
    blobs.clear();
42 46
    nBlobs = 0;
43 47
}
......
48 52
									  int maxArea,
49 53
									  int nConsidered,
50 54
									  bool bFindHoles,
51
                                      bool bUseApproximation) {
55
                                      bool bUseApproximation) 
56
{
52 57
	reset();
53 58

  
54 59
	// opencv will clober the image it detects contours on, so we want to
......
61 66
    // 320x240 image better to make two ContourFinder objects then to use
62 67
    // one, because you will get penalized less.
63 68

  
64
	if( inputCopy.width == 0 ) {
69
	if( inputCopy.width == 0 ) 
70
	{
65 71
		inputCopy.allocate( input.width, input.height );
66 72
		inputCopy = input;
67
	} else {
68
		if( inputCopy.width == input.width && inputCopy.height == input.height ) {
73
	} 
74
	else 
75
	{
76
		if( inputCopy.width == input.width && inputCopy.height == input.height ) 
69 77
			inputCopy = input;
70
		} else {
78
		else 
79
		{
71 80
			// we are allocated, but to the wrong size --
72 81
			// been checked for memory leaks, but a warning:
73 82
			// be careful if you call this function with alot of different
......
92 101
	nCvSeqsFound = 0;
93 102

  
94 103
	// put the contours from the linked list, into an array for sorting
95
	while( (contour_ptr != NULL) ) {
104
	while( (contour_ptr != NULL) ) 
105
	{
96 106
		float area = fabs( cvContourArea(contour_ptr, CV_WHOLE_SEQ) );
97
		if( (area > minArea) && (area < maxArea) ) {
98
                if (nCvSeqsFound < TOUCH_MAX_CONTOUR_LENGTH){
107
		if( (area > minArea) && (area < maxArea) ) 
108
		{
109
                if (nCvSeqsFound < TOUCH_MAX_CONTOUR_LENGTH)
110
				{
99 111
				cvSeqBlobs[nCvSeqsFound] = contour_ptr;	 // copy the pointer
100 112
                nCvSeqsFound++;
101 113
				}
......
104 116
	}
105 117

  
106 118
	// sort the pointers based on size
107
	if( nCvSeqsFound > 0 ) {
119
	if( nCvSeqsFound > 0 ) 
120
	{
108 121
		qsort( cvSeqBlobs, nCvSeqsFound, sizeof(CvSeq*), qsort_carea_compare);
109 122
	}
110 123

  
111 124
	// now, we have nCvSeqsFound contours, sorted by size in the array
112 125
    // cvSeqBlobs let's get the data out and into our structures that we like
113
	for( int i = 0; i < MIN(nConsidered, nCvSeqsFound); i++ ) {
126
	for( int i = 0; i < MIN(nConsidered, nCvSeqsFound); i++ ) 
127
	{
114 128
		blobs.push_back( Blob() );
115 129
		float area = cvContourArea( cvSeqBlobs[i], CV_WHOLE_SEQ );
116 130

  
......
136 150
		// assign other parameters
137 151
		blobs[i].area                = fabs(area);
138 152
		blobs[i].hole                = area < 0 ? true : false;
139
		blobs[i].length 			 = cvArcLength(cvSeqBlobs[i]);		
140
		blobs[i].centroid.x			 = (int) (myMoments->m10 / myMoments->m00);
141
		blobs[i].centroid.y 		 = (int) (myMoments->m01 / myMoments->m00);
142
		blobs[i].lastCentroid.x 	 = (int) 0;
143
		blobs[i].lastCentroid.y 	 = (int) 0;
153
		blobs[i].length 			 = cvArcLength(cvSeqBlobs[i]);
154
		// AlexP
155
		// The cast to int causes errors in tracking since centroids are calculated in
156
		// floats and they migh land between integer pixel values (which is what we really want)
157
		// This not only makes tracking more accurate but also more fluid
158
		blobs[i].centroid.x			 = (myMoments->m10 / myMoments->m00);
159
		blobs[i].centroid.y 		 = (myMoments->m01 / myMoments->m00);
160
		blobs[i].lastCentroid.x 	 = 0;
161
		blobs[i].lastCentroid.y 	 = 0;
144 162

  
145 163
		// get the points for the blob:
146 164
		CvPoint           pt;
147 165
		CvSeqReader       reader;
148 166
		cvStartReadSeq( cvSeqBlobs[i], &reader, 0 );
149 167

  
150
    	for( int j=0; j < min(TOUCH_MAX_CONTOUR_LENGTH, cvSeqBlobs[i]->total); j++ ) {
168
    	for( int j=0; j < min(TOUCH_MAX_CONTOUR_LENGTH, cvSeqBlobs[i]->total); j++ ) 
169
		{
151 170
			CV_READ_SEQ_ELEM( pt, reader );
152 171
            blobs[i].pts.push_back( ofPoint((float)pt.x, (float)pt.y) );
153 172
		}
154 173
		blobs[i].nPts = blobs[i].pts.size();
155

  
156 174
	}
157 175

  
158 176
    nBlobs = blobs.size();
branches/tbeta/Windows-PS3EyeMuticam/addons/ofxNCore/src/Tracking/Tracking.cpp (revision 198)
18 18
	isCalibrating = false;
19 19
}
20 20

  
21
BlobTracker::~BlobTracker(){
22

  
21
BlobTracker::~BlobTracker()
22
{
23 23
	delete calibrate;
24 24
}
25 25

  
26
void BlobTracker::passInCalibration(CalibrationUtils* calibrater) {
27

  
26
void BlobTracker::passInCalibration(CalibrationUtils* calibrater) 
27
{
28 28
    calibrate = calibrater;
29 29
}
30 30

  
......
35 35
	for(int i=0; i<newBlobs->nBlobs; i++)
36 36
		newBlobs->blobs[i].id=-1;
37 37

  
38
	// STEP 1: Blob matching
39
	//
38 40
	//go through all tracked blobs to compute nearest new point
39
	for(int i=0; i<trackedBlobs.size(); i++)
41
	for(int i = 0; i < trackedBlobs.size(); i++)
40 42
	{
41 43
		/******************************************************************
42 44
		 * *****************TRACKING FUNCTION TO BE USED*******************
......
47 49
		 *****************************************************************/
48 50
		int winner = trackKnn(newBlobs, &(trackedBlobs[i]), 3, 0);
49 51

  
50
		if(winner==-1) //track has died, mark it for deletion
52
		if(winner == -1) //track has died, mark it for deletion
51 53
		{
52 54
			//SEND BLOB OFF EVENT
53 55
			TouchEvents.messenger = trackedBlobs[i];
54 56

  
55
			if(isCalibrating){
57
			if(isCalibrating)
58
			{
56 59
				TouchEvents.RAWmessenger = trackedBlobs[i];
57 60
				TouchEvents.notifyRAWTouchUp(NULL);
58 61
			}
59

  
60 62
			calibrate->transformDimension(TouchEvents.messenger.boundingRect.width, TouchEvents.messenger.boundingRect.height);
61 63
			calibrate->cameraToScreenPosition(TouchEvents.messenger.centroid.x, TouchEvents.messenger.centroid.y);
62 64
			//erase calibrated blob from map
......
124 126
						//SEND BLOB OFF EVENT
125 127
						TouchEvents.messenger = trackedBlobs[j];
126 128

  
127
						if(isCalibrating){
129
						if(isCalibrating)
130
						{
128 131
							TouchEvents.RAWmessenger = trackedBlobs[j];
129 132
							TouchEvents.notifyRAWTouchUp(NULL);
130 133
						}
......
144 147
						//SEND BLOB OFF EVENT
145 148
						TouchEvents.messenger = trackedBlobs[i];
146 149

  
147
						if(isCalibrating){
150
						if(isCalibrating)
151
						{
148 152
							TouchEvents.RAWmessenger = trackedBlobs[i];
149 153
							TouchEvents.notifyRAWTouchUp(NULL);
150 154
						}
......
172 176
		}
173 177
	}
174 178

  
179
	// AlexP
180
	// save the current time since we will be using it a lot
181
	int now = ofGetElapsedTimeMillis();
182

  
183
	// STEP 2: Blob update
184
	//
175 185
	//--Update All Current Tracks
176 186
	//remove every track labeled as dead (ID='-1')
177 187
	//find every track that's alive and copy it's data from newBlobs
178
	for(int i=0; i<trackedBlobs.size(); i++)
188
	for(int i = 0; i < trackedBlobs.size(); i++)
179 189
	{
180 190
		if(trackedBlobs[i].id==-1) //dead
181 191
		{
182 192
			//erase track
183
			trackedBlobs.erase(trackedBlobs.begin()+i,
184
							   trackedBlobs.begin()+i+1);
193
			trackedBlobs.erase(trackedBlobs.begin()+i, trackedBlobs.begin()+i+1);
185 194

  
186 195
			i--; //decrement one since we removed an element
187 196
		}
188 197
		else //living, so update it's data
189 198
		{
190
			for(int j=0; j<newBlobs->nBlobs; j++)
199
			for(int j = 0; j < newBlobs->nBlobs; j++)
191 200
			{
192
				if(trackedBlobs[i].id==newBlobs->blobs[j].id)
201
				if(trackedBlobs[i].id == newBlobs->blobs[j].id)
193 202
				{
194 203
					//update track
195 204
					ofPoint tempLastCentroid = trackedBlobs[i].centroid; // assign the new centroid to the old
196
					trackedBlobs[i]=newBlobs->blobs[j];
205
					trackedBlobs[i] = newBlobs->blobs[j];
197 206
					trackedBlobs[i].lastCentroid = tempLastCentroid;
198 207

  
208
					// AlexP
209
					// now, filter the blob position based on MOVEMENT_FILTERING value
210
					// the MOVEMENT_FILTERING ranges [0,15] so we will have that many filtering steps
211
					// Here we have a simple weighted low-pass filter
212
					float a = 1.0f - (float)MOVEMENT_FILTERING / 15.0f;
213
					trackedBlobs[i].centroid.x = a * trackedBlobs[i].centroid.x + (1-a) * trackedBlobs[i].lastCentroid.x;
214
					trackedBlobs[i].centroid.y = a * trackedBlobs[i].centroid.y + (1-a) * trackedBlobs[i].lastCentroid.y;
215

  
199 216
					//get the Differences in position
200
					trackedBlobs[i].D.set((trackedBlobs[i].centroid.x - trackedBlobs[i].lastCentroid.x) / (ofGetElapsedTimeMillis() - trackedBlobs[i].lastTimeTimeWasChecked), 
201
										  (trackedBlobs[i].centroid.y - trackedBlobs[i].lastCentroid.y) / (ofGetElapsedTimeMillis() - trackedBlobs[i].lastTimeTimeWasChecked));
217
					trackedBlobs[i].D.set(trackedBlobs[i].centroid.x - trackedBlobs[i].lastCentroid.x, 
218
											trackedBlobs[i].centroid.y - trackedBlobs[i].lastCentroid.y);
202 219

  
203
					//printf("D(%f, %f)\n", trackedBlobs[i].D.x, trackedBlobs[i].D.y);
204
					
205 220
					//if( abs((int)trackedBlobs[i].D.x) > 1 || abs((int)trackedBlobs[i].D.y) > 1) {
206 221
//						printf("\nUNUSUAL BLOB @ %f\n-----------------------\ntrackedBlobs[%i]\nD = (%f, %f)\nXY= (%f, %f)\nlastTimeTimeWasChecked = %f\nsitting = %f\n",
207 222
//							   ofGetElapsedTimeMillis(),
......
213 228
//							   trackedBlobs[i].sitting
214 229
//						);
215 230
//					}
216
					
217
					
218
					//calculate the accelleration
231

  
232
					//calculate the acceleration
219 233
					ofPoint tD = trackedBlobs[i].D;
220
					trackedBlobs[i].maccel = sqrtf((tD.x* tD.x)+(tD.y*tD.y)/(ofGetElapsedTimeMillis() - trackedBlobs[i].lastTimeTimeWasChecked));
221
					
222
					trackedBlobs[i].lastTimeTimeWasChecked = ofGetElapsedTimeMillis();
234
					trackedBlobs[i].maccel = sqrtf((tD.x* tD.x)+(tD.y*tD.y)/(now - trackedBlobs[i].lastTimeTimeWasChecked));
223 235

  
224 236
					//calculate the age
225 237
					trackedBlobs[i].age = ofGetElapsedTimef() - trackedBlobs[i].downTime;
226 238

  
227
					//if not moving more than min_movement_threshold then set to same position as last frame
228
		            if(trackedBlobs[i].maccel < MIN_MOVEMENT_THRESHOLD)
229
					{	//this helps avoid jittery blobs
230
						trackedBlobs[i].centroid.x = trackedBlobs[i].lastCentroid.x;
231
						trackedBlobs[i].centroid.y = trackedBlobs[i].lastCentroid.y;
232
                    }
233

  
234 239
					//set sitting (held length)
235 240
                    if(trackedBlobs[i].maccel < 7)
236 241
					{	//1 more frame of sitting
237 242
						if(trackedBlobs[i].sitting != -1)
238
						trackedBlobs[i].sitting = ofGetElapsedTimef() - trackedBlobs[i].downTime;           
243
							trackedBlobs[i].sitting = ofGetElapsedTimef() - trackedBlobs[i].downTime;           
239 244
					}
240
					else {
245
					else
241 246
						trackedBlobs[i].sitting = -1;
242
					}
243 247

  
244 248
					//printf("time: %f\n", ofGetElapsedTimeMillis());
245 249
					//printf("%i age: %f, downTimed at: %f\n", i, trackedBlobs[i].age, trackedBlobs[i].downTime);
246 250

  
247 251
					//if blob has been 'holding/sitting' for 1 second send a held event
248
					if(trackedBlobs[i].sitting > 1.0f){
249

  
252
					if(trackedBlobs[i].sitting > 1.0f)
253
					{
250 254
						//SEND BLOB HELD EVENT
251 255
						TouchEvents.messenger = trackedBlobs[i];
252 256

  
253
						if(isCalibrating){
257
						if(isCalibrating)
258
						{
254 259
							TouchEvents.RAWmessenger = trackedBlobs[i];
255 260
							TouchEvents.notifyRAWTouchHeld(NULL);
256 261
						}
......
261 266
						calibrate->cameraToScreenPosition(TouchEvents.messenger.lastCentroid.x, TouchEvents.messenger.lastCentroid.y);
262 267
						
263 268
						//Calibrated dx/dy
264
						TouchEvents.messenger.D.set((TouchEvents.messenger.centroid.x - TouchEvents.messenger.lastCentroid.x) / (ofGetElapsedTimeMillis() - TouchEvents.messenger.lastTimeTimeWasChecked), 
265
													(TouchEvents.messenger.centroid.y - TouchEvents.messenger.lastCentroid.y) / (ofGetElapsedTimeMillis() - TouchEvents.messenger.lastTimeTimeWasChecked));
269
						TouchEvents.messenger.D.set(trackedBlobs[i].centroid.x - trackedBlobs[i].lastCentroid.x, 
270
												trackedBlobs[i].centroid.y - trackedBlobs[i].lastCentroid.y);
266 271
						
267
						TouchEvents.messenger.lastTimeTimeWasChecked = ofGetElapsedTimeMillis();
268
						
269
						
270

  
271
						
272
						//calibrated accelleration
272
					
273
						//calibrated acceleration
273 274
						ofPoint tD2 = TouchEvents.messenger.D;
274
						TouchEvents.messenger.maccel = sqrtf((tD2.x* tD2.x)+(tD2.y*tD2.y)/(ofGetElapsedTimeMillis() - trackedBlobs[i].lastTimeTimeWasChecked));						
275
						TouchEvents.messenger.maccel = sqrtf((tD2.x* tD2.x)+(tD2.y*tD2.y)/(now - TouchEvents.messenger.lastTimeTimeWasChecked));						
276
						TouchEvents.messenger.lastTimeTimeWasChecked = now;
275 277
						
276 278
						//add to calibration map
277 279
						calibratedBlobs[TouchEvents.messenger.id] = TouchEvents.messenger;
......
280 282
                        trackedBlobs[i].sitting = -1;
281 283

  
282 284
						TouchEvents.notifyTouchHeld(NULL);
283

  
284
					} else {
285
						
285
					} 
286
					else 
287
					{
286 288
						//printf("(%f, %f) -> (%f, %f) \n", trackedBlobs[i].lastCentroid.x, trackedBlobs[i].lastCentroid.y, trackedBlobs[i].centroid.x, trackedBlobs[i].centroid.y);
287 289

  
288 290
						//SEND BLOB MOVED EVENT
289 291
						TouchEvents.messenger = trackedBlobs[i];
290 292

  
291
						if(isCalibrating){
293
						if(isCalibrating)
294
						{
292 295
							TouchEvents.RAWmessenger = trackedBlobs[i];
293 296
							TouchEvents.notifyRAWTouchMoved(NULL);
294 297
						}
......
297 300
						calibrate->transformDimension(TouchEvents.messenger.boundingRect.width, TouchEvents.messenger.boundingRect.height);
298 301
						calibrate->cameraToScreenPosition(TouchEvents.messenger.centroid.x, TouchEvents.messenger.centroid.y);
299 302
						calibrate->cameraToScreenPosition(TouchEvents.messenger.lastCentroid.x, TouchEvents.messenger.lastCentroid.y);
300
						
303

  
301 304
						//Calibrated dx/dy
302
						TouchEvents.messenger.D.set((TouchEvents.messenger.centroid.x - TouchEvents.messenger.lastCentroid.x) / (ofGetElapsedTimeMillis() - TouchEvents.messenger.lastTimeTimeWasChecked), 
303
													(TouchEvents.messenger.centroid.y - TouchEvents.messenger.lastCentroid.y) / (ofGetElapsedTimeMillis() - TouchEvents.messenger.lastTimeTimeWasChecked));
304
	
305
						
306
						TouchEvents.messenger.lastTimeTimeWasChecked = ofGetElapsedTimeMillis();
307
						
308
						
305
						TouchEvents.messenger.D.set(trackedBlobs[i].centroid.x - trackedBlobs[i].lastCentroid.x, 
306
											trackedBlobs[i].centroid.y - trackedBlobs[i].lastCentroid.y);
307

  
309 308
						//printf("d(%0.4f, %0.4f)\n", TouchEvents.messenger.D.x, TouchEvents.messenger.D.y);
310

  
311
						
312 309
												
313
						//calibrated accelleration
310
						//calibrated acceleration
314 311
						ofPoint tD2 = TouchEvents.messenger.D;
315
						TouchEvents.messenger.maccel = sqrtf((tD2.x* tD2.x)+(tD2.y*tD2.y)/(ofGetElapsedTimeMillis() - trackedBlobs[i].lastTimeTimeWasChecked));						
312
						TouchEvents.messenger.maccel = sqrtf((tD2.x* tD2.x)+(tD2.y*tD2.y)/(now - TouchEvents.messenger.lastTimeTimeWasChecked));						
313
						TouchEvents.messenger.lastTimeTimeWasChecked = now;
316 314
						
317 315
						//add to calibration map
318 316
						calibratedBlobs[TouchEvents.messenger.id] = TouchEvents.messenger;
319 317

  
320 318
						TouchEvents.notifyTouchMoved(NULL);
321 319
					}
320
					// AlexP
321
					// The last lastTimeTimeWasChecked is updated at the end after all acceleration values are calculated
322
					trackedBlobs[i].lastTimeTimeWasChecked = now;
322 323
				}
323 324
			}
324 325
		}
325 326
	}
327
	
328
	// STEP 3: add tracked blobs to TouchEvents
326 329
	//--Add New Living Tracks
327 330
	//now every new blob should be either labeled with a tracked ID or\
328 331
	//have ID of -1... if the ID is -1... we need to make a new track
329
	for(int i=0; i<newBlobs->nBlobs; i++)
332
	for(int i = 0; i < newBlobs->nBlobs; i++)
330 333
	{
331 334
		if(newBlobs->blobs[i].id==-1)
332 335
		{
......
347 350
			//Add to blob messenger
348 351
			TouchEvents.messenger = newBlobs->blobs[i];
349 352

  
350
			if(isCalibrating){
353
			if(isCalibrating)
354
			{
351 355
				TouchEvents.RAWmessenger = newBlobs->blobs[i];
352 356
				TouchEvents.notifyRAWTouchDown(NULL);
353 357
			}
354

  
355 358
            calibrate->transformDimension(TouchEvents.messenger.boundingRect.width, TouchEvents.messenger.boundingRect.height);
356 359
            calibrate->cameraToScreenPosition(TouchEvents.messenger.centroid.x, TouchEvents.messenger.centroid.y);
357 360
			//add to calibrated blob map
......
359 362

  
360 363
			//Send Event
361 364
			TouchEvents.notifyTouchDown(NULL);
362

  
363 365
			trackedBlobs.push_back(newBlobs->blobs[i]);
364 366
		}
365 367
	}
366 368
}
367 369

  
368
std::map<int, Blob> BlobTracker::getTrackedBlobs(){
369
	
370
std::map<int, Blob> BlobTracker::getTrackedBlobs()
371
{
370 372
    return calibratedBlobs;
371 373
}
372 374

  
......
455 457
			winner = iter->first;
456 458
		}
457 459
	}
458

  
459 460
	return winner;
460 461
}
branches/tbeta/Windows-PS3EyeMuticam/addons/ofxNCore/src/Tracking/Blob.h (revision 198)
37 37
		int					color;				
38 38

  
39 39
        //----------------------------------------
40
        Blob() {
40
        Blob() 
41
		{
41 42
            area 		= 0.0f;
42 43
            length 		= 0.0f;
43 44
            hole 		= false;
......
52 53
        }
53 54

  
54 55
        //----------------------------------------
55
        void drawContours(float x = 0, float y = 0, float inputWidth = ofGetWidth(), float inputHeight = ofGetHeight(), float outputWidth = ofGetWidth(), float outputHeight = ofGetHeight()) {
56
            
56
        void drawContours(float x = 0, float y = 0, float inputWidth = ofGetWidth(), float inputHeight = ofGetHeight(), float outputWidth = ofGetWidth(), float outputHeight = ofGetHeight()) 
57
		{
57 58
            glPushMatrix();
58 59
                glTranslatef(x + angleBoundingRect.x/inputWidth * outputWidth, y + angleBoundingRect.y/inputHeight * outputHeight, 0.0f);
59 60
                glRotatef(-angle, 0.0f, 0.0f, 1.0f);
......
73 74
			ofNoFill();
74 75
            ofSetColor(0xFF0099);
75 76
            ofBeginShape();
76
            for (int i = 0; i < nPts; i++){
77
            for (int i = 0; i < nPts; i++)
77 78
                   ofVertex(x + pts[i].x/inputWidth * outputWidth, y + pts[i].y/(inputHeight) * outputHeight);
78
            }
79 79
            ofEndShape(true);	
80 80
        }
81 81
};
branches/tbeta/Windows-PS3EyeMuticam/addons/ofxNCore/src/Tracking/ContourFinder.h (revision 198)
17 17
#include "ofxOpenCv.h"
18 18
#include "Blob.h"
19 19

  
20
#define TOUCH_MAX_CONTOURS 128
21
#define TOUCH_MAX_CONTOUR_LENGTH 1024
20
#define TOUCH_MAX_CONTOURS			128
21
#define TOUCH_MAX_CONTOUR_LENGTH	1024
22 22

  
23
class ContourFinder {
24

  
23
class ContourFinder 
24
{
25 25
  public:
26 26

  
27 27
    ContourFinder();
branches/tbeta/Windows-PS3EyeMuticam/addons/ofxNCore/src/Tracking/Tracking.h (revision 198)
18 18
#include "../Events/TouchMessenger.h"
19 19
#include "../Calibration/CalibrationUtils.h"
20 20

  
21

  
22

  
21 23
class BlobTracker : public TouchListener
22 24
{
23

  
24 25
public:
25 26

  
26 27
	BlobTracker();
......
31 32

  
32 33
	CalibrationUtils* calibrate;
33 34
	bool isCalibrating;
34
	int MIN_MOVEMENT_THRESHOLD;
35
	int MOVEMENT_FILTERING;
35 36
	std::map<int, Blob> getTrackedBlobs();
36 37

  
37 38
private:
branches/tbeta/Windows-PS3EyeMuticam/addons/ofxNCore/src/Controls/gui.h (revision 198)
41 41
	controls->mGlobals->mTextColor.b = 0;
42 42
	controls->mGlobals->mTextColor.a = 1;
43 43
	//button color
44
	controls->mGlobals->mButtonColor.r = .9;
45
	controls->mGlobals->mButtonColor.g = 1;
44
	controls->mGlobals->mButtonColor.r = 1;
45
	controls->mGlobals->mButtonColor.g = 0;
46 46
	controls->mGlobals->mButtonColor.b = 0;
47 47
	controls->mGlobals->mButtonColor.a = .8;
48 48
	//slider tip color
......
85 85
	ofxGuiPanel* trackPanel = controls->addPanel(appPtr->trackedPanel, "Tracked Image", 386, 270, OFXGUI_PANEL_BORDER, OFXGUI_PANEL_SPACING);
86 86
	trackPanel->addButton(appPtr->trackedPanel_darkblobs, "Inverse", OFXGUI_BUTTON_HEIGHT, OFXGUI_BUTTON_HEIGHT, kofxGui_Button_Off, kofxGui_Button_Switch, "");
87 87
	trackPanel->addSlider(appPtr->trackedPanel_threshold, "Image Threshold", 140, 13, 0.0f, 255.0f, filter->threshold, kofxGui_Display_Int, 0);
88
	trackPanel->addSlider(appPtr->trackedPanel_min_movement, "Movement Threshold", 140, 13, 0.0f, 15.0f, tracker.MIN_MOVEMENT_THRESHOLD, kofxGui_Display_Int, 0);
88
	trackPanel->addSlider(appPtr->trackedPanel_min_movement, "Movement Filtering", 140, 13, 0.0f, 15.0f, tracker.MOVEMENT_FILTERING, kofxGui_Display_Int, 0);
89 89
	trackPanel->addSlider(appPtr->trackedPanel_min_blob_size, "Min Blob Size", 140, 13, 1.0f, 500.0f, MIN_BLOB_SIZE, kofxGui_Display_Int, 0);
90 90
	trackPanel->addSlider(appPtr->trackedPanel_max_blob_size, "Max Blob Size", 140, 13, 1.0f, 1000.0f, MAX_BLOB_SIZE, kofxGui_Display_Int, 0);
91 91
	trackPanel->mObjHeight = 100;
......
197 197
	//Threshold
198 198
	controls->update(appPtr->trackedPanel_threshold, kofxGui_Set_Bool, &appPtr->filter->threshold, sizeof(float));
199 199
	//Min Movement
200
	controls->update(appPtr->trackedPanel_min_movement, kofxGui_Set_Bool, &appPtr->tracker.MIN_MOVEMENT_THRESHOLD, sizeof(float));
200
	controls->update(appPtr->trackedPanel_min_movement, kofxGui_Set_Bool, &appPtr->tracker.MOVEMENT_FILTERING, sizeof(float));
201 201
	//Min Blob Size
202 202
	controls->update(appPtr->trackedPanel_min_blob_size, kofxGui_Set_Bool, &appPtr->MIN_BLOB_SIZE, sizeof(float));
203 203
	//Max Blob Size
......
440 440
			break;
441 441
		case trackedPanel_min_movement:
442 442
			if(length == sizeof(float))
443
				tracker.MIN_MOVEMENT_THRESHOLD = *(float*)data;
443
				tracker.MOVEMENT_FILTERING = *(float*)data;
444 444
			break;
445 445
		case trackedPanel_min_blob_size:
446 446
			if(length == sizeof(float))
branches/tbeta/Windows-PS3EyeMuticam/addons/ofxNCore/src/Communication/TUIO.cpp (revision 198)
9 9

  
10 10
#include "TUIO.h"
11 11

  
12
TUIO::TUIO() {
12
TUIO::TUIO() 
13
{
13 14
}
14 15

  
15
TUIO::~TUIO() {
16

  
16
TUIO::~TUIO() 
17
{
17 18
	// this could be useful for whenever we get rid of an object
18 19
}
19 20

  
20
void TUIO::setup(const char* host, int port, int flashport) {
21

  
21
void TUIO::setup(const char* host, int port, int flashport) 
22
{
22 23
	localHost = host;
23 24
	TUIOPort = port;
24 25
	TUIOFlashPort = flashport;
25 26
	frameseq = 0;
26 27

  
27
	//FOR Flash/XML
28
	//FOR TCP
28 29
	bIsConnected = m_tcpServer.setup(TUIOFlashPort);
29 30
	//FOR OSC
30 31
	TUIOSocket.setup(localHost, TUIOPort);
......
34 35
{
35 36
	frameseq += 1;
36 37

  
37
	//if sending OSC (not TCP)
38
	if(bOSCMode){
39

  
38
	// if sending OSC (not TCP)
39
	if(bOSCMode)
40
	{
40 41
		ofxOscBundle b;
42
		ofxOscMessage alive;
43
		// Sends alive message - saying 'Hey, there's no alive blobs'
44
		alive.setAddress("/tuio/2Dcur");
45
		alive.addStringArg("alive");
41 46

  
47
		// Send fseq message
48
		ofxOscMessage fseq;
49
		fseq.setAddress( "/tuio/2Dcur" );
50
		fseq.addStringArg( "fseq" );
51
		fseq.addIntArg(frameseq);
52

  
42 53
		if(blobs->size() == 0)
43 54
		{
44
			ofxOscMessage source;
45
			source.setAddress("/tuio/2Dcur");
46
			source.addStringArg("source");
47
			source.addStringArg("CCV");
48
			
49
			//Sends alive message - saying 'Hey, there's no alive blobs'
50
			ofxOscMessage alive;
51
			alive.setAddress("/tuio/2Dcur");
52
			alive.addStringArg("alive");
53

  
54
			//Send fseq message
55
			ofxOscMessage fseq;
56
			fseq.setAddress("/tuio/2Dcur" );
57
			fseq.addStringArg( "fseq" );
58
			fseq.addIntArg(frameseq);
59

  
60
			b.addMessage( source ); //add message to bundle
61
			b.addMessage( alive ); //add message to bundle
62
			b.addMessage( fseq ); //add message to bundle
63
			TUIOSocket.sendBundle( b ); //send bundle
55
			b.addMessage( alive );		// add message to bundle
56
			b.addMessage( fseq );		// add message to bundle
57
			TUIOSocket.sendBundle( b ); // send bundle
64 58
		}
65
		else //actually send the blobs
59
		else // actually send the blobs
66 60
		{
67
			
68
			ofxOscMessage source;
69
			source.setAddress("/tuio/2Dcur");
70
			source.addStringArg("source");
71
			source.addStringArg("CCV");
72
			b.addMessage( source ); //add message to bundle
73
		
74
			//Send alive message of all alive IDs
75
			ofxOscMessage alive;
76
			alive.setAddress("/tuio/2Dcur");
77
			alive.addStringArg("alive");
78
			
79
			std::map<int, Blob>::iterator this_blobID;
80
			for(this_blobID = blobs->begin(); this_blobID != blobs->end(); this_blobID++)
61
			map<int, Blob>::iterator blob;
62
			for(blob = blobs->begin(); blob != blobs->end(); blob++)
81 63
			{
82
				alive.addIntArg(this_blobID->second.id); //Get list of ALL active IDs
83
			}
84
			
85
			b.addMessage( alive ); //add message to bundle
86
			
87
			map<int, Blob>::iterator this_blob;
88
			for(this_blob = blobs->begin(); this_blob != blobs->end(); this_blob++)
89
			{
64
				// omit point (0,0) since this means that we are outside of the range
65
				if(blob->second.centroid.x == 0 && blob->second.centroid.y == 0)
66
					continue;
67

  
90 68
				//Set Message
91 69
				ofxOscMessage set;
92
	
93 70
				set.setAddress( "/tuio/2Dcur" );
94 71
				set.addStringArg("set");
95
				set.addIntArg(this_blob->second.id); //id
96
				set.addFloatArg(this_blob->second.centroid.x);  // x
97
				set.addFloatArg(this_blob->second.centroid.y); // y
98
				set.addFloatArg(this_blob->second.D.x); //dX
99
				set.addFloatArg(this_blob->second.D.y); //dY
100
				set.addFloatArg(this_blob->second.maccel); //m
101
				// this proprietary message extension includes the ABB width & height
102
				if(bHeightWidth){
103
					set.addFloatArg(this_blob->second.boundingRect.width); // wd
104
					set.addFloatArg(this_blob->second.boundingRect.height);// ht
72
				set.addIntArg(blob->second.id);				// id
73
				set.addFloatArg(blob->second.centroid.x);	// x
74
				set.addFloatArg(blob->second.centroid.y);	// y
75
				set.addFloatArg(blob->second.D.x);			// dX
76
				set.addFloatArg(blob->second.D.y);			// dY
77
				set.addFloatArg(blob->second.maccel);		// m
78
				if(bHeightWidth)
79
				{
80
					set.addFloatArg(blob->second.boundingRect.width);	// wd
81
					set.addFloatArg(blob->second.boundingRect.height);	// ht
105 82
				}
106
				b.addMessage( set ); //add message to bundle
83
				b.addMessage( set );							// add message to bundle
84
				alive.addIntArg(blob->second.id);				// add blob to list of ALL active IDs
107 85
			}
108 86

  
87
// 			// Send alive message of all alive IDs
88
// 			ofxOscMessage alive;
89
// 			alive.setAddress("/tuio/2Dcur");
90
// 			alive.addStringArg("alive");
91

  
92
//			std::map<int, Blob>::iterator this_blobID;
93
//			for(this_blobID = blobs->begin(); this_blobID != blobs->end(); this_blobID++)
94
//			{
95
//				alive.addIntArg(this_blobID->second.id); //Get list of ALL active IDs
96
//			}
97

  
109 98
			//Send fseq message
110
			ofxOscMessage fseq;
111
			fseq.setAddress( "/tuio/2Dcur" );
112
			fseq.addStringArg( "fseq" );
113
			fseq.addIntArg(frameseq);
114
			b.addMessage( fseq ); //add message to bundle
99
//			ofxOscMessage fseq;
100
//			fseq.setAddress( "/tuio/2Dcur" );
101
//			fseq.addStringArg( "fseq" );
102
//			fseq.addIntArg(frameseq);
115 103

  
104
			b.addMessage( alive );		//add message to bundle
105
			b.addMessage( fseq );		//add message to bundle
116 106
			TUIOSocket.sendBundle( b ); //send bundle
117 107
		}
118

  
119
	}else if(bTCPMode) //else, if Flash/XML mode
108
	}
109
	else if(bTCPMode) // else, if TCP (flash) mode
120 110
	{
121
		if(blobs->size() == 0){
122

  
111
		if(blobs->size() == 0)
112
		{
123 113
			m_tcpServer.sendToAll("<OSCPACKET ADDRESS=\"127.0.0.1\" PORT=\""+ofToString(TUIOPort)+"\" TIME=\""+ofToString(ofGetElapsedTimef())+"\">" +
124 114
							 "<MESSAGE NAME=\"/tuio/2Dcur\">"+
125 115
							 "<ARGUMENT TYPE=\"s\" VALUE=\"alive\"/>"+
......
133 123
		else
134 124
		{
135 125
			string setBlobsMsg;
126
			string aliveBeginMsg = "<MESSAGE NAME=\"/tuio/2Dcur\"><ARGUMENT TYPE=\"s\" VALUE=\"alive\"/>";
127
			string aliveEndMsg = "</MESSAGE>";
128
			string aliveBlobsMsg;
136 129

  
137
			map<int, Blob>::iterator this_blob;
138
			for(this_blob = blobs->begin(); this_blob != blobs->end(); this_blob++)
130
			map<int, Blob>::iterator blob;
131
			for(blob = blobs->begin(); blob != blobs->end(); blob++)
139 132
			{
140
				//if sending height and width
141
				if(bHeightWidth){
142
					setBlobsMsg += "<MESSAGE NAME=\"/tuio/2Dcur\"><ARGUMENT TYPE=\"s\" VALUE=\"set\"/><ARGUMENT TYPE=\"i\" VALUE=\""+ofToString(this_blob->second.id)+"\"/>"+
143
					"<ARGUMENT TYPE=\"f\" VALUE=\""+ofToString(this_blob->second.centroid.x)+"\"/>"+
144
					"<ARGUMENT TYPE=\"f\" VALUE=\""+ofToString(this_blob->second.centroid.y)+"\"/>"+
145
					"<ARGUMENT TYPE=\"f\" VALUE=\""+ofToString(this_blob->second.D.x)+"\"/>"+
146
					"<ARGUMENT TYPE=\"f\" VALUE=\""+ofToString(this_blob->second.D.y)+"\"/>"+
147
					"<ARGUMENT TYPE=\"f\" VALUE=\""+ofToString(this_blob->second.maccel)+"\"/>"+
148
					"<ARGUMENT TYPE=\"f\" VALUE=\""+ofToString(this_blob->second.boundingRect.width)+"\"/>"+
149
					"<ARGUMENT TYPE=\"f\" VALUE=\""+ofToString(this_blob->second.boundingRect.height)+"\"/>"+
133
				// omit point (0,0) since this means that we are outside of the range
134
				if(blob->second.centroid.x == 0 && blob->second.centroid.y == 0)
135
					continue;
136

  
137
				// if sending height and width
138
				if(bHeightWidth)
139
				{
140
					setBlobsMsg += "<MESSAGE NAME=\"/tuio/2Dcur\"><ARGUMENT TYPE=\"s\" VALUE=\"set\"/><ARGUMENT TYPE=\"i\" VALUE=\""+ofToString(blob->second.id)+"\"/>"+
141
					"<ARGUMENT TYPE=\"f\" VALUE=\""+ofToString(blob->second.centroid.x)+"\"/>"+
142
					"<ARGUMENT TYPE=\"f\" VALUE=\""+ofToString(blob->second.centroid.y)+"\"/>"+
143
					"<ARGUMENT TYPE=\"f\" VALUE=\""+ofToString(blob->second.D.x)+"\"/>"+
144
					"<ARGUMENT TYPE=\"f\" VALUE=\""+ofToString(blob->second.D.y)+"\"/>"+
145
					"<ARGUMENT TYPE=\"f\" VALUE=\""+ofToString(blob->second.maccel)+"\"/>"+
146
					"<ARGUMENT TYPE=\"f\" VALUE=\""+ofToString(blob->second.boundingRect.width)+"\"/>"+
147
					"<ARGUMENT TYPE=\"f\" VALUE=\""+ofToString(blob->second.boundingRect.height)+"\"/>"+
150 148
					"</MESSAGE>";
151 149
				}
152
				else{
153
					setBlobsMsg += "<MESSAGE NAME=\"/tuio/2Dcur\"><ARGUMENT TYPE=\"s\" VALUE=\"set\"/><ARGUMENT TYPE=\"i\" VALUE=\""+ofToString(this_blob->second.id)+"\"/>"+
154
					"<ARGUMENT TYPE=\"f\" VALUE=\""+ofToString(this_blob->second.centroid.x)+"\"/>"+
155
					"<ARGUMENT TYPE=\"f\" VALUE=\""+ofToString(this_blob->second.centroid.y)+"\"/>"+
156
					"<ARGUMENT TYPE=\"f\" VALUE=\""+ofToString(this_blob->second.D.x)+"\"/>"+
157
					"<ARGUMENT TYPE=\"f\" VALUE=\""+ofToString(this_blob->second.D.y)+"\"/>"+
158
					"<ARGUMENT TYPE=\"f\" VALUE=\""+ofToString(this_blob->second.maccel)+"\"/>"+
150
				else
151
				{
152
					setBlobsMsg += "<MESSAGE NAME=\"/tuio/2Dcur\"><ARGUMENT TYPE=\"s\" VALUE=\"set\"/><ARGUMENT TYPE=\"i\" VALUE=\""+ofToString(blob->second.id)+"\"/>"+
153
					"<ARGUMENT TYPE=\"f\" VALUE=\""+ofToString(blob->second.centroid.x)+"\"/>"+
154
					"<ARGUMENT TYPE=\"f\" VALUE=\""+ofToString(blob->second.centroid.y)+"\"/>"+
155
					"<ARGUMENT TYPE=\"f\" VALUE=\""+ofToString(blob->second.D.x)+"\"/>"+
156
					"<ARGUMENT TYPE=\"f\" VALUE=\""+ofToString(blob->second.D.y)+"\"/>"+
157
					"<ARGUMENT TYPE=\"f\" VALUE=\""+ofToString(blob->second.maccel)+"\"/>"+
159 158
					"</MESSAGE>";
160 159
				}
160
				aliveBlobsMsg += "<ARGUMENT TYPE=\"i\" VALUE=\""+ofToString(blob->second.id)+"\"/>";
161 161
			}
162 162

  
163
			string aliveBeginMsg = "<MESSAGE NAME=\"/tuio/2Dcur\"><ARGUMENT TYPE=\"s\" VALUE=\"alive\"/>";
163
// 			std::map<int, Blob>::iterator this_blobID;
164
// 			for(this_blobID = blobs->begin(); this_blobID != blobs->end(); this_blobID++)
165
// 			{
166
// 				aliveBlobsMsg += "<ARGUMENT TYPE=\"i\" VALUE=\""+ofToString(this_blobID->second.id)+"\"/>";
167
// 			}
164 168

  
165
			string aliveBlobsMsg;
166
			std::map<int, Blob>::iterator this_blobID;
167
			for(this_blobID = blobs->begin(); this_blobID != blobs->end(); this_blobID++)
168
			{
169
				aliveBlobsMsg += "<ARGUMENT TYPE=\"i\" VALUE=\""+ofToString(this_blobID->second.id)+"\"/>";
170
			}
171

  
172
			string aliveEndMsg = "</MESSAGE>";
173

  
174
			string fseq = "<MESSAGE NAME=\"/tuio/2Dcur\"><ARGUMENT TYPE=\"s\" VALUE=\"fseq\"/><ARGUMENT TYPE=\"i\" VALUE=\""+ofToString(frameseq)+"\"/></MESSAGE>";
175

  
176
			m_tcpServer.sendToAll("<OSCPACKET ADDRESS=\"127.0.0.1\" PORT=\""+ofToString(TUIOPort)+"\" TIME=\""+ofToString(ofGetElapsedTimef())+"\">" +
169
			string fseq = "<MESSAGE NAME=\"/tuio/2Dcur\"><ARGUMENT TYPE=\"s\" VALUE=\"fseq\"/><ARGUMENT TYPE=\"i\" VALUE=\""+ofToString(frameseq) + "\"/></MESSAGE>";
170
			m_tcpServer.sendToAll("<OSCPACKET ADDRESS=\"127.0.0.1\" PORT=\"" + 
171
									ofToString(TUIOPort) + "\" TIME=\""+ofToString(ofGetElapsedTimef()) + "\">" +
177 172
									setBlobsMsg + aliveBeginMsg + aliveBlobsMsg + aliveEndMsg + fseq + "</OSCPACKET>");
178 173
		}
179 174
	}
branches/tbeta/Windows-PS3EyeMuticam/addons/ofxNCore/src/Communication/TUIO.h (revision 198)
14 14
#include "ofxOsc.h"
15 15
#include "ofxNetwork.h"
16 16

  
17
class TUIO {
18

  
17
class TUIO 
18
{
19 19
	public:		
20

  
21 20
		TUIO();
22 21
		~TUIO();
23 22
		
branches/tbeta/Windows-PS3EyeMuticam/addons/ofxNCore/src/Calibration/Calibration.cpp (revision 198)
34 34
	printf("Calibration is setup!\n\n");
35 35
}
36 36

  
37
void Calibration::passInContourFinder(int numBlobs, vector<Blob> blobs) {
38

  
37
void Calibration::passInContourFinder(int numBlobs, vector<Blob> blobs) 
38
{
39 39
    contourFinder.nBlobs = numBlobs;
40 40
	contourFinder.blobs  = blobs;
41 41
}
42 42

  
43
void Calibration::passInTracker(BlobTracker *trackerIn) {
43
void Calibration::passInTracker(BlobTracker *trackerIn) 
44
{
44 45
	tracker = trackerIn;
45 46
	tracker->passInCalibration(&calibrate);
46 47
}
......
49 50
/******************************
50 51
 *		  CALIBRATION
51 52
 *******************************/
52
void Calibration::doCalibration(){
53

  
53
void Calibration::doCalibration()
54
{
54 55
	//Change the background color to black
55 56
	ofSetColor(0x000000);
56 57
	ofFill();
......
81 82
	}
82 83
}
83 84

  
84
void Calibration::drawCalibrationPointsAndBox(){
85

  
85
void Calibration::drawCalibrationPointsAndBox()
86
{
86 87
    //this all has to do with getting the angle for loading circle
87 88
    arcAngle = 0;
88 89
	std::map<int, Blob> trackedBlobs;
......
128 129
		   calibrate.screenBB.getWidth() * ofGetWidth(), calibrate.screenBB.getHeight() * ofGetHeight());
129 130
}
130 131

  
131
void Calibration::drawCalibrationBlobs(){
132

  
132
void Calibration::drawCalibrationBlobs()
133
{
133 134
	//find blobs
134 135
	std::map<int, Blob> trackedBlobs;
135 136
	std::map<int, Blob>::iterator iter;
branches/tbeta/Windows-PS3EyeMuticam/addons/ofxNCore/src/Calibration/CalibrationUtils.cpp (revision 198)
19 19
	_camHeight = 240;
20 20
}
21 21

  
22
CalibrationUtils::~CalibrationUtils(){
23

  
22
CalibrationUtils::~CalibrationUtils()
23
{
24 24
    delete screenPoints;
25 25
	delete cameraPoints;
26 26
    delete triangles;
......
30 30
//--------------------------------------------------------------
31 31
//	Load Settings from the config.xml file
32 32
//--------------------------------------------------------------
33
void CalibrationUtils::loadXMLSettings(){
34

  
33
void CalibrationUtils::loadXMLSettings()
34
{
35 35
	bGoToNextStep = false;
36 36

  
37 37
	// Can this load via http?
38
	if( calibrationXML.loadFile("calibration.xml")){
38
	if( calibrationXML.loadFile("calibration.xml"))
39 39
		//WOOT!
40 40
		message = "Calibration Loaded!";
41
	}else{
41
	else
42 42
		//FAIL!
43 43
		message = "No calibration Found...";
44 44
		// GENERATE DEFAULT XML DATA WHICH WILL BE SAVED INTO THE CONFIG
45
	}
46 45

  
47 46
	bool bboxRoot = true;
48 47
	bool screenRoot = true;
......
57 56
	setGrid(GRID_X, GRID_Y);
58 57

  
59 58
	//Bounding Box Points
60
	if(bboxRoot){
59
	if(bboxRoot)
60
	{
61 61
	    vector2df ul(calibrationXML.getValue("SCREEN:BOUNDINGBOX:ulx", 0.000000),calibrationXML.getValue("SCREEN:BOUNDINGBOX:uly", 0.000000));
62 62
	    vector2df lr(calibrationXML.getValue("SCREEN:BOUNDINGBOX:lrx", 1.000000),calibrationXML.getValue("SCREEN:BOUNDINGBOX:lry", 1.000000));
63 63
		rect2df boundingbox(ul, lr);
64 64
		setScreenBBox(boundingbox);
65
	}else{
66
		setScreenScale(1.0f);
67 65
	}
66
	else
67
		setScreenScale(1.0f);
68 68

  
69 69
	//Calibration Points
70 70
	if(screenRoot)
......
72 72
		//lets see how many <STROKE> </STROKE> tags there are in the xml file
73 73
		int numDragTags = calibrationXML.getNumTags("SCREEN:POINT");
74 74

  
75
			//if there is at least one <POINT> tag we can read the list of points
76
			if(numDragTags > 0){
75
		//if there is at least one <POINT> tag we can read the list of points
76
		if(numDragTags > 0)
77
		{
78
			//we push into the last POINT tag this temporarirly treats the tag as the document root.
79
			calibrationXML.pushTag("SCREEN:POINT", numDragTags-1);
77 80

  
78
				//we push into the last POINT tag this temporarirly treats the tag as the document root.
79
				calibrationXML.pushTag("SCREEN:POINT", numDragTags-1);
81
			//we see how many points we have stored in <POINT> tags
82
			int numPtTags = calibrationXML.getNumTags("POINT");
80 83

  
81
				//we see how many points we have stored in <POINT> tags
82
				int numPtTags = calibrationXML.getNumTags("POINT");
83

  
84
			if(numPtTags > 0){
85

  
84
			if(numPtTags > 0)
85
			{
86 86
				//We then read those x y values into our array
87
				for(int i = 0; i < numPtTags; i++){
88

  
87
				for(int i = 0; i < numPtTags; i++)
88
				{
89 89
					//the last argument of getValue can be used to specify
90 90
					//which tag out of multiple tags you are refering to.
91 91
					int x = calibrationXML.getValue("POINT:X", 0.000000, i);
......
105 105

  
106 106
	//Set the camera calibated box.
107 107
	calculateBox();
108
	computeCameraToScreenMap();
108
//	computeCameraToScreenMap();
109 109
}
110 110

  
111 111

  
......
134 134
			float transformedX = (float)x;
135 135
			float transformedY = (float)y;
136 136

  
137
			//convert camera to screenspace for all possible camera positions
137
			//convert camera to screen space for all possible camera positions
138 138
			cameraToScreenSpace(transformedX, transformedY);
139
			//save these into a map of transformed camera to screenspace positions
139
			//save these into a map of transformed camera to screen space positions
140 140
			cameraToScreenMap[p] = vector2df(transformedX, transformedY);
141 141
			p++;
142 142
		}
......
157 157

  
158 158
	initTriangles();
159 159

  
160
	if(bscreenPoints && bcameraPoints){
161
	initScreenPoints();
162
	initCameraPoints(_camWidth, _camHeight);
160
	if(bscreenPoints && bcameraPoints)
161
	{
162
		initScreenPoints();
163
		initCameraPoints(_camWidth, _camHeight);
163 164
	}
164 165
}
165 166

  
......
169 170
	_camHeight = camHeight;
170 171
}
171 172

  
172
void CalibrationUtils::initTriangles(){
173

  
174
	int i,j;
173
void CalibrationUtils::initTriangles()
174
{
175 175
	int t = 0;
176

  
177
	for(j=0; j<GRID_Y; j++)
176
	for(int j = 0; j < GRID_Y; j++)
178 177
	{
179
		for(i=0; i<GRID_X; i++)
178
		for(int i = 0; i < GRID_X; i++)
180 179
		{
181 180
			triangles[t+0] = (i+0) + ((j+0) * (GRID_X+1));
182 181
			triangles[t+1] = (i+1) + ((j+0) * (GRID_X+1));
......
198 197
{
199 198
	int p = 0;
200 199

  
201
	int i,j;
202

  
203 200
	vector2df xd(screenBB.lowerRightCorner.X-screenBB.upperLeftCorner.X,0.0f);
204 201
	vector2df yd(0.0f, screenBB.lowerRightCorner.Y-screenBB.upperLeftCorner.Y);
205 202

  
206 203
	xd /= (float) GRID_X;
207 204
	yd /= (float) GRID_Y;
208 205

  
209
	for(j=0; j<=GRID_Y; j++)
206
	for(int j = 0; j <= GRID_Y; j++)
210 207
	{
211
		for(i=0; i<=GRID_X; i++)
208
		for(int i = 0; i <= GRID_X; i++)
212 209
		{
213 210
			screenPoints[p] = screenBB.upperLeftCorner + xd*i + yd*j;
214 211
			//printf("(%d, %d) = (%f, %f)\n", i, j, screenPoints[p].X, screenPoints[p].Y);
......
220 217
void CalibrationUtils::initCameraPoints(int camWidth, int camHeight)
221 218
{
222 219
	int p = 0;
223

  
224
	int i,j;
225
	for(j=0; j<=GRID_Y; j++)
220
	for(int j = 0; j <= GRID_Y; j++)
226 221
	{
227
		for(i=0; i<=GRID_X; i++)
222
		for(int i = 0; i <= GRID_X; i++)
228 223
		{
229 224
			cameraPoints[p] = vector2df((i * camWidth) / (float)GRID_X, (j * camHeight) / (float)GRID_Y);
230 225
			p++;
......
235 230
void CalibrationUtils::setScreenScale(float s)
236 231
{
237 232
	// legacy
238
	float offset = (1.0f - s)*0.5f;
233
	float offset = (1.0f - s) * 0.5f;
239 234
	screenBB = rect2df(vector2df(offset,offset),vector2df(1.0f-offset,1.0f-offset));
240 235
	initScreenPoints();
241 236
}
......
252 247

  
253 248
void CalibrationUtils::cameraToScreenPosition(float &x, float &y)
254 249
{
255
	//is this right to avoid boundingbox overflow? this overflow occurs due to new angle box
256
	if(y > _camHeight) y = _camHeight;
257
	if(y < 0) y = 0;
258
	if(x > _camWidth) x = _camWidth;
259
	if(x < 0) x = 0;
250
	cameraToScreenSpace(x, y);
260 251

  
261
	int pos = (int)y * (int)_camWidth + (int)x;
262

  
263
	x = cameraToScreenMap[pos].X;
264
	y = cameraToScreenMap[pos].Y;
265

  
266
	return;
252
	//is this right to avoid boundingbox overflow? this overflow occurs due to new angle box
253
// 	if(y > _camHeight) y = _camHeight;
254
// 	if(y < 0) y = 0;
255
// 	if(x > _camWidth) x = _camWidth;
256
// 	if(x < 0) x = 0;
257
// 
258
// 	int pos = (int)y * (int)_camWidth + (int)x;
259
// 
260
// 	x = cameraToScreenMap[pos].X;
261
// 	y = cameraToScreenMap[pos].Y;
267 262
}
268 263

  
269 264
void CalibrationUtils::transformDimension(float &width, float &height)
......
276 271
	float centerX = ((maxBoxX - minBoxX)/2) + minBoxX;
277 272
	float centerY = ((maxBoxY - minBoxY)/2) + minBoxY;
278 273

  
279
	//Calculate x/y position of upperleft and lowerright x/y positions
274
	//Calculate x/y position of upper left and lower right x/y positions
280 275
    float ulX = centerX - halfX;
281 276
    float ulY = centerY - halfY;
282 277
    float lrX = centerX + halfX;
283 278
    float lrY = centerY + halfY;
284 279

  
285
	//Transform these x/y positions to screenspace
280
	//Transform these x/y positions to screen space
286 281
	cameraToScreenPosition(ulX, ulY);
287 282
	cameraToScreenPosition(lrX, lrY);
288 283

  
......
298 293
	minBoxX = _camWidth;
299 294
	maxBoxY = 0;
300 295
	minBoxY = _camHeight;
301

  
302
	//Calculate the max/min points based on cameraPoints
303
	for(int i = 0; i < GRID_POINTS; i++){
304

  
305
		if(cameraPoints[i].X > maxBoxX){
306

  
307
			maxBoxX = cameraPoints[i].X;
308
		}
309
		else if(cameraPoints[i].X < minBoxX){
310

  
311
			minBoxX = cameraPoints[i].X;
312
		}
313
		if(cameraPoints[i].Y > maxBoxY){
314

  
315
			maxBoxY = cameraPoints[i].Y;
316
		}
317
		if(cameraPoints[i].Y < minBoxY){
318

  
319
			minBoxY = cameraPoints[i].Y;
320
		}
296
	// Calculate the max/min points based on cameraPoints
297
	for(int i = 0; i < GRID_POINTS; i++)
298
	{
299
		if(cameraPoints[i].X > maxBoxX)			maxBoxX = cameraPoints[i].X;
300
		else if(cameraPoints[i].X < minBoxX)	minBoxX = cameraPoints[i].X;
301
		if(cameraPoints[i].Y > maxBoxY)			maxBoxY = cameraPoints[i].Y;
302
		else if(cameraPoints[i].Y < minBoxY)	minBoxY = cameraPoints[i].Y;
321 303
	}
322 304
}
323 305

  
......
325 307
void CalibrationUtils::cameraToScreenSpace(float &x, float &y)
326 308
{
327 309
	vector2df pt(x, y);
328

  
329 310
	int t = findTriangleWithin(pt);
330

  
331 311
	if(t != -1)
332 312
	{
333 313
		vector2df A = cameraPoints[triangles[t+0]];
......
357 337
		y = transformedPos.Y;
358 338
		return;
359 339
	}
360

  
361 340
	x = 0;
362 341
	y = 0;
363 342
	// FIXME: what to do in the case that it's outside the mesh?
......
373 352

  
374 353
int CalibrationUtils::findTriangleWithin(vector2df pt)
375 354
{
376
	int t;
377

  
378
	for(t=0; t<GRID_INDICES; t+=3)
355
	for(int t = 0; t < GRID_INDICES; t += 3)
379 356
	{
380
		if( isPointInTriangle(pt, cameraPoints[triangles[t]], cameraPoints[triangles[t+1]], cameraPoints[triangles[t+2]]) )
381
		{
357
		if(isPointInTriangle(pt, cameraPoints[triangles[t]], cameraPoints[triangles[t+1]], cameraPoints[triangles[t+2]]) )
382 358
			return t;
383
		}
384 359
	}
385

  
386 360
	return -1;
387 361
}
388 362

  
......
397 371
	if(bCalibrating)
398 372
	{
399 373
		calibrationStep++;
400

  
401 374
		if(calibrationStep >= GRID_POINTS)
402 375
		{
403 376
			bCalibrating = false;
404 377
			calibrationStep = 0;
405 378
			saveCalibration();
406 379
			calculateBox();
407
			computeCameraToScreenMap();
380
// 			computeCameraToScreenMap();
408 381

  
409 382
            saveCalibration();
410 383
		}
......
432 405
	int numDragTags = calibrationXML.getNumTags("SCREEN:POINT");
433 406

  
434 407
	//if there is at least one <POINT> tag we can read the list of points
435
	if(numDragTags > 0){
436

  
408
	if(numDragTags > 0)
409
	{
437 410
		//we push into the last POINT tag this temporarirly treats the tag as the document root.
438 411
		calibrationXML.pushTag("SCREEN:POINT", numDragTags-1);
439 412

  
......
450 423
		calibrationXML.setValue("BOUNDINGBOX:lry", screenBB.lowerRightCorner.Y);
451 424

  
452 425
		//Save all the Calibration Points
453
		if(GRID_POINTS > 0){
454

  
426
		if(GRID_POINTS > 0)
427
		{
455 428
			//We then read those x y values into our array
456
			for(int i = 0; i < GRID_POINTS; i++){
457

  
429
			for(int i = 0; i < GRID_POINTS; i++)
430
			{
458 431
				//the last argument of getValue can be used to specify
459 432
				//which tag out of multiple tags you are refering to.
460 433
				calibrationXML.setValue("POINT:X", cameraPoints[i].X, i);
branches/tbeta/Windows-PS3EyeMuticam/addons/ofxNCore/src/Modules/ofxNCoreVision.h (revision 198)
35 35

  
36 36
class ofxNCoreVision : public ofxGuiListener
37 37
{
38
	//ofxGUI setup stuff
38
	// ofxGUI setup stuff
39 39
	enum
40 40
	{
41 41
		propertiesPanel,
......
154 154
	{
155 155
		// AlexP
156 156
		// C++ guarantees that operator delete checks its argument for null-ness
157
		delete filter;		filter=NULL;
158
		delete vidGrabber;	vidGrabber=NULL;
159
		delete vidPlayer;	vidPlayer=NULL;
157
		delete filter;		filter = NULL;
158
		delete vidGrabber;	vidGrabber = NULL;
159
		delete vidPlayer;	vidPlayer = NULL;
160 160
		#ifdef TARGET_WIN32
161
			delete PS3;		PS3=NULL;
162
			delete ffmv; 	ffmv=NULL;
163
			delete dsvl;	dsvl=NULL;
161
		delete PS3;		PS3 = NULL;
162
		delete ffmv; 	ffmv = NULL;
163
		delete dsvl;	dsvl = NULL;
164 164
		#endif
165 165
	}
166 166

  
branches/tbeta/Windows-PS3EyeMuticam/addons/ofxNCore/src/Modules/ofxNCoreVision.cpp (revision 198)
1
/*
2
*  ofxNCoreVision.cpp
3
*  NUI Group Community Core Vision
4
*
5
*  Created by NUI Group Dev Team A on 2/1/09.
6
*  Copyright 2009 NUI Group. All rights reserved.
7
*
8
*/
9

  
10
#include "ofxNCoreVision.h"
11
#include "../Controls/gui.h"
12

  
13
/******************************************************************************
14
* The setup function is run once to perform initializations in the application
15
*****************************************************************************/
16
void ofxNCoreVision::_setup(ofEventArgs &e)
17
{	
18
	//set the title
19
	ofSetWindowTitle(" Community Core Vision ");
20
	
21
	//create filter
22
	if ( filter == NULL )	filter = new ProcessFilters();
23
	
24
	//Load Settings from config.xml file
25
	loadXMLSettings();
26

  
27
	//Setup Window Properties
28
	ofSetWindowShape(winWidth,winHeight);
29
	ofSetVerticalSync(false);	            //Set vertical sync to false for better performance?
30
	
31
	//printf("Application Loaded...\n?");
32

  
33
	//load camera/video
34
	initDevice();
35
	//set framerate
36
	ofSetFrameRate(camRate * 1.3);			//This will be based on camera fps in the future
37

  
38
	/*****************************************************************************************************
39
	* Allocate images (needed for drawing/processing images)
40
	******************************************************************************************************/
41
	processedImg.allocate(camWidth, camHeight); //main Image that'll be processed.
42
	processedImg.setUseTexture(false);			//We don't need to draw this so don't create a texture
43
	sourceImg.allocate(camWidth, camHeight);    //Source Image
44
	sourceImg.setUseTexture(false);				//We don't need to draw this so don't create a texture
45
	/******************************************************************************************************/
46
	//printf("Cameras Loaded...\n");
47

  
48
	//Fonts - Is there a way to dynamically change font size?
49
	verdana.loadFont("verdana.ttf", 8, true, true);	   //Font used for small images
50
	bigvideo.loadFont("verdana.ttf", 13, true, true);  //Font used for big images.
51

  
52
	//Static Images
53
	background.loadImage("images/background.jpg"); //Main (Temp?) Background
54
	//printf("freedom3?");
55
	
56
	//GUI Controls
57
	controls = ofxGui::Instance(this);
58
	setupControls();
59
	
60
	//printf("Controls Loaded...\n");
61

  
62
	//Setup Calibration
63
	calib.setup(camWidth, camHeight, &tracker);
64

  
65
	//Allocate Filters
66
	filter->allocate( camWidth, camHeight );
67

  
68
	/*****************************************************************************************************
69
	* Startup Modes
70
	******************************************************************************************************/
71
	//If Standalone Mode (not an addon)
72
	if (bStandaloneMode)
73
	{
74
		printf("Starting in standalone mode...\n\n");
75
		showConfiguration = true;
76
	}
77
	if (bMiniMode)
78
	{
79
		showConfiguration = true;
80
		bShowInterface = false;
81
		printf("Starting in Mini Mode...\n\n");
82
		ofSetWindowShape(190, 200); //minimized size
83
		filter->bMiniMode = bMiniMode;
84
	}
85
	else
86
	{
87
		bShowInterface = true;
88
		printf("Starting in full mode...\n\n");
89
	}
90
	
91
	#ifdef TARGET_WIN32
92
	    //get rid of the console window
93
        FreeConsole();
94
	#endif
95

  
96
	printf("Community Core Vision is setup!\n\n");
97
}
98

  
99
/****************************************************************
100
*	Load/Save config.xml file Settings
101
****************************************************************/
102
void ofxNCoreVision::loadXMLSettings()
103
{
104
	// TODO: a seperate XML to map keyboard commands to action
105
	message = "Loading config.xml...";
106
	// Can this load via http?
107
	if ( XML.loadFile("config.xml"))
108
		message = "Settings Loaded!\n\n";
109
	else
110
		message = "No Settings Found...\n\n"; //FAIL
111
	
112
	//--------------------------------------------------------------
113
	//  START BINDING XML TO VARS
114
	//--------------------------------------------------------------
115
	winWidth					= XML.getValue("CONFIG:WINDOW:WIDTH", 950);
116
	winHeight					= XML.getValue("CONFIG:WINDOW:HEIGHT", 600);
117
	bcamera						= XML.getValue("CONFIG:CAMERA_0:USECAMERA", 1);
118
	deviceID					= XML.getValue("CONFIG:CAMERA_0:DEVICE", 0);
119
	camWidth					= XML.getValue("CONFIG:CAMERA_0:WIDTH", 320);
120
	camHeight					= XML.getValue("CONFIG:CAMERA_0:HEIGHT", 240);
121
	camRate						= XML.getValue("CONFIG:CAMERA_0:FRAMERATE", 0);
122
	videoFileName				= XML.getValue("CONFIG:VIDEO:FILENAME", "test_videos/RearDI.m4v");
123
	maxBlobs					= XML.getValue("CONFIG:BLOBS:MAXNUMBER", 20);
124
	bShowLabels					= XML.getValue("CONFIG:BOOLEAN:LABELS",0);
125
	bDrawOutlines				= XML.getValue("CONFIG:BOOLEAN:OUTLINES",0);
126
	filter->bLearnBakground		= XML.getValue("CONFIG:BOOLEAN:LEARNBG",0);
127
	filter->bVerticalMirror		= XML.getValue("CONFIG:BOOLEAN:VMIRROR",0);
128
	filter->bHorizontalMirror	= XML.getValue("CONFIG:BOOLEAN:HMIRROR",0);
129
	
130
	//Filters
131
	filter->bTrackDark			= XML.getValue("CONFIG:BOOLEAN:TRACKDARK", 0);
132
	filter->bHighpass			= XML.getValue("CONFIG:BOOLEAN:HIGHPASS",1);
133
	filter->bAmplify			= XML.getValue("CONFIG:BOOLEAN:AMPLIFY", 1);
134
	filter->bSmooth				= XML.getValue("CONFIG:BOOLEAN:SMOOTH", 1);
135
	filter->bDynamicBG			= XML.getValue("CONFIG:BOOLEAN:DYNAMICBG", 1);
136
	//MODES
137
	bGPUMode					= XML.getValue("CONFIG:BOOLEAN:GPU", 0);
138
	bMiniMode                   = XML.getValue("CONFIG:BOOLEAN:MINIMODE",0);
139
	//CONTROLS
140
	tracker.MIN_MOVEMENT_THRESHOLD	= XML.getValue("CONFIG:INT:MINMOVEMENT",0);
141
	MIN_BLOB_SIZE				= XML.getValue("CONFIG:INT:MINBLOBSIZE",2);
142
	MAX_BLOB_SIZE				= XML.getValue("CONFIG:INT:MAXBLOBSIZE",100);
143
	backgroundLearnRate			= XML.getValue("CONFIG:INT:BGLEARNRATE", 0.01f);
144
	//Filter Settings
145
	filter->threshold			= XML.getValue("CONFIG:INT:THRESHOLD",0);
146
	filter->highpassBlur		= XML.getValue("CONFIG:INT:HIGHPASSBLUR",0);
147
	filter->highpassNoise		= XML.getValue("CONFIG:INT:HIGHPASSNOISE",0);
148
	filter->highpassAmp			= XML.getValue("CONFIG:INT:HIGHPASSAMP",0);
149
	filter->smooth				= XML.getValue("CONFIG:INT:SMOOTH",0);
150
	//NETWORK SETTINGS
151
	bTUIOMode					= XML.getValue("CONFIG:BOOLEAN:TUIO",0);
152
	myTUIO.bOSCMode				= XML.getValue("CONFIG:BOOLEAN:OSCMODE",1);
153
	myTUIO.bTCPMode				= XML.getValue("CONFIG:BOOLEAN:TCPMODE",1);
154
	myTUIO.bHeightWidth			= XML.getValue("CONFIG:BOOLEAN:HEIGHTWIDTH",0);
155
	tmpLocalHost				= XML.getValue("CONFIG:NETWORK:LOCALHOST", "localhost");
156
	tmpPort						= XML.getValue("CONFIG:NETWORK:TUIOPORT_OUT", 3333); 
157
	tmpFlashPort				= XML.getValue("CONFIG:NETWORK:TUIOFLASHPORT_OUT", 3000);
158
	myTUIO.setup(tmpLocalHost.c_str(), tmpPort, tmpFlashPort); //have to convert tmpLocalHost to a const char*	
159
	//--------------------------------------------------------------
160
	//  END XML SETUP
161
}
162

  
163
void ofxNCoreVision::saveSettings()
164
{
165
	XML.setValue("CONFIG:CAMERA_0:USECAMERA", bcamera);
166
	XML.setValue("CONFIG:CAMERA_0:DEVICE", deviceID);
167
	XML.setValue("CONFIG:CAMERA_0:WIDTH", camWidth);
168
	XML.setValue("CONFIG:CAMERA_0:HEIGHT", camHeight);
169
	XML.setValue("CONFIG:CAMERA_0:FRAMERATE", camRate);
170
	XML.setValue("CONFIG:BOOLEAN:PRESSURE",bShowPressure);
171
	XML.setValue("CONFIG:BOOLEAN:LABELS",bShowLabels);
172
	XML.setValue("CONFIG:BOOLEAN:OUTLINES",bDrawOutlines);
173
	XML.setValue("CONFIG:BOOLEAN:LEARNBG", filter->bLearnBakground);
174
	XML.setValue("CONFIG:BOOLEAN:VMIRROR", filter->bVerticalMirror);
175
	XML.setValue("CONFIG:BOOLEAN:HMIRROR", filter->bHorizontalMirror);
176
	XML.setValue("CONFIG:BOOLEAN:TRACKDARK", filter->bTrackDark);
177
	XML.setValue("CONFIG:BOOLEAN:HIGHPASS", filter->bHighpass);
178
	XML.setValue("CONFIG:BOOLEAN:AMPLIFY", filter->bAmplify);
179
	XML.setValue("CONFIG:BOOLEAN:SMOOTH", filter->bSmooth);
180
	XML.setValue("CONFIG:BOOLEAN:DYNAMICBG", filter->bDynamicBG);
181
	XML.setValue("CONFIG:BOOLEAN:GPU", bGPUMode);
182
	XML.setValue("CONFIG:INT:MINMOVEMENT", tracker.MIN_MOVEMENT_THRESHOLD);
183
	XML.setValue("CONFIG:INT:MINBLOBSIZE", MIN_BLOB_SIZE);
184
	XML.setValue("CONFIG:INT:MAXBLOBSIZE", MAX_BLOB_SIZE);
185
	XML.setValue("CONFIG:INT:BGLEARNRATE", backgroundLearnRate);
186
	XML.setValue("CONFIG:INT:THRESHOLD", filter->threshold);
187
	XML.setValue("CONFIG:INT:HIGHPASSBLUR", filter->highpassBlur);
188
	XML.setValue("CONFIG:INT:HIGHPASSNOISE", filter->highpassNoise);
189
	XML.setValue("CONFIG:INT:HIGHPASSAMP", filter->highpassAmp);
190
	XML.setValue("CONFIG:INT:SMOOTH", filter->smooth);
191
	XML.setValue("CONFIG:BOOLEAN:MINIMODE", bMiniMode);
192
	XML.setValue("CONFIG:BOOLEAN:TUIO",bTUIOMode);
193
	XML.setValue("CONFIG:BOOLEAN:HEIGHTWIDTH", myTUIO.bHeightWidth);
194
	XML.setValue("CONFIG:BOOLEAN:OSCMODE", myTUIO.bOSCMode);
195
	XML.setValue("CONFIG:BOOLEAN:TCPMODE", myTUIO.bTCPMode);
196
//	XML.setValue("CONFIG:NETWORK:LOCALHOST", myTUIO.localHost);
197
//	XML.setValue("CONFIG:NETWORK:TUIO_PORT_OUT",myTUIO.TUIOPort);
198
	XML.saveFile("config.xml");
199
}
200

  
201
/************************************************
202
*				Init Device
203
************************************************/
204
//Init Device (camera/video)
205
void ofxNCoreVision::initDevice()
206
{
207
	//Pick the Source - camera or video
208
	if (bcamera)
209
	{
210
		//check if a firefly, ps3 camera, or other is plugged in
211
		#ifdef TARGET_WIN32
212
			/****PS3 - PS3 camera only****/
213
		    if(ofxPS3::getDeviceCount() > 0 && PS3 == NULL)
214
			{
215
				PS3 = new ofxPS3();
216
				PS3->listDevices();
217
				PS3->initPS3(camWidth, camHeight, camRate);
218
				camWidth = PS3->getCamWidth();
219
			    camHeight = PS3->getCamHeight();
220
				printf("Camera Mode\nAsked for %i by %i - actual size is %i by %i \n\n", camWidth, camHeight, PS3->getCamWidth(), PS3->getCamHeight());
221
				return;
222
			}
223
			/****ffmv - firefly camera only****/
224
			else if(ofxffmv::getDeviceCount() > 0 && ffmv == NULL)
225
			{
226
			   ffmv = new ofxffmv();
227
			   ffmv->listDevices();
228
			   ffmv->initFFMV(camWidth,camHeight);
229
			   printf("Camera Mode\nAsked for %i by %i - actual size is %i by %i \n\n", camWidth, camHeight, ffmv->getCamWidth(), ffmv->getCamHeight());
230
			   camWidth = ffmv->getCamWidth();
231
			   camHeight = ffmv->getCamHeight();
232
			   return;
233
			}
234
			else if( vidGrabber == NULL ) 
235
			{
236
				vidGrabber = new ofVideoGrabber();
237
				vidGrabber->listDevices();
238
				vidGrabber->setVerbose(true);
239
				vidGrabber->initGrabber(camWidth,camHeight);
240
				printf("Camera Mode\nAsked for %i by %i - actual size is %i by %i \n\n", camWidth, camHeight, vidGrabber->width, vidGrabber->height);
241
				camWidth = vidGrabber->width;
242
				camHeight = vidGrabber->height;
243
				return;
244
			}
245
			else if( dsvl == NULL) 
246
			{
247
				dsvl = new ofxDSVL();
248
				dsvl->initDSVL();
249
				printf("Camera Mode\nAsked for %i by %i - actual size is %i by %i \n\n", camWidth, camHeight, dsvl->getCamWidth(), dsvl->getCamHeight());
250
				camWidth = dsvl->getCamWidth();
251
				camHeight = dsvl->getCamHeight();
252
				return;
253
			}
254
		#else 
255
			if( vidGrabber == NULL ) 
256
			{
257
				vidGrabber = new ofVideoGrabber();
258
				vidGrabber->listDevices();
259
				vidGrabber->setVerbose(true);
260
				vidGrabber->initGrabber(camWidth,camHeight);
261
				printf("Camera Mode\nAsked for %i by %i - actual size is %i by %i \n\n", camWidth, camHeight, vidGrabber->width, vidGrabber->height);
262
				camWidth = vidGrabber->width;
263
				camHeight = vidGrabber->height;
264
				return;
265
			}
266
		#endif
267
	}
268
	else
269
	{
270
		if( vidPlayer == NULL ) 
271
		{
272
            vidPlayer = new ofVideoPlayer();
273
            vidPlayer->loadMovie( videoFileName );
274
            vidPlayer->play();
275
            vidPlayer->setLoopState(OF_LOOP_NORMAL);
276
			printf("Video Mode\n\n");
277
			camHeight = vidPlayer->height;
278
			camWidth = vidPlayer->width;
279
			return;
280
        }
281
	}
282
}
283

  
284
/******************************************************************************
285
* The update function runs continuously. Use it to update states and variables
286
*****************************************************************************/
287
void ofxNCoreVision::_update(ofEventArgs &e)
288
{
289
	bNewFrame = false;
290

  
291
	if(bcamera) //if camera
292
	{
293
		#ifdef TARGET_WIN32
294
			if(PS3!=NULL)//ps3 camera
295
			{
296
				bNewFrame = PS3->isFrameNew();
297
			}
298
			else if(ffmv!=NULL)
299
			{
300
				ffmv->grabFrame();
301
				bNewFrame = true;
302
			}
303
			else if(vidGrabber !=NULL)
304
			{
305
				vidGrabber->grabFrame();
306
				bNewFrame = vidGrabber->isFrameNew();
307
			}
308
			else if(dsvl !=NULL)
309
			{
310
				bNewFrame = dsvl->isFrameNew();
311
			}
312
		#else
313
			vidGrabber->grabFrame();
314
			bNewFrame = vidGrabber->isFrameNew();
315
		#endif
316
	}
317
	else //if video
318
	{
319
		vidPlayer->idleMovie();
320
		bNewFrame = vidPlayer->isFrameNew();
321
	}
322

  
323
	//if no new frame, return
324
	if(!bNewFrame)
325
	{
326
		return;
327
	}
328
	else//else process camera frame
329
	{
330
		ofBackground(0, 0, 0);
331

  
332
		// Calculate FPS of Camera
333
		frames++;
334
		float time = ofGetElapsedTimeMillis();
335
		if (time > (lastFPSlog + 1000))
336
		{
337
			fps = frames;
338
			frames = 0;
339
			lastFPSlog = time;
340
		}//End calculation
341

  
342
		float beforeTime = ofGetElapsedTimeMillis();
343

  
344
		if (bGPUMode)
345
		{
346
			grabFrameToGPU(filter->gpuSourceTex);
347
			filter->applyGPUFilters();
348
			contourFinder.findContours(filter->gpuReadBackImageGS,  (MIN_BLOB_SIZE * 2) + 1, ((camWidth * camHeight) * .4) * (MAX_BLOB_SIZE * .001), maxBlobs, false);
349
		}
350
		else
351
		{
352
			grabFrameToCPU();
353
			filter->applyCPUFilters( processedImg );
354
			contourFinder.findContours(processedImg,  (MIN_BLOB_SIZE * 2) + 1, ((camWidth * camHeight) * .4) * (MAX_BLOB_SIZE * .001), maxBlobs, false);
355
		}
356

  
357
		//Track found contours/blobss
358
		tracker.track(&contourFinder);
359
		//get DSP time
360
		differenceTime = ofGetElapsedTimeMillis() - beforeTime;
361

  
362
		//Dynamic Background subtraction LearRate
363
		if (filter->bDynamicBG)
364
		{
365
			filter->fLearnRate = backgroundLearnRate * .0001; //If there are no blobs, add the background faster.
366
			if (contourFinder.nBlobs > 0) //If there ARE blobs, add the background slower.
367
			{
368
				filter->fLearnRate = backgroundLearnRate * .0001;
369
			}
370
		}//End Background Learning rate
371

  
372
		if (bTUIOMode)
373
		{
374
			//Start sending OSC
375
			myTUIO.sendTUIO(&getBlobs());
376
		}
377
	}
378
}
379

  
380

  
381
/************************************************
382
*				Input Device Stuff
383
************************************************/
384
//get pixels from camera
385
void ofxNCoreVision::getPixels()
386
{
387
#ifdef TARGET_WIN32
388
	if(PS3!=NULL)
389
	{
390
		//already grayscale
391
		processedImg.setFromPixels(PS3->getPixels(), camWidth, camHeight);
392
	}
393
	else if(ffmv != NULL)
394
	{
395
		processedImg.setFromPixels(ffmv->fcImage[ffmv->getDeviceID()].pData, camWidth, camHeight);
396
	}
397
	else if(vidGrabber != NULL ) 
398
	{
399
		sourceImg.setFromPixels(vidGrabber->getPixels(), camWidth, camHeight);
400
		//convert to grayscale
401
		processedImg = sourceImg;
402
	}
403
	else if(dsvl!=NULL)
404
	{
405
		if(dsvl->getNumByes() != 1)
406
		{ 	
407
			//if not grayscale
408
			sourceImg.setFromPixels(dsvl->getPixels(), camWidth, camHeight);
409
			//convert to grayscale
410
			processedImg = sourceImg;
411
		}
412
		else
413
		{	//if grayscale
414
			processedImg.setFromPixels(dsvl->getPixels(), camWidth, camHeight);
415
		}
416
	}
417
#endif	
418
}
419

  
420

  
421
//Grab frame from CPU
422
void ofxNCoreVision::grabFrameToCPU()
423
{
424
	//Set sourceImg as new camera/video frame
425
	if (bcamera)
426
	{
427
	    #ifdef TARGET_WIN32
428
			getPixels();
429
 		#else
430
            sourceImg.setFromPixels(vidGrabber->getPixels(), camWidth, camHeight);
431
 			//convert to grayscale
432
 			processedImg = sourceImg;
433
 		#endif
434
	}
435
	else
436
	{
437
		sourceImg.setFromPixels(vidPlayer->getPixels(), camWidth, camHeight);
438
		//convert to grayscale
439
		processedImg = sourceImg;
440
	}
441
}
442

  
443
//Grab frame from GPU
444
void ofxNCoreVision::grabFrameToGPU(GLuint target)
445
{
446
	//grab the frame to a raw openGL texture
447
	if (bcamera)
448
	{
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff