Esempio n. 1
0
bool GUIPanel::loadXMLSettings(const char *stackPath)
{
  std::string xmlFile = MediaPathManager::lookUpMediaPath(stackPath);
  bool        result = false;

  if(!xmlFile.size())
    return Logger::writeErrorLog("Failed to locate the XML GUI file");

  TiXmlDocument cfgStack(xmlFile);

  if(!cfgStack.LoadFile())
    return  Logger::writeErrorLog("Invalid XML GUI description file");

  result = loadXMLSettings(cfgStack.FirstChildElement());
  forceUpdate(true);
  return result;
}
Esempio n. 2
0
//--------------------------------------------------------------
void ofApp::setup()
{
    flowWidth = WINDOW_WIDTH / 4;
    flowHeight = WINDOW_HEIGHT / 4;
    tuioForce.setup(flowWidth, flowHeight, WINDOW_WIDTH, WINDOW_HEIGHT);
    
    loadXMLSettings();
    setupGui();
    
    ofEnableSmoothing();
    
    tuioClient.start(3333);
    
    fluidSimulation.setup(flowWidth, flowHeight, WINDOW_WIDTH, WINDOW_HEIGHT);
    fluidSimulation.addObstacle(backgroundLogo.getTexture());
    
    particleFlow.setup(flowWidth, flowHeight, WINDOW_WIDTH, WINDOW_HEIGHT);
    
    
    ofAddListener(tuioClient.cursorAdded,this,&ofApp::tuioAdded);
    ofAddListener(tuioClient.cursorRemoved,this,&ofApp::tuioRemoved);
    ofAddListener(tuioClient.cursorUpdated,this,&ofApp::tuioUpdated);
}
/******************************************************************************
* The setup function is run once to perform initializations in the application
*****************************************************************************/
void ofxNCoreVision::_setup(ofEventArgs &e)
{
	//set the title
	ofSetWindowTitle(" Community Core Vision v 1.4");

	//create filter
	if(filter == NULL)	filter = new ProcessFilters();
	if ( filter_fiducial == NULL ){filter_fiducial = new ProcessFilters();}

	//Load Settings from config.xml file
	loadXMLSettings();

	if(debugMode)
	{
		printf("DEBUG MODE : Printing to File\n");
		/*****************************************************************************************************
		* LOGGING
		******************************************************************************************************/
		/* alright first we need to get time and date so our logs can be ordered */
		time ( &rawtime );
		timeinfo = localtime ( &rawtime );
		strftime (fileName,80,"../logs/log_%B_%d_%y_%H_%M_%S.txt",timeinfo);
		FILE *stream ;
		sprintf(fileName, ofToDataPath(fileName).c_str());
		if((stream = freopen(fileName, "w", stdout)) == NULL){}
		/******************************************************************************************************/
	}

	cameraInited = false;

	//Setup Window Properties
	ofSetWindowShape(winWidth,winHeight);
	ofSetVerticalSync(false);	            //Set vertical sync to false for better performance?

	//printf("Application Loaded...\n?");

	//load camera/video
	initDevice();
	printf("Camera(s)/Video Initialised...\n");

	//set framerate
	ofSetFrameRate(camRate * 1.3);			//This will be based on camera fps in the future

	/*****************************************************************************************************
	* Allocate images (needed for drawing/processing images)
	******************************************************************************************************/
	processedImg.allocate(camWidth, camHeight); //main Image that'll be processed.
	processedImg.setUseTexture(false);			//We don't need to draw this so don't create a texture
	sourceImg.allocate(camWidth, camHeight);    //Source Image
	sourceImg.setUseTexture(false);				//We don't need to draw this so don't create a texture

	//Fiducial Images
	processedImg_fiducial.allocate(camWidth, camHeight); //main Image that'll be processed.
	processedImg_fiducial.setUseTexture(false);                        //We don't need to draw this so don't create a texture
	undistortedImg.allocate(camWidth, camHeight);
	/******************************************************************************************************/

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

	//Static Images
	background.loadImage("images/background.jpg"); //Main (Temp?) Background
	//GUI Controls
	controls = ofxGui::Instance(this);
	setupControls();

	//printf("Controls Loaded...\n");

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

	//Allocate Filters
	filter->allocate( camWidth, camHeight );
	filter_fiducial->allocate( camWidth, camHeight );

	//Fiducial Initialisation

	// factor for Fiducial Drawing. The ImageSize is hardcoded 320x240 Pixel!(Look at ProcessFilters.h at the draw() Method
	fiducialDrawFactor_Width = 320 / static_cast<float>(filter->camWidth);//camWidth;
	fiducialDrawFactor_Height = 240 / static_cast<float>(filter->camHeight);//camHeight;


	/*****************************************************************************************************
	* Startup Modes
	******************************************************************************************************/
	//If Standalone Mode (not an addon)
	if (bStandaloneMode)
	{
		printf("Starting in standalone mode...\n\n");
		showConfiguration = true;
	}
	if (bMiniMode)
	{
		showConfiguration = true;
		bShowInterface = false;
		printf("Starting in Mini Mode...\n\n");
		ofSetWindowShape(190, 200); //minimized size
		filter->bMiniMode = bMiniMode;
	}
	else{
		bShowInterface = true;
		printf("Starting in full mode...\n\n");
	}

	//If Object tracking activated
	if(contourFinder.bTrackObjects)
	{
		templates.loadTemplateXml();
	}

	contourFinder.setTemplateUtils(&templates);
	tracker.passInFiducialInfo(&fidfinder);

	#ifdef TARGET_WIN32
		//get rid of the console window
		FreeConsole();
	#endif

	printf("Community Core Vision is setup!\n\n");
}
/******************************************************************************
* The setup function is run once to perform initializations in the application
*****************************************************************************/
void ofxKCoreVision::_setup(ofEventArgs &e){
	threshold = 80;
	nearThreshold = 550;
	farThreshold  = 650;

	//set the title
	ofSetWindowTitle("Kinect Vision based on CCV v2");

	//create filter
	if(filter == NULL)
		filter = new ProcessFilters();

	//Load Settings from config.xml file
	loadXMLSettings();

	if(debugMode){
		printf("DEBUG MODE : Printing to File\n");
		/*****************************************************************************************************
		* LOGGING
		******************************************************************************************************/
		/* alright first we need to get time and date so our logs can be ordered */
		time ( &rawtime );
		timeinfo = localtime ( &rawtime );
		strftime (fileName,80,"../logs/log_%B_%d_%y_%H_%M_%S.txt",timeinfo);
		FILE *stream;
		sprintf(fileName, ofToDataPath(fileName).c_str());
		if((stream = freopen(fileName, "w", stdout)) == NULL){}
		/******************************************************************************************************/
	}

	cameraInited = false;

	//Setup Window Properties
	ofSetWindowShape(winWidth,winHeight);
	ofSetVerticalSync(false);	            //Set vertical sync to false for better performance?

	//load camera/video
	initDevice();
	printf("Kinect Initialised...\n");

	//set framerate
	ofSetFrameRate(camRate * 1.3);			//This will be based on camera fps in the future

	/*****************************************************************************************************
	* Allocate images (needed for drawing/processing images)
	******************************************************************************************************/
	processedImg.allocate(camWidth, camHeight); //main Image that'll be processed.
	processedImg.setUseTexture(false);			//We don't need to draw this so don't create a texture
	sourceImg.allocate(camWidth, camHeight);    //Source Image
	sourceImg.setUseTexture(false);				//We don't need to draw this so don't create a texture

	//Fiducial Images
	undistortedImg.allocate(camWidth, camHeight);		// ES NECESARIO???
	/******************************************************************************************************/

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

	//Static Images
	background.loadImage("images/background.jpg"); //Main (Temp?) Background
	//GUI Controls
	controls = ofxGui::Instance(this);
	setupControls();

	//printf("Controls Loaded...\n");

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

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

	/*****************************************************************************************************
	* Startup Modes
	******************************************************************************************************/
	//If Standalone Mode (not an addon)
	if (bStandaloneMode)
	{
		printf("Starting in standalone mode...\n\n");
		showConfiguration = true;
	}
	if (bMiniMode)
	{
		showConfiguration = true;
		bShowInterface = false;
		printf("Starting in Mini Mode...\n\n");
		ofSetWindowShape(190, 200); //minimized size
		filter->bMiniMode = bMiniMode;
	}
	else{
		bShowInterface = true;
		printf("Starting in full mode...\n\n");
	}

	//If Object tracking activated
	if(contourFinder.bTrackObjects)
	{
		templates.loadTemplateXml();
	}

	contourFinder.setTemplateUtils(&templates);

	printf("Community Core Vision is setup!\n\n");
}
Esempio n. 5
0
/******************************************************************************
 * The setup function is run once to perform initializations in the application
 *****************************************************************************/
void ofxNCoreAudio::_setup(ofEventArgs &e)
{	
    // set the title
    ofSetWindowTitle(" Community Core Audio ");	
	
    // Load Settings from config.xml file
    loadXMLSettings();
	
    // Setup Window Properties
    ofSetWindowShape(winWidth,winHeight);
    ofSetVerticalSync(false);
	
    // Fonts
    verdana.loadFont("verdana.ttf", 8, true, true);	   // Font used for small images
    bigvideo.loadFont("verdana.ttf", 13, true, true);  // Font used for big images.
	
    // Static Images
    background.loadImage("images/background.jpg"); // Main Background
	
    // GUI Controls
    controls = ofxGui::Instance(this);
    setupControls(); 
	
    // ASR Engine: commandpicking
    asrEngine_1 = new ofxSphinxASR;
    ofAsrEngineArgs *engineArgs = new ofAsrEngineArgs;
    engineArgs->sphinxmodel_am = sphinxmodel_am;
    engineArgs->sphinxmodel_lm = sphinxmodel_lm;
    engineArgs->sphinxmodel_dict = sphinxmodel_dict;
    engineArgs->sphinxmodel_fdict = sphinxmodel_fdict;
    engineArgs->sphinx_mode = 2;
    engineArgs->samplerate = model_sampleRate;
    FILE *fp_list = fopen(commandList.c_str(), "rt");
    if (fp_list==NULL) {
        printf("Error: Can not find command list file %s.", commandList.c_str());
    }
    char *sentence = new char[maxSentenceLength];
    while (fgets(sentence, maxSentenceLength, fp_list)) {
        engineArgs->sphinx_candidate_sentences.push_back(sentence);
    }
    if (asrEngine_1->engineInit(engineArgs) != OFXASR_SUCCESS) {
        printf("Initial ASR Engine Failed!");
    }
    delete []sentence;
    curAsrEngine = asrEngine_1;

    // ASR Engine: freespeaking
    asrEngine_2 = new ofxSphinxASR;
    engineArgs->sphinx_mode = 4;
    if (asrEngine_2->engineInit(engineArgs) != OFXASR_SUCCESS) {
        printf("Initial ASR Engine Failed!");
    }
    delete engineArgs;
	
    // Display
    ofColor outBgColor;
    outBgColor.r = outBgColor.g = outBgColor.b = 0x33;
    ofColor outFgColor;
    outFgColor.r = 0; outFgColor.g = 255; outFgColor.b = 0;
    ofRectangle outRect;
    int outRectBorder = 20;
    outRect.x = 386 + outRectBorder/2;
    outRect.y = 41 + outRectBorder;
    outRect.height = 229 - 2 * outRectBorder;
    outRect.width = 320 - 2 * outRectBorder/2;
    rectPrint.init(outRect, outBgColor, outFgColor, "verdana.ttf", 8);
    rectPrint.setLineHeight(15);

    // Resample
    resample_factor = (float)model_sampleRate / SampleRate;
    resample_handle = resample_open(1, resample_factor, resample_factor);
    tcpServer.setup(tcpPort);
	
    /*****************************************************************************************************
	 * Startup Modes
	 ******************************************************************************************************/
    showConfiguration = true;
    if (bMiniMode)
    {
        bShowInterface = false;
        printf("Starting in Mini Mode...\n\n");
        ofSetWindowShape(190, 200); // minimized size
    }
    else{
        bShowInterface = true;
        printf("Starting in full mode...\n\n");
    }
	
#ifdef TARGET_WIN32
#ifndef _DEBUG
    FreeConsole();
#endif
#endif
	
    printf("Community Core Audio is setup!\n\n");
}
Esempio n. 6
0
/******************************************************************************
 * The setup function is run once to perform initializations in the application
 *****************************************************************************/
void testApp::setup()
{	
	

	/********************
	* Initalize Variables
	*********************/
	fuzzy.loadImage("particle.png");
	fuzzy.setUseTexture(true);

	//For screengrab
	snapCounter	= 6; 
	//Background Subtraction Learning Rate
	fLearnRate	= 0.0001f;
	//Intialize FPS variables
	frames		= 0;
	fps			= 0;
	lastFPSlog	= 0;
	//Calibration Booleans
	bCalibration= false;
	bShowTargets = true;
	bW			= false;
	bA			= false;
	bS			= false;
	bD			= false;
	
	downColor = 0xFF0000;

	bDrawVideo = true;
	bFullscreen = false;

	//bFlowing	= false;
//	ofSetBackgroundAuto(false);

	//Load Settings from config.xml file 
	loadXMLSettings();

	//Load Calibration Settings from calibration.xml file
	calibrate.setCamRes(camWidth, camHeight);
	calibrate.loadXMLSettings();

	//Setup Window Properties 
	ofSetWindowShape(winWidth,winHeight);
	ofSetFrameRate(camRate);			//This will be based on camera fps in the future		
	ofSetVerticalSync(false);	//Set vertical sync to false for better performance

	//Pick the Source - camera or video
	if(bcamera){

		activeInput = true;

		vidGrabber.listDevices();
		vidGrabber.setDeviceID(deviceID);
		vidGrabber.setVerbose(true);		
        vidGrabber.initGrabber(camWidth,camHeight);		

		printf("Camera Mode\n");
		int grabW = vidGrabber.width;
		int grabH = vidGrabber.height;
		printf("Asked for %i by %i - actual size is %i by %i \n", 
				camWidth, camHeight, grabW, grabH);
	}
	else{
		
		activeInput = true;	

        //vidPlayer.loadMovie("test_videos/FrontDI.m4v");
		//vidPlayer.loadMovie("test_videos/HCI_FTIR.mov");
		vidPlayer.loadMovie("test_videos/raw.mp4");
		//vidPlayer.loadMovie("test_videos/5point.avi");
        vidPlayer.play();	
		printf("Video Mode\n");
		camHeight = vidPlayer.height;
		camWidth = vidPlayer.width;
	}
    
	/*****************************************************************************************************
	* Allocate images (needed for drawing/processing images) ----Most of These won't be needed in the end
	******************************************************************************************************/
	processedImg.allocate(camWidth, camHeight); //main Image that'll be processed.
	processedImg.setUseTexture(false);
	sourceImg.allocate(camWidth, camHeight);    //Source Image
	sourceImg.setUseTexture(false);				//We don't need to draw this so don't create a texture

	//These images are used for drawing only
	grayImg.allocate(camWidth, camHeight);		//Gray Image
	grayBg.allocate(camWidth, camHeight);		//Background Image
	subtractBg.allocate(camWidth, camHeight);   //Background After subtraction
	grayDiff.allocate(camWidth, camHeight);		//Difference Image between Background and Source
	highpassImg.allocate(camWidth, camHeight);  //Highpass Image
	ampImg.allocate(camWidth, camHeight);		//Amplied Image	
	fiLearn.allocate(camWidth, camHeight);		//ofxFloatImage used for simple dynamic background subtracti
//	fiLearn.setUseTexture(false);
	pressureMap.allocate(camWidth, camHeight);	//Pressure Map Image
	
	//For camera warp
	giWarped.allocate(camWidth, camHeight);     //Warped Image (used for warped calibration)
	giWarped.setUseTexture(false);

   if(bFlowing){	
	//FLOW
	   opticalFlowLK.allocate(camWidth, camHeight);
	   opticalFlowBM.allocate(camWidth, camHeight);
   }
	/********************************************************************************************************/


	/**********************************************************/
	//GPU stuff initialization
	/**********************************************************/
	glGenTextures(1, &gpuSourceTex);
	glGenTextures(1, &gpuBGTex);

	//initialize texture once with glTexImage2D so we can use gltexSubImage2D afetrwards (fastser)
	glEnable(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D, gpuSourceTex);
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8,  camWidth, camHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
	glBindTexture(GL_TEXTURE_2D, gpuBGTex);
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8,  camWidth, camHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
	glBindTexture(GL_TEXTURE_2D, 0);
	glDisable(GL_TEXTURE_2D);

	grabFrameToGPU(gpuBGTex);

	//so very inefficient..but only for now..until i fix the gpu blob detection and geoemtry shader for variable length output
	gpuReadBackBuffer = new unsigned char[camWidth*camHeight*3]; 
	gpuReadBackImage.allocate(camWidth, camHeight);
	gpuReadBackImageGS.allocate(camWidth, camHeight);

	subtractFilter = new ImageFilter("filters/absSubtract.xml", camWidth, camHeight);
	subtractFilter2 = new ImageFilter("filters/subtract.xml", camWidth, camHeight);
	contrastFilter = new ImageFilter("filters/contrast.xml", camWidth, camHeight);
	gaussVFilter = new ImageFilter("filters/gaussV.xml", camWidth, camHeight);
	gaussHFilter = new ImageFilter("filters/gauss.xml", camWidth, camHeight);
	gaussVFilter2 = new ImageFilter("filters/gaussV2.xml", camWidth, camHeight);
	gaussHFilter2 = new ImageFilter("filters/gauss2.xml", camWidth, camHeight);
	threshFilter = new ImageFilter("filters/threshold.xml", camWidth, camHeight);
	/**********************************************************/




	//Fonts - Is there a way to dynamically change font size?
	verdana.loadFont("verdana.ttf", 8, true, true);	   //Font used for small images
	sidebarTXT.loadFont("verdana.ttf", 8, true, true);
	calibrationText.loadFont("verdana.ttf", 10, true, true);
	bigvideo.loadFont("verdana.ttf", 13, true, true);  //Font used for big images.
	
	//Static Images
	logo.loadImage("images/logo.jpg");
	background.loadImage("images/background.jpg"); //Main (Temp?) Background

	//Setup green warped box
	warp_box.setup( 40, 30, camWidth, camHeight, camWidth/320, camHeight/240); 

	warp_box.fHandles[0].x = handle1x;
	warp_box.fHandles[0].y = handle1y;
	warp_box.fHandles[1].x = handle2x;
	warp_box.fHandles[1].y = handle2y;
	warp_box.fHandles[2].x = handle3x;
	warp_box.fHandles[2].y = handle3y;
	warp_box.fHandles[3].x = handle4x;
	warp_box.fHandles[3].y = handle4y;

	//Warped points
	dstPts[0].x = 0.0f;
    dstPts[0].y = camHeight;   
    dstPts[1].x = camWidth;
    dstPts[1].y = camHeight;   
    dstPts[2].x = camWidth;
    dstPts[2].y = 0.0f;   
    dstPts[3].x = 0.0f;
    dstPts[3].y = 0.0f;

	//Setup testApp to listen for touch events
	tracker.setListener(this); 

	gui = ofxGui::Instance(this);
	setupGUI();

	printf("Touchlib application is setup!\n");
}
Esempio n. 7
0
bool GUIPanel::loadXMLSettings(const TiXmlElement *element)
{
  if(!XMLArbiter::inspectElementInfo(element, "Panel"))
    return Logger::writeErrorLog("Need a Panel node in the xml file");

  const char  *description = element->Attribute("description");
  std::string  type        = element->Attribute("layout") ? element->Attribute("layout") : "UNKNOWN";

  if(description)
    return  loadXMLSettings(description);

  layout = (type == "CEN_YAXIS") ? PL_YAXIS_CEN_LAYOUT :
           (type == "YAXIS"    ) ? PL_YAXIS_LAYOUT     :
           (type == "XAXIS"    ) ? PL_XAXIS_LAYOUT     :
           (type == "GRID"     ) ? PL_GRID_LAYOUT      : PL_FREE_LAYOUT;

  for(const TiXmlElement *child = element->FirstChildElement();
      child;
   	  child = child->NextSiblingElement() )
  {
    std::string childName  = child->Value();
 
    if(!childName.size())
      continue;

    if(childName == "CheckBox")
    {
      GUICheckBox *newCheckBox = new GUICheckBox();
      if(!newCheckBox->loadXMLSettings(child) || !addWidget(newCheckBox))
        deleteObject(newCheckBox);
      continue;
    }

    if(childName == "TabbedPanel")
    {
      GUITabbedPanel *newTabbedPanel = new GUITabbedPanel();
      if(!newTabbedPanel->loadXMLSettings(child) || !addWidget(newTabbedPanel))
        deleteObject(newTabbedPanel);
      continue;
    }

    if(childName == "RadioButton")
    {
      GUIRadioButton *newRadioButton = new GUIRadioButton();
      if(!newRadioButton->loadXMLSettings(child) || !addWidget(newRadioButton))
      {
        deleteObject(newRadioButton);
      }
      else
      {
        if(newRadioButton->isChecked())
          notify(newRadioButton);
      }
      continue;
    }

    if(childName == "ComboBox")
    {
      GUIComboBox *newComboBox = new GUIComboBox();
      if(!newComboBox->loadXMLSettings(child) || !addWidget(newComboBox))
        deleteObject(newComboBox);
      continue;
    }

    if(childName == "TextBox")
    {
      GUITextBox *newTextBox = new GUITextBox();
      if(!newTextBox->loadXMLSettings(child) || !addWidget(newTextBox))
        deleteObject(newTextBox);
      continue;
    }

    if(childName == "Slider")
    {
      GUISlider *newSlider = new GUISlider();
      if(!newSlider->loadXMLSettings(child) || !addWidget(newSlider))
        deleteObject(newSlider);
      continue;
    }

    if(childName == "Separator")
    {
      GUISeparator *newSeparator = new GUISeparator();
      if((layout != PL_YAXIS_LAYOUT &&
          layout != PL_XAXIS_LAYOUT &&
          layout != PL_YAXIS_CEN_LAYOUT) ||
         (!newSeparator->loadXMLSettings(child)))
      {
        deleteObject(newSeparator);
      }
      else
      {
        newSeparator->setParent(this);
        newSeparator->setOrientation((layout != PL_YAXIS_LAYOUT && layout != PL_YAXIS_CEN_LAYOUT));
        elements.push_back(newSeparator);
      }
      continue;
    }

    if(childName == "Button")
    {
      GUIButton *newButton = new GUIButton();
      if(!newButton->loadXMLSettings(child) || !addWidget(newButton))
        deleteObject(newButton);
      continue;
    }

    if(childName == "Label")
    {
      GUILabel *newLabel = new GUILabel();
      if(!newLabel->loadXMLSettings(child) || !addWidget(newLabel))
        deleteObject(newLabel);
      continue;
    }


    if(childName == "Interval")
      setInterval(XMLArbiter::fillComponents2i(child, interval));

    if(childName == "Panel")
    {
      GUIPanel *panel = new GUIPanel();
      if(!panel->loadXMLSettings(child) || !addWidget(panel))
        deleteObject(panel);
      continue;
    }
  }

  return  GUIRectangle::loadXMLSettings(element)  &&
          GUIClippedRectangle::loadXMLClippedRectangleInfo(element);
}