Esempio n. 1
0
DaemonConfig::DaemonConfig(std::string config_file, std::string config_defaults_file) {
  CSimpleIniA ini;
  ini.SetMultiKey();
  ini.LoadFile(config_file.c_str());
  
  CSimpleIniA defaultIni;
  defaultIni.SetMultiKey();
  defaultIni.LoadFile(config_defaults_file.c_str());
  
  // Stream will only be in the user override config, never in the defaults
  CSimpleIniA::TNamesDepend values;
  ini.GetAllValues("daemon", "stream", values);

  // sort the values into the original load order
  values.sort(CSimpleIniA::Entry::LoadOrder());

  // output all of the items
  CSimpleIniA::TNamesDepend::const_iterator i;
  for (i = values.begin(); i != values.end(); ++i) { 
      stream_urls.push_back(i->pItem);
  }

  country = getString(&ini, &defaultIni, "daemon", "country", "us");
  topn = getInt(&ini, &defaultIni, "daemon", "topn", 20);
  
  storePlates = getBoolean(&ini, &defaultIni, "daemon", "store_plates", false);
  imageFolder = getString(&ini, &defaultIni, "daemon", "store_plates_location", "/tmp/");
  uploadData = getBoolean(&ini, &defaultIni, "daemon", "upload_data", false);
  upload_url = getString(&ini, &defaultIni, "daemon", "upload_address", "");
  company_id = getString(&ini, &defaultIni, "daemon", "company_id", "");
  site_id = getString(&ini, &defaultIni, "daemon", "site_id", "");
  pattern = getString(&ini, &defaultIni, "daemon", "pattern", "");
}
int AvgChoiceModule::init() {
  std::string config_path = "config.ini";

  CSimpleIniA ini;
  ini.SetMultiKey(true);

  if (ini.LoadFile(config_path.c_str()) < 0) {
    colorPrintf(ConsoleColor(ConsoleColor::red), "Can't load '%s' file!",
                config_path.c_str());
    return 1;
  }

  const char *db_path = ini.GetValue("statisctic", "db_path", NULL);
  if (!db_path) {
    colorPrintf(ConsoleColor(ConsoleColor::red), "Can't read db_path value");
    return 1;
  }

  int rc = sqlite3_open(db_path, &db);
  if (rc) {
    colorPrintf(ConsoleColor(ConsoleColor::red), "Can't open database: %s\n",
                sqlite3_errmsg(db));
    sqlite3_close(db);
    return (1);
  }
  return 0;
}
Esempio n. 3
0
bool TestStreams()
{
    const char * rgszTestFile[3] = {
        "test1-input.ini",
        "test1-output.ini",
        "test1-expected.ini"
    };

    Test oTest("TestStreams");

    CSimpleIniA ini;
    ini.SetUnicode(true);
    ini.SetMultiKey(true);
    ini.SetMultiLine(true);

    // load the file
    try {
        std::ifstream infile;
        infile.open(rgszTestFile[0], std::ifstream::in | std::ifstream::binary);
        if (ini.Load(infile) < 0) throw false;
        infile.close();
    }
    catch (...) {
        return oTest.Failure("Failed to load file");
    }

    // standard contents test
    //if (!StandardContentsTest(ini, oTest)) {
    //    return false;
    //}

    // save the file
    try {
        std::ofstream outfile;
        outfile.open(rgszTestFile[1], std::ofstream::out | std::ofstream::binary);
        if (ini.Save(outfile, true) < 0) throw false;
        outfile.close();
    }
    catch (...) {
        return oTest.Failure("Failed to save file");
    }

    // file comparison test
    if (!FileComparisonTest(rgszTestFile[1], rgszTestFile[2])) {
        return oTest.Failure("Failed file comparison");
    }
    if (!FileLoadTest(rgszTestFile[1], rgszTestFile[2])) {
        return oTest.Failure("Failed file load comparison");
    }

    return oTest.Success();
}
Esempio n. 4
0
int main( int argc, const char** argv )
{
  daemon_active = true;

  bool noDaemon = false;
  bool clockOn = false;
  std::string logFile;
  int topn;
  
  std::string configFile;
  std::string country;

  TCLAP::CmdLine cmd("OpenAlpr Daemon", ' ', Alpr::getVersion());

  TCLAP::ValueArg<std::string> countryCodeArg("c","country","Country code to identify (either us for USA or eu for Europe).  Default=us",false, "us" ,"country_code");
  TCLAP::ValueArg<std::string> configFileArg("","config","Path to the openalpr.conf file.",false, "" ,"config_file");
  TCLAP::ValueArg<int> topNArg("n","topn","Max number of possible plate numbers to return.  Default=25",false, 25 ,"topN");
  TCLAP::ValueArg<std::string> logFileArg("l","log","Log file to write to.  Default=" + DEFAULT_LOG_FILE_PATH,false, DEFAULT_LOG_FILE_PATH ,"topN");

  TCLAP::SwitchArg daemonOffSwitch("f","foreground","Set this flag for debugging.  Disables forking the process as a daemon and runs in the foreground.  Default=off", cmd, false);
  TCLAP::SwitchArg clockSwitch("","clock","Display timing information to log.  Default=off", cmd, false);

  try
  {
    
    cmd.add( countryCodeArg );
    cmd.add( topNArg );
    cmd.add( configFileArg );
    cmd.add( logFileArg );

    
    if (cmd.parse( argc, argv ) == false)
    {
      // Error occured while parsing.  Exit now.
      return 1;
    }

    country = countryCodeArg.getValue();
    configFile = configFileArg.getValue();
    logFile = logFileArg.getValue();
    topn = topNArg.getValue();
    noDaemon = daemonOffSwitch.getValue();
    clockOn = clockSwitch.getValue();
  }
  catch (TCLAP::ArgException &e)    // catch any exceptions
  {
    std::cerr << "error: " << e.error() << " for arg " << e.argId() << std::endl;
    return 1;
  }
  
  log4cplus::BasicConfigurator config;
  config.configure();
    
  if (noDaemon == false)
  {
    // Fork off into a separate daemon
    daemon(0, 0);
    
    
    log4cplus::SharedAppenderPtr myAppender(new log4cplus::RollingFileAppender(logFile));
    myAppender->setName("alprd_appender");
    // Redirect std out to log file
    logger = log4cplus::Logger::getInstance(LOG4CPLUS_TEXT("alprd"));
    logger.addAppender(myAppender);
    
    
    LOG4CPLUS_INFO(logger, "Running OpenALPR daemon in daemon mode.");
  }
  else
  {
    //log4cplus::SharedAppenderPtr myAppender(new log4cplus::ConsoleAppender());
    //myAppender->setName("alprd_appender");
    // Redirect std out to log file
    logger = log4cplus::Logger::getInstance(LOG4CPLUS_TEXT("alprd"));
    //logger.addAppender(myAppender);
    
    LOG4CPLUS_INFO(logger, "Running OpenALPR daemon in the foreground.");
  }
  
  CSimpleIniA ini;
  ini.SetMultiKey();
  
  ini.LoadFile(DAEMON_CONFIG_FILE_PATH.c_str());
  
  std::vector<std::string> stream_urls;
  
  
  CSimpleIniA::TNamesDepend values;
  ini.GetAllValues("daemon", "stream", values);

  // sort the values into the original load order
  values.sort(CSimpleIniA::Entry::LoadOrder());

  // output all of the items
  CSimpleIniA::TNamesDepend::const_iterator i;
  for (i = values.begin(); i != values.end(); ++i) { 
      stream_urls.push_back(i->pItem);
  }
  
  
  if (stream_urls.size() == 0)
  {
    LOG4CPLUS_FATAL(logger, "No video streams defined in the configuration.");
    return 1;
  }
  
  bool storePlates = ini.GetBoolValue("daemon", "store_plates", false);
  std::string imageFolder = ini.GetValue("daemon", "store_plates_location", "/tmp/");
  bool uploadData = ini.GetBoolValue("daemon", "upload_data", false);
  std::string upload_url = ini.GetValue("daemon", "upload_address", "");
  std::string site_id = ini.GetValue("daemon", "site_id", "");
  
  LOG4CPLUS_INFO(logger, "Using: " << imageFolder << " for storing valid plate images");
  
  pid_t pid;
  
  for (int i = 0; i < stream_urls.size(); i++)
  {
    pid = fork();
    if (pid == (pid_t) 0)
    {
      // This is the child process, kick off the capture data and upload threads
      CaptureThreadData* tdata = new CaptureThreadData();
      tdata->stream_url = stream_urls[i];
      tdata->camera_id = i + 1;
      tdata->config_file = configFile;
      tdata->output_images = storePlates;
      tdata->output_image_folder = imageFolder;
      tdata->country_code = country;
      tdata->site_id = site_id;
      tdata->top_n = topn;
      tdata->clock_on = clockOn;
      
      tthread::thread* thread_recognize = new tthread::thread(streamRecognitionThread, (void*) tdata);
      
      if (uploadData)
      {
	// Kick off the data upload thread
	UploadThreadData* udata = new UploadThreadData();
	udata->upload_url = upload_url;
	tthread::thread* thread_upload = new tthread::thread(dataUploadThread, (void*) udata );
      }
      
      break;
    }

    // Parent process will continue and spawn more children
  }



  while (daemon_active)
  {
    usleep(30000);
  }

}
Esempio n. 5
0
void ConfigOptions::init()
{
	//Opening ini file
	CSimpleIniA ini;
	ini.SetUnicode();
	ini.SetMultiKey();
	if (ini.LoadFile("Config.ini") == SI_OK)
	{
		/////////////////////GAMEPLAY///////////////////////////////
		//Difficulty
		m_aiThinkingTime = atoi(ini.GetValue("Gameplay", "Difficulty", "1"));
		m_p1AI = ini.GetBoolValue("Gameplay", "Player1AI", 0);
		m_p2AI = ini.GetBoolValue("Gameplay", "Player2AI", 0);
		m_dialogOn = ini.GetBoolValue("Gameplay", "ShowDialog", 0);
		m_autoReset = ini.GetBoolValue("Gameplay", "AutoReset", 0);

		/////////////////////GRAPHICS///////////////////////////////
		//Resoltion
		m_resolution = sf::Vector2i(atoi(ini.GetValue("Graphics", "ScreenWidth", "1920")), atoi(ini.GetValue("Graphics", "ScreenHeight", "1080")));
		m_inFullscreen = ini.GetBoolValue("Graphics", "FullScreen", 0);
		m_view.SetFromRect(sf::FloatRect(0, 0, (float) nativeWidth(), (float) nativeHeight()));

		//////////////////////CONTROLS/////////////////////////////
		std::string item;
		std::string val;

		//Keys
		std::map<std::string, sf::Key::Code> allKeys = getNamedKeys();

		// if there are keys and values...
		const CSimpleIniA::TKeyVal* keys = ini.GetSection("KeyboardControls");
		if (keys)
		{
			// iterate over all keys and dump the key name and value
			for (CSimpleIniA::TKeyVal::const_iterator it = keys->begin() ; it != keys->end() ; ++it)
			{
				item = it->first.pItem;
				val = it->second;
				m_iHandler.map(item, allKeys[val]);
			}
		}

		//Mouse buttons
		std::map<std::string, sf::Mouse::Button> allButtons = getNamedButtons();

		// if there are keys and values...
		const CSimpleIniA::TKeyVal* buttons = ini.GetSection("MouseControls");
		if (keys)
		{
			// iterate over all keys and dump the key name and value
			for (CSimpleIniA::TKeyVal::const_iterator it = buttons->begin() ; it != buttons->end() ; ++it)
			{
				item = it->first.pItem;
				val = it->second;
				m_iHandler.map(item, allButtons[val]);
			}
		}

		//////////////////////OTHER/////////////////////////////

		m_theme = ini.GetValue("Graphics", "Theme", "");
		if (m_theme == "Default") //default theme
			m_theme = "";
	}
	else
	{
		std::cerr << "Unable to load file : Config.ini" << std::endl;
	}
}
Esempio n. 6
0
void Config::loadCountryValues(string configFile, string country)
{
    CSimpleIniA iniObj;
    iniObj.SetMultiKey(true);
    iniObj.LoadFile(configFile.c_str());
    CSimpleIniA* ini = &iniObj;

    minPlateSizeWidthPx = getInt(ini, "", "min_plate_size_width_px", 100);
    minPlateSizeHeightPx = getInt(ini, "", "min_plate_size_height_px", 100);

    multiline = 	getBoolean(ini, "", "multiline",		false);

    string invert_val = getString(ini, "", "invert", "auto");

    if (invert_val == "always")
    {
        auto_invert = false;
        always_invert = true;
    }
    else if (invert_val == "never")
    {
        auto_invert = false;
        always_invert = false;
    }
    else
    {
        auto_invert = true;
        always_invert = false;
    }

    plateWidthMM = getFloat(ini, "", "plate_width_mm", 100);
    plateHeightMM = getFloat(ini, "", "plate_height_mm", 100);

    charHeightMM = getAllFloats(ini, "", "char_height_mm");
    charWidthMM = getAllFloats(ini, "", "char_width_mm");

    // Compute the average char height/widths
    avgCharHeightMM = 0;
    avgCharWidthMM = 0;
    for (unsigned int i = 0; i < charHeightMM.size(); i++)
    {
        avgCharHeightMM += charHeightMM[i];
        avgCharWidthMM += charWidthMM[i];
    }
    avgCharHeightMM /= charHeightMM.size();
    avgCharWidthMM /= charHeightMM.size();

    charWhitespaceTopMM = getFloat(ini, "", "char_whitespace_top_mm", 100);
    charWhitespaceBotMM = getFloat(ini, "", "char_whitespace_bot_mm", 100);
    charWhitespaceBetweenLinesMM = getFloat(ini, "", "char_whitespace_between_lines_mm", 5);

    templateWidthPx = getInt(ini, "", "template_max_width_px", 100);
    templateHeightPx = getInt(ini, "", "template_max_height_px", 100);

    charAnalysisMinPercent = getFloat(ini, "", "char_analysis_min_pct", 0);
    charAnalysisHeightRange = getFloat(ini, "", "char_analysis_height_range", 0);
    charAnalysisHeightStepSize = getFloat(ini, "", "char_analysis_height_step_size", 0);
    charAnalysisNumSteps = getInt(ini, "", "char_analysis_height_num_steps", 0);

    segmentationMinSpeckleHeightPercent = getFloat(ini, "", "segmentation_min_speckle_height_percent", 0);
    segmentationMinBoxWidthPx = getInt(ini, "", "segmentation_min_box_width_px", 0);
    segmentationMinCharHeightPercent = getFloat(ini, "", "segmentation_min_charheight_percent", 0);
    segmentationMaxCharWidthvsAverage = getFloat(ini, "", "segmentation_max_segment_width_percent_vs_average", 0);

    plateLinesSensitivityVertical = getFloat(ini, "", "plateline_sensitivity_vertical", 0);
    plateLinesSensitivityHorizontal = getFloat(ini, "", "plateline_sensitivity_horizontal", 0);

    ocrLanguage = getString(ini, "", "ocr_language", "none");

    postProcessRegexLetters = getString(ini, "", "postprocess_regex_letters", "\\pL");
    postProcessRegexNumbers = getString(ini, "", "postprocess_regex_numbers", "\\pN");

    ocrImageWidthPx = round(((float) templateWidthPx) * ocrImagePercent);
    ocrImageHeightPx = round(((float)templateHeightPx) * ocrImagePercent);
    stateIdImageWidthPx = round(((float)templateWidthPx) * stateIdImagePercent);
    stateIdimageHeightPx = round(((float)templateHeightPx) * stateIdImagePercent);

    postProcessMinCharacters = getInt(ini, "", "postprocess_min_characters", 4);
    postProcessMaxCharacters = getInt(ini, "", "postprocess_max_characters", 8);
}