Esempio n. 1
0
void Vehicle::_matchExistingFrameBlobwWithCurrentFrameBlob(vector <Blob> &existingBlob, vector <Blob> &currentBlob)
{
	for (int i = 0; i < existingBlob.size(); i++) {
	
		//add some boolean
		existingBlob[i].blnCurrentMatchFoundOrNewBlob = false;

		existingBlob[i].predictNextPosition();
	}

	for (int i = 0; i < currentBlob.size(); i++) {
	
		int indexOfMinDist = 0;
		
		double minDist = 10000.0;
		
		for (unsigned int i = 0; i < existingBlob.size(); i++) {
		
			if (existingBlob[i].existingStillBeingTracked == true) {
			
				double distance = distanceBetweenPoints(currentBlob[i].centerPositions.back(), existingBlob[i].predictedNextPosition);
				
				if (distance < minDist) {
				
					minDist = distance;
					indexOfMinDist = i;
				}
			
			}
		}

		if (minDist < currentBlob[i].DiagonalSize*1.15) {
		
			addBlobToExistingBlobs(currentBlob[i],existingBlob,indexOfMinDist);
		}
		else {
		
			addNewBlob(currentBlob[i], existingBlob);
		}
	}
	
	for (int i = 0; i < existingBlob.size(); i++) {
	
		if (existingBlob[i].blnCurrentMatchFoundOrNewBlob == false) {
			existingBlob[i].intNumOfConsecutiveFramesWithoutAMatch++;
		}

		if (existingBlob[i].intNumOfConsecutiveFramesWithoutAMatch >= 5) {
			existingBlob[i].existingStillBeingTracked = false;
		}


	}
}
Esempio n. 2
0
//--------------------------------------------------------------
void testApp::setup(){
	
	oclx1 = ofGetWidth()* 4/16;
	oclx2 = ofGetWidth()*11/16;
	oclw  = ofGetWidth()   /16;

	ofBackground(0);
	ofEnableAlphaBlending();
	ofSetCircleResolution(36);

	ofSetFrameRate(5);

	nextStep = false;
	stepByStep = false;

	for(int i=0; i<5; i++) addNewBlob();
}
Esempio n. 3
0
//--------------------------------------------------------------
void testApp::update(){
	
	if(stepByStep && !nextStep) return;

	if(!B.size() || (B.size() < 10 && ofRandom(0.0, 100.0) > 99.5)) 
		addNewBlob();

	// random kill first 
	if(B.size() >= 5 && ofRandom(0.0, 100.0) > 99.5) {
		B.erase(B.begin());
		T.erase(T.begin());
	}

	for (int i=0; i<B.size(); i++) {
		ofPoint& bc = B[i].center;
		ofPoint  D  = T[i]-bc;
		D.normalize();
		float    v  = 50.0;
		
		B[i].velocity += (D*v-B[i].velocity)/100.0;
		
		B[i].center += B[i].velocity;
		B[i].rect.setFromCenter(B[i].center, B[i].rect.width, B[i].rect.height);

		T[i].x +=B[i].velocity.y*v/200.0;
		T[i].y -=B[i].velocity.x*v/200.0;
	
		if(ofRandom(0.0, 100.0) > 99.85) 
			T[i] = ofPoint( ofRandom(ofGetWidth()), ofRandom(ofGetHeight()));
	}

	vector<Face> b;
	// occlude  blobs
	for (int i=0; i< B.size(); i++) {
		float x = B[i].center.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);
	
	nextStep = false;
}