Пример #1
0
DetectorPrx initIceConnection(const std::string& detectorNameStr,
                              Ice::Identity& det_cb,
                              DetectorCallbackHandlerPtr cr)
{
  
  initIce(detectorNameStr);
  
  Ice::PropertiesPtr props = iceComm->getProperties();
  std::string proxStr = detectorNameStr + ".Proxy";
  DetectorPrx detector = NULL;
  try
  {
  
    detector = DetectorPrx::checkedCast(
        iceComm->propertyToProxy(proxStr)->ice_twoway());
  }
  catch (const IceUtil::NullHandleException& e)
  {
    localAndClientMsg( VLogger::ERROR, NULL, "Invalid proxy: '%s'. %s\n", 
                       detectorNameStr.c_str(), e.what());
    return NULL;
  }

  Ice::ObjectAdapterPtr adapter = iceComm->createObjectAdapter("");
  det_cb.name = IceUtil::generateUUID();
  det_cb.category = "";
  adapter->add(cr, det_cb);
  adapter->activate();
  detector->ice_getConnection()->setAdapter(adapter);    
  
  // note that we need an ObjectAdapter to permit bidirectional communication
  // if we want to get past firewalls without Glacier2
  
  return detector;  // Success
}
Пример #2
0
int ClientApp::initializeDetector(DetectorPrx detector)
{
	DetectorData detectorData;
	localAndClientMsg(VLogger::DEBUG, NULL, "Client using Detector-name: %s\n", detector->ice_getIdentity().name.c_str());
	detectorData.type = ::cvac::FILE;
	
	// If a detector dat file was passed then use that instead of getting it from the config file
	if (m_detectorData.length() > 0)
	{
		detectorData.file.directory.relativePath = getFilePath(m_detectorData);
		detectorData.file.filename = getFileName(m_detectorData);
	}
	else
	{ // Determine which data files to pass as detector data based on .DetectorFilename in 'config.client'
		std::string filenameStr = m_detectorName + ".DetectorFilename";
		Ice::PropertiesPtr props = communicator()->getProperties();
		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;
		}
		
		if ((filename.length() > 1 && filename[1] == ':' )||
			filename[0] == '/' ||
			filename[0] == '\\')
		{  // absolute path
			int idx = filename.find_last_of('/');
			detectorData.file.directory.relativePath = filename.substr(0, idx);
			detectorData.file.filename = filename.substr(idx+1, filename.length() - idx);
		}
		else
		{ //Add the current directory
			detectorData.file.directory.relativePath = "detectors";
			detectorData.file.filename = filename;
		}
	}
	try
	{
		localAndClientMsg(VLogger::INFO, NULL, "Initializing detector with relativePath: %s\n", detectorData.file.directory.relativePath.c_str());
		localAndClientMsg(VLogger::INFO, NULL, "Initializing detector with filename: %s\n", detectorData.file.filename.c_str());
		detector->initialize(5, detectorData);
		localAndClientMsg(VLogger::DEBUG, NULL, "IceBox test client: initialized the detector\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;
	}

  return EXIT_SUCCESS;
}
Пример #3
0
	void finished(const Ice::AsyncResultPtr& result)
	{
		DetectorPrx detector = DetectorPrx::uncheckedCast(result->getProxy());

		try
		{
			detector->end_process(result);
			localAndClientMsg(VLogger::DEBUG, NULL, "FinishedCallback: detector finished.\n");
		}
		catch (const Ice::Exception& e)
		{
			localAndClientMsg(VLogger::WARN, NULL, "Exception: %s\n", 
				 e.ice_name().c_str());
		}
		mFinished = true;
	}
Пример #4
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;
}
Пример #5
0
int ClientApp::initializeDetector(DetectorPrx detector)
{

	localAndClientMsg(VLogger::DEBUG, NULL, "Client using Detector-name: %s\n", detector->ice_getIdentity().name.c_str());
	
	// If a detector dat file was passed then use that instead of getting it from the config file
	if (m_detectorData.length() > 0)
	{
		detectorData.directory.relativePath = getFileDirectory(m_detectorData);
		detectorData.filename = getFileName(m_detectorData);
	}
	else
	{ // Determine which data files to pass as detector data based on .DetectorFilename in 'config.client'
		std::string filenameStr = m_detectorName + ".DetectorFilename";
		Ice::PropertiesPtr props = communicator()->getProperties();
		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;
		}
		
		if ((filename.length() > 1 && filename[1] == ':' )||
			filename[0] == '/' ||
			filename[0] == '\\')
		{  // absolute path
			int idx = filename.find_last_of('/');
			detectorData.directory.relativePath = filename.substr(0, idx);
			detectorData.filename = filename.substr(idx+1, filename.length() - idx);
		}
		else
		{ //Add the current directory
			detectorData.directory.relativePath = "detectors";
			detectorData.filename = filename;
		}
	}
	

  return EXIT_SUCCESS;

}
Пример #6
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;
}
Пример #7
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;
  
  
}
Пример #8
0
 /// usage:
    ///IceBoxTestClientApp.exe <detector> <directory>
    /// <detector>: The name of the detector (found in the config.client file)
    /// <directory>: The full path to a folder containing images to process
    /// Returns 0 on success ('EXIT_SUCCESS'), and 1 on failure ('EXIT_FAILURE')
DetectorPrx ClientApp::initIceConnection(std::string detectorNameStr)
{  // Connect to the Ice Service
	Ice::PropertiesPtr props = communicator()->getProperties();
    std::string proxStr = detectorNameStr + ".Proxy";
    DetectorPrx detector = NULL;
    try
    {
        detector = DetectorPrx::checkedCast(
                               communicator()->propertyToProxy(proxStr)->ice_twoway());
    }
    catch (const IceUtil::NullHandleException& e)
    {
       localAndClientMsg(VLogger::WARN, NULL, "Invalid proxy: '%s'. %s\n", 
               detectorNameStr.c_str(), e.what());
       return NULL;
    }

    Ice::ObjectAdapterPtr adapter = communicator()->createObjectAdapter("");
    ident.name = IceUtil::generateUUID();
    ident.category = "";
    DetectorCallbackHandlerPtr cr = new CallbackHandlerI(appData);
    adapter->add(cr, ident);
    adapter->activate();
    detector->ice_getConnection()->setAdapter(adapter);    

    // note that we need an ObjectAdapter to permit bidirectional communication
    // if we want to get past firewalls without Glacier2

    localAndClientMsg(VLogger::DEBUG, NULL, "IceBox test client: created callbackHandler proxy\n");
                
    if(!detector)
    {
		localAndClientMsg(VLogger::WARN, NULL, "%s: invalid proxy \n", appName());
		return NULL;
    }
    else
		return detector;  // Success

#if 0
    Ice::ObjectAdapterPtr adapter = communicator()->createObjectAdapter("");
    Ice::Identity ident;
    ident.name = IceUtil::generateUUID();
    ident.category = "";
    CallbackReceiverPtr cr = new CallbackReceiverI;
    adapter->add(cr, ident);
    adapter->activate();
    detector->ice_getConnection()->setAdapter(adapter);
    printf("about to call addClient\n");
//    RunSet runSet;
//    detector->process(ident, runSet);
    detector->addClient(ident);
    printf("just called addClient\n");
    communicator()->waitForShutdown();

    return 0;
#elif 0
    Ice::ObjectAdapterPtr adapter = communicator()->createObjectAdapter("");
    Ice::Identity ident;
    ident.name = IceUtil::generateUUID();
    ident.category = "";
    DetectorCallbackHandlerPtr cr = new CallbackHandlerI;
    adapter->add(cr, ident);
    adapter->activate();
    detector->ice_getConnection()->setAdapter(adapter);
    printf("about to call process\n");
    RunSet runSet;
    detector->process(ident, runSet);
//    detector->addClient(ident);
    printf("just called process\n");
    communicator()->waitForShutdown();

    return 0;
#endif

}