Ejemplo n.º 1
0
 void operator() ( Buffer< SampleType > &_buffer ) {
   if ( is_end ) {
     fillZero ( _buffer );
     return;
   }
   double time = instrument.getGlobalTime();
   while ( !release_stack.empty() && time - release_stack.top().first >= -0.00001f ) {
     instrument.noteOff ( release_stack.top().second );
     release_stack.pop();
   }
   while ( time - current_score->pos >= -0.00001f ) {
     if ( current_score->length == 0.0f ) {
       is_end = true;
       fillZero ( _buffer );
       return;
     }
     else {
       std::pair< double, int > temp;
       temp.first = current_score->pos + current_score->length;
       temp.second = instrument.noteOn ( current_score->note, exp2f ( ( current_score->touch - 1.0f ) * 10.0f ) );
       release_stack.push ( temp );
     }
     current_score++;
   }
   instrument ( _buffer );
 }
void BlobDetectionEngine::runMatching(bool **bgMask, int ****bins, int *time)
{
	curHypNum = numOfRegions;
	//@At that frame, accumulate region information on temporary hypothesises
	for(int hyp = 0; hyp < curHypNum ; hyp++){
		//Fill hyp_t_1 (matrix column HYP)
		hyp_t_1[hyp].ex_x0 = regRect[hyp].x;
		hyp_t_1[hyp].ex_y0 = regRect[hyp].y;
		hyp_t_1[hyp].ex_h = regRect[hyp].height;
		hyp_t_1[hyp].ex_w = regRect[hyp].width;
		hyp_t_1[hyp].x0 =	regRect[hyp].x;
		hyp_t_1[hyp].y0 = regRect[hyp].y;
		hyp_t_1[hyp].width = regRect[hyp].width;
		hyp_t_1[hyp].height = regRect[hyp].height;
		hyp_t_1[hyp].hasMatch = false;
		//Uncomment if we dont need color histograms
		hyp_t_1[hyp].updateColor( bgMask, bins, time );
	}
	//Tag as previous hypothesis as no match yet.
	for(int hyp = 0; hyp < preHypNum ; hyp++){
		hyp_t[hyp].hasMatch = false;		
	}
	//Determine Correspondence Matrix Matches
	fillZero(corMatrix, 50); //Fill zeros
	//Check for matches
	for(int row = 0; row < preHypNum ; row++){
		for(int col = 0; col < curHypNum ; col++){
			float matchRatio = hyp_t[row].match( hyp_t_1[col] );	//Check match i,j
			//cout << "colorHist match : (" << hyp_t[row].id << ","<< col  << ") : " << hyp_t[row].matchHist_Bhattarcharya_Coefficient(hyp_t_1[col] ) << endl;
			corMatrix[row][col] = matchRatio;
			//cout << "match rat : " << matchRatio << endl;
			if ( matchRatio > 0.7 ){
				//cout << "traj change : hyp" << row << " as : " << hyp_t_1[col].x0 << endl;
				hyp_t[row].appear( hyp_t_1[col] );
				hyp_t_1[col].hasMatch = true;
				hyp_t[row].hasMatch = true;
				hyp_t[row].state = HYP_TRACKED;
			}
		}
		if (hyp_t[row].hasMatch == false){
			cout << "No match for hyp : " << hyp_t[row].id << " (disappear) " << endl;
			hyp_t[row].state = HYP_OCCLUDED;
		}
	}
	//Check for still non-matched new hypothesis (Appear Events automaticily)
	//Create hypothesis with mouse clicks
	if ( hypClicked ){
		hypClicked = false;
		int trackedX = tx;
		int trackedY = ty;
		//Find which region user clicked
		int i = 0;
		while( i < curHypNum ){
			//Found correct region user clicked
			if ( tx >= hyp_t_1[i].x0 && ty >= hyp_t_1[i].y0 
				&& tx <= hyp_t_1[i].x0 + hyp_t_1[i].width && ty <= hyp_t_1[i].y0 + hyp_t_1[i].height ){
					//Create a new hypothesis, appear event...
					hyp_t[preHypNum].trajColor = colors[ Hypothesis::objectNumber];
					hyp_t[preHypNum].id = Hypothesis::objectNumber;
					hyp_t[preHypNum].appear( hyp_t_1[i] );
					hyp_t[preHypNum].updateColor( bgMask, bins, time);
					float matchRatio = hyp_t[preHypNum].match( hyp_t_1[i] );
					corMatrix[preHypNum][i] = matchRatio;
					cout << "Created new Hypothesis. code (" << hyp_t[preHypNum].id <<") " << endl;
					preHypNum++;
					Hypothesis::objectNumber++;
					break;
			}
			i++;
		}
	}


	//Output Phase
	//Output correspondence matrix
	cout << "***[_CorrespondenceMat_]***" << endl;
	cout.precision(2);
	for(int row = 0; row < preHypNum ; row++){
		cout << endl;
		//cout << "[" << hyp_t[row].id << "] "; 
		for(int col = 0; col < curHypNum ; col++){
			cout << corMatrix[row][col] << " ";
		}
	}
	cout << endl;

	//Advance all hypothesis on time, (if occluded long time remove them )
	for(int row = 0; row < preHypNum ; row++){
		cout << "Hyp " << hyp_t[row].id << " :  vx " << hyp_t[row].vx << " vy  " << hyp_t[row].vy << " ang: " << hyp_t[row].ang << 
			" velmag veldir : " << hyp_t[row].velMag << " " << hyp_t[row].velDirection <<  endl;
		hyp_t[row].printTrack(visualImg);
		sprintf(text, "Hyp %d", hyp_t[row].id);
		cvPutText(visualImg, text, cvPoint(hyp_t[row].x0 + hyp_t[row].width /2 , hyp_t[row].y0 + hyp_t[row].height /2), &font, colors[hyp_t[row].id] );
		if ( hyp_t[row].lastSeenIndex == MAX_FRAME_OCCLUDED ){
			//Remove hypothesis from list...
		}
		else if(hyp_t[row].state == HYP_OCCLUDED){
			hyp_t[row].lastSeenIndex ++;	// 1 more frame we couldnt see the shit object.
		}
		else{ // If still tracking hypothesis
			hyp_t[row].time++;
		}
	}
}