Ejemplo n.º 1
0
int ClientApp::verification(std::string testFilePath, DetectorPrx detector)
{
	appData->isVerification = true;
	Purpose positive(POSITIVE, 0);
	RunSet runSet;
	std::string suffix;
	if(appData->videoInputType)
	{
		suffix = "mpg";
	}
	else
	{
		suffix = "jpg";
	}
	
	if(appData->multiclassDetection)
	{
		std::string testFileName0 = (m_detectorName + "0." + suffix);
		std::string testFileName1 = (m_detectorName + "1." + suffix);
		std::string testFileName2 = (m_detectorName + "2." + suffix);

		addToRunSet(runSet, testFilePath, testFileName0, Purpose(MULTICLASS, 0));
		addToRunSet(runSet, testFilePath, testFileName1, Purpose(MULTICLASS, 1));
		addToRunSet(runSet, testFilePath, testFileName2, Purpose(MULTICLASS, 2));
	}
	else
	{
    localAndClientMsg(VLogger::DEBUG, NULL, "IceBoxTestClient-verification setting RunSet dir: %s\n", testFilePath.c_str());
		std::string testFileName = (m_detectorName + "." + suffix);
		addToRunSet(runSet, testFilePath, testFileName, positive);  // Path relative to CVAC.data dir
	}
	
	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);
		
		// 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 verification\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();
	if(appData->needSBDVerified)
	{
		if(false == SBDResultsOK())
		{
			appData->detectionsVerified.push_back(false);  // Add SBD-test failure
		}
	}

  // Scan for missed detections
  bool missedDetections = false;
  while(appData->detectionsVerified.size() > 0) {

    bool element = appData->detectionsVerified.back();
    appData->detectionsVerified.pop_back();

    if(false == element) {
      missedDetections = true;
    }
  }

  if(missedDetections) {
    return EXIT_FAILURE;
  }

  return EXIT_SUCCESS;
}
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;
  
  
}