示例#1
0
int main()
{
	PROFILER_INIT();

	FrameList frameList(10);	// Keep a history of up to 100 frames (might be used by some modules)
	
	// Modules
	//BackgroundModelling_simple::BackgroundModel backgroundModel;
	BackgroundModelling::BackgroundModel backgroundModel;
	ForegroundProcessing::ForegroundProcessor foregroundProcessor;
	Identification::Identifier identifier;
	Prediction::Kalman kalmanFilter;
	Evaluation evaluate(&frameList, 20);

	// Init
	foregroundProcessor.setAlgortihm(ForegroundProcessing::SLOW); //Use slow, toggle shadows in the init command
	foregroundProcessor.init(3, 2, 125, 4, false);
	foregroundProcessor.initShadow(0.5, 0.5, 0.3, 0.99);
	identifier.init(Identification::Ultimate);
	evaluate.readXML2FrameList("clip1.xml");
	//evaluate.readXML2FrameList("CAVIAR1/fosne2gt.xml");

	int waitForBGConvergence = 60;
	
	
	// Load frame source
	//frameList.open("CAVIAR1/OneStopNoEnter2front.mpg");
	//frameList.open("clip1.mpeg");
	frameList.open("camera1.mov");
	//frameList.open("Renova_20080420_083025_Cam10_0000.mpeg");
	
	//Record video
	VideoWriter demo("trackingDemo.mpeg", CV_FOURCC('P','I','M','1'), 20, frameList.movieSize*2);

	// Create windows
	namedWindow("Info",CV_WINDOW_AUTOSIZE);
	namedWindow("Background",CV_WINDOW_AUTOSIZE);
	namedWindow("Foreground",CV_WINDOW_AUTOSIZE);
	namedWindow("Tracking",CV_WINDOW_AUTOSIZE);
	namedWindow("Raw image", CV_WINDOW_AUTOSIZE);
	//namedWindow("BackgroundModel",CV_WINDOW_AUTOSIZE);
	namedWindow("Evaluation", CV_WINDOW_AUTOSIZE);

	while (frameList.queryNextFrame())
	{
		PROFILER_RESET();

		sampleDown(frameList.getLatestFrame().image, frameList.getLatestFrame().image, 1);	// Speed up by sampling down the image
		
		// Do the nessecary processing
		backgroundModel.update(frameList.getFrames());							PROFILE("BackgroundModel");
		if (frameList.getCurrentFrameNumber() > waitForBGConvergence)	//Wait for convergence
			foregroundProcessor.segmentForeground(frameList.getLatestFrame());	PROFILE("ForegroundSeg.");
		identifier.identify(frameList.getFrames());								PROFILE("Identification");	
		kalmanFilter.predict(frameList.getLatestFrame());						PROFILE("Kalman Prediction");
		evaluate.currentFrame();												PROFILE("Evaluation");

		// Display result
		frameList.display("Tracking");
		frameList.displayBackground("Background");
		if (frameList.getCurrentFrameNumber() > waitForBGConvergence) //Wait for convergence
			frameList.displayForeground("Foreground");
		evaluate.displayInfo("Evaluation");
		// Give the GUI time to render
		waitKey(1);															PROFILE("Display");
		
		// Write current frame (and info) to file
		demo << frameList.getLatestFrame().demoImage;
		
		// Optional pause between each frame
		//stepWiseFromFrame(frameList, 55);
																			PROFILE("QueryNextFrame");										
																			PROFILE_TOTALTIME();
																			PROFILE("FPS");
																			PROFILE_FPS();
		// Evaluate accuracy and precision
		evaluate.MOTA();
		evaluate.MOTP();

		// Display info
		frameList.displayInfo("Info");
	} 
	
	evaluate.displaySequenceInfo("Evaluation");
	waitKey(0);
	return 0;
}
示例#2
0
//Trigger the ODE simulation. This method should be called frequently
//(call SetTime() before invoking Trigger() to update the current Time).
//The method will invoke dWorldStep one or several times, depending
//on the Time since the last call, and the step size of the Level.
//The method will make sure that the physics simulation is triggered
//using a constant step size.
void CLevel::Trigger()
{
	PROFILER_START(profFrameBefore);
	for (int i = 0; i < Entities.Size(); i++) Entities[i]->OnFrameBefore();
	PROFILER_STOP(profFrameBefore);

	PROFILER_RESET(profStepBefore);
	PROFILER_RESET(profStepAfter);
	PROFILER_RESET(profCollide);
	PROFILER_RESET(profStep);
	PROFILER_RESET(profJointGroupEmpty);

#ifdef __NEBULA_STATS__
	statsNumNearCallbackCalled = 0;
	statsNumCollideCalled = 0;
	statsNumCollided = 0;
	statsNumSpaceCollideCalled = 0;
	statsNumSteps = 0;
#endif

	TimeToSim += GameSrv->GetFrameTime();
	while (TimeToSim > StepSize)
	{
		PROFILER_STARTACCUM(profStepBefore);
		for (int i = 0; i < Entities.Size(); i++) Entities[i]->OnStepBefore();
		PROFILER_STOPACCUM(profStepBefore);

		// do collision detection
		PROFILER_STARTACCUM(profCollide);
		statsNumSpaceCollideCalled++;
		dSpaceCollide2((dGeomID)ODEDynamicSpaceID, (dGeomID)ODEStaticSpaceID, this, &ODENearCallback);
		dSpaceCollide(ODEDynamicSpaceID, this, &ODENearCallback);
		PROFILER_STOPACCUM(profCollide);

		// step physics simulation
		PROFILER_STARTACCUM(profStep);
		dWorldQuickStep(ODEWorldID, dReal(StepSize));
		PROFILER_STOPACCUM(profStep);

		// clear Contact joints
		PROFILER_STARTACCUM(profJointGroupEmpty);
		dJointGroupEmpty(ContactJointGroup);
		PROFILER_STOPACCUM(profJointGroupEmpty);

		PROFILER_STARTACCUM(profStepAfter);
		for (int i = 0; i < Entities.Size(); i++) Entities[i]->OnStepAfter();
		PROFILER_STOPACCUM(profStepAfter);

		statsNumSteps++;
		TimeToSim -= StepSize;
    }

	// export statistics
#ifdef __NEBULA_STATS__
	//nWatched watchSpaceCollideCalled("statsMangaPhysicsSpaceCollideCalled", DATA_TYPE(int));
	//nWatched watchNearCallbackCalled("statsMangaPhysicsNearCallbackCalled", DATA_TYPE(int));
	//nWatched watchCollideCalled("statsMangaPhysicsCollideCalled", DATA_TYPE(int));
	//nWatched watchCollided("statsMangaPhysicsCollided", DATA_TYPE(int));
	//nWatched watchSpaces("statsMangaPhysicsSpaces", DATA_TYPE(int));
	//nWatched watchShapes("statsMangaPhysicsShapes", DATA_TYPE(int));
	//nWatched watchSteps("statsMangaPhysicsSteps", DATA_TYPE(int));
	//if (statsNumSteps > 0)
	//{
	//	watchSpaceCollideCalled->SetValue(statsNumSpaceCollideCalled/statsNumSteps);
	//	watchNearCallbackCalled->SetValue(statsNumNearCallbackCalled/statsNumSteps);
	//	watchCollideCalled->SetValue(statsNumCollideCalled/statsNumSteps);
	//	watchCollided->SetValue(statsNumCollided/statsNumSteps);
	//}
	//watchSpaces->SetValue(statsNumSpaces);
	//watchShapes->SetValue(statsNumShapes);
	//watchSteps->SetValue(statsNumSteps);
#endif

	// invoke the "on-frame-after" methods
	PROFILER_START(profFrameAfter);
	for (int i = 0; i < Entities.Size(); i++) Entities[i]->OnFrameAfter();
	PROFILER_STOP(profFrameAfter);
}