Ejemplo n.º 1
0
/** A convenience function that creates the callback,
 *  collects results, and makes them available in the
 *  return argument.
 */
ResultSet cvac::detect(
                    const std::string& algorithm,
                    const cvac::RunSet& runset,
                    const cvac::FilePath& model,
                    const cvac::DetectorProperties* detprops )
{
  // Connect to detector
  Ice::Identity det_cb;
  CallbackHandlerI *cr = new CallbackHandlerI();
  DetectorPrx detector = initIceConnection( algorithm, det_cb, cr );
  if(NULL == detector.get())
  {
    localAndClientMsg( VLogger::ERROR, NULL, "Could not connect to CVAC Ice Services" );
    return ResultSet();
  }
  cvac::DetectorProperties dprops;
  // If user did not supply any detector properties then provide default one.
  if (NULL == detprops)
  {
      // need to initialize detector properties to their defaults
      dprops = detector->getDetectorProperties();   
      detprops = &dprops;
  }

  try
    {	
      detector->process(det_cb, runset, model, *detprops);
    }
  catch (const Ice::Exception& ex)
    {
      throw ex;
    }

  iceComm->shutdown();  // Shut down at the end of either branch
  return cr->rs;
}
Ejemplo n.º 2
0
int ClientApp::run(int argc, char* argv[])
{
  string verbStr = communicator()->getProperties()->getProperty("CVAC.ClientVerbosity");
  if (!verbStr.empty())
  {
      vLogger.setLocalVerbosityLevel( verbStr );
  }
  localAndClientMsg(VLogger::DEBUG_2, NULL, "App 2nd arg (testFileFolder): %s\n", argv[2]);
  std::string testFileFolder = std::string(argv[2]);

  if(argc < 3 || argc > 5)  // Warn wrong args
  {
	localAndClientMsg(VLogger::ERROR, NULL,
	"not enough or too many command line arguments\n", appName());
	localAndClientMsg(VLogger::ERROR, NULL,
	"<exe filename> <detector xml or zipFile from config> <name of the detector> [path to directory of images to process] [flag: 'verifyresults']\n");
	return EXIT_FAILURE;
  }
  ResultSet result;
  RunSet runSet;
  Ice::PropertiesPtr props = communicator()->getProperties();
  std::string dataDir = props->getProperty("CVAC.DataDir");
		
  PurposedDirectoryPtr dir = new PurposedDirectory();

  localAndClientMsg(VLogger::DEBUG, NULL, "IceBoxTestClient-mainLoop setting RunSet dir: %s\n", testFileFolder.c_str());
	  dir->directory.relativePath = std::string(testFileFolder.c_str());
  runSet.purposedLists.push_back(dir);

  std::string _detectorName = argv[1];
  if(appData->videoInputType) {
		 dir->fileSuffixes.push_back("mpg");
         localAndClientMsg(VLogger::DEBUG_2, NULL, "Using (.mpg) extension.\n");
  }
  else {
		 dir->fileSuffixes.push_back("jpg");
  }

  dir->recursive = true;
  // get the model file
  std::string filenameStr = m_detectorName + ".DetectorFilename";
  
  std::string filename = props->getProperty(filenameStr);
		
  if (filename.length() == 0)
  {
		localAndClientMsg(VLogger::WARN, NULL,
					  "No .DetectorFilename pair found for %s.\n", 
					  m_detectorName.c_str());
		return EXIT_FAILURE;
  }
  FilePath file;
  if ((filename.length() > 1 && filename[1] == ':' )||
			filename[0] == '/' ||
			filename[0] == '\\')
  {  // absolute path
			int idx = filename.find_last_of('/');
			file.directory.relativePath = filename.substr(0, idx);
			file.filename = filename.substr(idx+1, filename.length() - idx);
  }
  else
  { //Add the current directory
			file.directory.relativePath = "detectors";
			file.filename = filename;
  }
	
 
  
  // Connect to detector
  DetectorPrx detector = initIceConnection(m_detectorName);
  if(NULL == detector.get()) {
    localAndClientMsg(VLogger::ERROR, NULL, "Could not connect to CVAC Ice Services\n");
    return EXIT_FAILURE;
  }

  int resultInit = initializeDetector(detector);
  if((EXIT_SUCCESS != resultInit)) {
      
    localAndClientMsg(VLogger::ERROR, NULL, "Detector->isInitialized() failed.  Aborting IceTestClient.\n");
    return(EXIT_FAILURE);
  }
  else {
    localAndClientMsg(VLogger::DEBUG, NULL, "IceBoxTestClient detector: initialization OK. \n");
  }

  //CTest requested?
  if(5 == argc) 
  {
	  std::string lastArgStr = std::string(argv[4]);
	  if(-1 == lastArgStr.find("verifyresults")) 
	  {
		  localAndClientMsg(VLogger::ERROR, NULL, "Invalid value for argument #5: %s.  CMakeLists.txt must specify token: 'verifyresults'\n", argv[4]);
		  return(EXIT_FAILURE);
	  }
		
	  int verResult = verification(testFileFolder, detector);
	  if(EXIT_SUCCESS != verResult)
	  {
		  return(EXIT_FAILURE);
	  }
  }
  else
	{
	  // Main Loop: build RunSet from 'testFileFolder'
	  RunSet runSet;
	  Ice::PropertiesPtr props = communicator()->getProperties();
	  std::string dataDir = props->getProperty("CVAC.DataDir");
		
	  PurposedDirectoryPtr dir = new PurposedDirectory();

    localAndClientMsg(VLogger::DEBUG, NULL, "IceBoxTestClient-mainLoop setting RunSet dir: %s\n", testFileFolder.c_str());
	  dir->directory.relativePath = std::string(testFileFolder.c_str());
	  runSet.purposedLists.push_back(dir);

	  std::string _detectorName = argv[1];
    if(appData->videoInputType) {
		  dir->fileSuffixes.push_back("mpg");
      localAndClientMsg(VLogger::DEBUG_2, NULL, "Using (.mpg) extension.\n");
    }
    else {
		  dir->fileSuffixes.push_back("jpg");
    }

	  dir->recursive = true;
		
	  try
	  {	// Create our callback class so that we can be informed when process completes
		  FinishedCallbackPtr finishCallback = new FinishedCallback();
		  Ice::CallbackPtr finishedAsync = Ice::newCallback(finishCallback, &FinishedCallback::finished);
	      cvac::DetectorProperties dprops;
		  Ice::AsyncResultPtr asyncResult = detector->begin_process(ident, runSet, detectorData, dprops, finishedAsync);
		  localAndClientMsg(VLogger::DEBUG, NULL, "IceBox test client: initiated processing\n");
			
		  // end_myFunction should be call from the "finished" callback
		  //detector->end_process(asyncResult);
			
		  // Wait for the processing to complete before exiting the app
		  while (!finishCallback->hasFinished())
		  {
			  sleep(100);
		  }
		  localAndClientMsg(VLogger::DEBUG_2, NULL, "IceBox test client: finished processing\n");
	  }
	  catch (const Ice::Exception& ex)
	  {
		  localAndClientMsg(VLogger::WARN, NULL, "Ice- name():  %s\n", ex.ice_name().c_str());
		  localAndClientMsg(VLogger::WARN, NULL, "Ice- stackTrace(): \n%s\n", ex.ice_stackTrace().c_str());
		  localAndClientMsg(VLogger::WARN, NULL, "%s\n", ex.what());
		  return EXIT_FAILURE;
	  }
  }

  communicator()->shutdown();  // Shut down at the end of either branch
  return EXIT_SUCCESS;
  
  
}