void FileWatcher::Worker::AddWatch(std::string path, FileEventCallback_t callback) { m_Mutex.lock(); boost::filesystem::path bpath(path); m_FileCallbacks[bpath] = callback; if (boost::filesystem::exists(bpath)) { m_FileInfo[bpath] = GetFileInfo(bpath); } m_Mutex.unlock(); }
Ogre::String Utils::FindResourcePath(Ogre::String path, Ogre::String filename) { boost::filesystem::path bpath(path.c_str()); for (boost::filesystem::directory_iterator i(bpath); i != boost::filesystem::directory_iterator(); i++) { Ogre::String file = Ogre::String((*i).path().leaf().c_str()); if (file == filename) return (*i).path().file_string(); if (boost::filesystem::is_directory((*i))) { Ogre::String csearch = FindResourcePath((*i).path().directory_string().c_str(), filename); if (csearch != "") return csearch; } } return ""; }
std::string CXMLExporterBase::GetFileName(BSTR path) { #ifdef _WINDOWS _bstr_t bpath(path, true); std::string filePath = (const char*) bpath; #else std::string filePath = BSTRToPath(path); #endif long index = static_cast<long>(filePath.rfind(47)); if (index == -1) { index = static_cast<long>(filePath.rfind(92)); } std::string filename = filePath.substr(index+1,m_fileName.size()); return filename; }
ompl::base::PlannerStatus ompl::geometric::LBTRRT::solve(const base::PlannerTerminationCondition &ptc) { checkValidity(); // update goal and check validity base::Goal *goal = pdef_->getGoal().get(); base::GoalSampleableRegion *goal_s = dynamic_cast<base::GoalSampleableRegion*>(goal); if (!goal) { OMPL_ERROR("%s: Goal undefined", getName().c_str()); return base::PlannerStatus::INVALID_GOAL; } // update start and check validity while (const base::State *st = pis_.nextStart()) { Motion *motion = new Motion(si_); si_->copyState(motion->state_, st); motion->id_ = nn_->size(); idToMotionMap_.push_back(motion); nn_->add(motion); lowerBoundGraph_.addVertex(motion->id_); } if (nn_->size() == 0) { OMPL_ERROR("%s: There are no valid initial states!", getName().c_str()); return base::PlannerStatus::INVALID_START; } if (nn_->size() > 1) { OMPL_ERROR("%s: There are multiple start states - currently not supported!", getName().c_str()); return base::PlannerStatus::INVALID_START; } if (!sampler_) sampler_ = si_->allocStateSampler(); OMPL_INFORM("%s: Starting planning with %u states already in datastructure", getName().c_str(), nn_->size()); Motion *solution = lastGoalMotion_; Motion *approxSol = nullptr; double approxdif = std::numeric_limits<double>::infinity(); // e*(1+1/d) K-nearest constant, as used in RRT* double k_rrg = boost::math::constants::e<double>() + boost::math::constants::e<double>() / (double)si_->getStateDimension(); Motion *rmotion = new Motion(si_); base::State *rstate = rmotion->state_; base::State *xstate = si_->allocState(); unsigned int statesGenerated = 0; bestCost_ = lastGoalMotion_ ? lastGoalMotion_->costApx_ : std::numeric_limits<double>::infinity(); while (ptc() == false) { iterations_++; /* sample random state (with goal biasing) */ if (goal_s && rng_.uniform01() < goalBias_ && goal_s->canSample()) goal_s->sampleGoal(rstate); else sampler_->sampleUniform(rstate); /* find closest state in the tree */ Motion *nmotion = nn_->nearest(rmotion); base::State *dstate = rstate; /* find state to add */ double d = si_->distance(nmotion->state_, rstate); if (d == 0) // this takes care of the case that the goal is a single point and we re-sample it multiple times continue; if (d > maxDistance_) { si_->getStateSpace()->interpolate(nmotion->state_, rstate, maxDistance_ / d, xstate); dstate = xstate; } if (checkMotion(nmotion->state_, dstate)) { statesGenerated++; /* create a motion */ Motion *motion = new Motion(si_); si_->copyState(motion->state_, dstate); /* update fields */ double distN = distanceFunction(nmotion, motion); motion->id_ = nn_->size(); idToMotionMap_.push_back(motion); lowerBoundGraph_.addVertex(motion->id_); motion->parentApx_ = nmotion; std::list<std::size_t> dummy; lowerBoundGraph_.addEdge(nmotion->id_, motion->id_, distN, false, dummy); motion->costLb_ = nmotion->costLb_ + distN; motion->costApx_ = nmotion->costApx_ + distN; nmotion->childrenApx_.push_back(motion); std::vector<Motion*> nnVec; unsigned int k = std::ceil(k_rrg * log((double)(nn_->size() + 1))); nn_->nearestK(motion, k, nnVec); nn_->add(motion); // if we add the motion before the nearestK call, we will get ourselves... IsLessThan isLessThan(this, motion); std::sort(nnVec.begin(), nnVec.end(), isLessThan); //-------------------------------------------------// // Rewiring Part (i) - find best parent of motion // //-------------------------------------------------// if (motion->parentApx_ != nnVec.front()) { for (std::size_t i(0); i < nnVec.size(); ++i) { Motion *potentialParent = nnVec[i]; double dist = distanceFunction(potentialParent, motion); considerEdge(potentialParent, motion, dist); } } //------------------------------------------------------------------// // Rewiring Part (ii) // // check if motion may be a better parent to one of its neighbors // //------------------------------------------------------------------// for (std::size_t i(0); i < nnVec.size(); ++i) { Motion *child = nnVec[i]; double dist = distanceFunction(motion, child); considerEdge(motion, child, dist); } double dist = 0.0; bool sat = goal->isSatisfied(motion->state_, &dist); if (sat) { approxdif = dist; solution = motion; } if (dist < approxdif) { approxdif = dist; approxSol = motion; } if (solution != nullptr && bestCost_ != solution->costApx_) { OMPL_INFORM("%s: approximation cost = %g", getName().c_str(), solution->costApx_); bestCost_ = solution->costApx_; } } } bool solved = false; bool approximate = false; if (solution == nullptr) { solution = approxSol; approximate = true; } if (solution != nullptr) { lastGoalMotion_ = solution; /* construct the solution path */ std::vector<Motion*> mpath; while (solution != nullptr) { mpath.push_back(solution); solution = solution->parentApx_; } /* set the solution path */ PathGeometric *path = new PathGeometric(si_); for (int i = mpath.size() - 1 ; i >= 0 ; --i) path->append(mpath[i]->state_); // Add the solution path. base::PathPtr bpath(path); base::PlannerSolution psol(bpath); psol.setPlannerName(getName()); if (approximate) psol.setApproximate(approxdif); pdef_->addSolutionPath(psol); solved = true; } si_->freeState(xstate); if (rmotion->state_) si_->freeState(rmotion->state_); delete rmotion; OMPL_INFORM("%s: Created %u states", getName().c_str(), statesGenerated); return base::PlannerStatus(solved, approximate); }
/** * @function main */ int main( int argc, char** argv ){ /* std::string test = " uressat - \nHerrn 1\nRein-hard Scherf |\nZur Grünen Schildmühle 2 - \n99084 Erfurt"; ExtractAddress* eat = new ExtractAddress(); eat->setString(test); eat->extract(); std::string testsql = "select GET_SORTBOX('"+eat->getStreetName()+" "+eat->getZipCode()+" "+eat->getTown()+"','"+eat->getZipCode()+"','"+eat->getHouseNumber()+"','123') res"; std::cout << "testsql " << testsql << std::endl; exit(1); */ bool usePZA = false; if(const char* env_pza = std::getenv("USEPZA")){ usePZA = (atoi(env_pza)==1)?true:false; } std::string protokollsql = ""; std::string imagepath = "/imagedata/"; if(const char* env_path = std::getenv("IMAGEPATH")){ imagepath = std::string(env_path); } std::string imagepath_result = "/imagedata/result/"; if(const char* env_pathir = std::getenv("IMAGEPATH_RESULT")){ imagepath_result = std::string(env_pathir); } std::string force_customer = ""; if(const char* env_force_customer = std::getenv("FORCECUSTOMER")){ force_customer = std::string(env_force_customer); } int keepfiles = 0; if(const char* env_keep = std::getenv("KEEPFILES")){ keepfiles = atoi(env_keep); } int forceaddress = 0; if(const char* env_forceaddress = std::getenv("FORCEADDRESS")){ forceaddress = atoi(env_forceaddress); } std::string store_original = ""; if(const char* env_store_original = std::getenv("STORE_ORIGINAL")){ store_original = std::string(env_store_original); } const char* db_host = "localhost"; if(const char* env_host = std::getenv("DB_HOST")){ db_host = env_host; } const char* db_user = "******"; if(const char* env_user = std::getenv("DB_USER")){ db_user = env_user; } const char* db_password = "******"; if(const char* env_password = std::getenv("DB_PASSWORD")){ db_password = env_password; } const char* db_name = "sorter"; if(const char* env_dbname = std::getenv("DB_NAME")){ db_name = env_dbname; } bool window = false; if(const char* env_window = std::getenv("DEBUGWINDOW")){ window = (atoi(env_window)==1)?true:false; } bool windowalltogether = false; if(const char* env_windowa = std::getenv("DEBUGWINDOW_ALL")){ windowalltogether = (atoi(env_windowa)==1)?true:false; } int window_wait = 500; if(const char* env_windowwait = std::getenv("DEBUGWINDOWWAIT")){ window_wait = atoi(env_windowwait); } bool debug = false; if(const char* env_debug = std::getenv("DEBUG")){ debug = (atoi(env_debug)==1)?true:false; } bool headOver = false; if(const char* env_hover = std::getenv("HEAD_OVER")){ headOver = (atoi(env_hover)==1)?true:false; } bool psmAuto = false; if(const char* env_psmAuto = std::getenv("PSM_AUTO")){ psmAuto = (atoi(env_psmAuto)==1)?true:false; } bool light_up_original = false; if(const char* env_light_up_original = std::getenv("LIGHT_UP_ORIGINAL")){ light_up_original = (atoi(env_light_up_original)==1)?true:false; } bool try_reduced = false; if(const char* env_try_reduced = std::getenv("TRY_REDUCED")){ try_reduced = (atoi(env_try_reduced)==1)?true:false; } bool rotate_inline = true; if(const char* env_rotate_inline = std::getenv("ROTATE_INLINE")){ rotate_inline = (atoi(env_rotate_inline)==1)?true:false; } bool barcode_light_correction = true; if(const char* env_barcode_light_correction = std::getenv("BC_LIGHT_CORRECTION")){ barcode_light_correction = (atoi(env_barcode_light_correction)==1)?true:false; } int analysisType=1; if(const char* env_atype = std::getenv("ANALYSETYPE")){ analysisType = atoi(env_atype); } int subtractMean=20; if(const char* env_subtractMean = std::getenv("ADAPTIVE_THRESH_SUBTRACT_MEAN")){ subtractMean = atoi(env_subtractMean); } int blockSize=55; if(const char* env_blockSize = std::getenv("ADAPTIVE_THRESH_BLOCK_SIZE")){ blockSize = atoi(env_blockSize); } std::cout << "ADAPTIVE_THRESH_SUBTRACT_MEAN="<<subtractMean << std::endl; std::cout << "ADAPTIVE_THRESH_BLOCK_SIZE="<<blockSize << std::endl; std::cout << "PSM_AUTO="<<psmAuto << std::endl; int barcode_algorthim=0; if(const char* env_ba = std::getenv("BARCODE_ALGORTHIM")){ barcode_algorthim = atoi(env_ba); } std::string machine_id = "00"; if(const char* env_machine_id = std::getenv("MACHINEID")){ machine_id = std::string(env_machine_id); } const char* scale = "1.38"; if(const char* env_scale = std::getenv("SCALE")){ scale = env_scale; } const char* width = "28"; if(const char* env_width = std::getenv("WIDTH_CM")){ width = env_width; } std::string mandant = "0000"; std::string modell = "Clearing"; if(const char* env_mandant = std::getenv("MANDANT")){ mandant = env_mandant; } if(const char* env_modell = std::getenv("MODELL")){ modell = env_modell; } double t = (double)cv::getTickCount(); int cthread = 0; MYSQL *con = mysql_init(NULL); mysql_options(con, MYSQL_SET_CHARSET_NAME, "utf8"); mysql_options(con, MYSQL_INIT_COMMAND, "SET NAMES utf8"); if (con == NULL){ fprintf(stderr, "%s\n", mysql_error(con)); exit(1); } if (mysql_real_connect(con, db_host, db_user, db_password, db_name, 0, NULL, 0) == NULL){ fprintf(stderr, "%s\n", mysql_error(con)); mysql_close(con); exit(1); } std::string sql = ""; ImageRecognize* ir = new ImageRecognize(); ir->debug=debug; ir->con = con; ir->machine_id = machine_id; ir->try_reduced = try_reduced; ir->psmAuto = psmAuto; ir->light_up_original = light_up_original; ir->rotate_inline=rotate_inline; ir->showWindow=window; ir->forceaddress=forceaddress; ir->barcode_light_correction=barcode_light_correction; std::cout << "debug window" << window << std::endl; ir->analysisType=analysisType; ir->headOver = headOver; ir->barcode_algorthim = barcode_algorthim; ir->window_wait = window_wait; ir->windowalltogether = windowalltogether; ir->subtractMean=subtractMean; ir->blockSize = blockSize; if (usePZA){ ir->cmWidth = 21; ir->scale = 1; ir->openPZA(argv[1]); }else{ ir->cmWidth = std::atoi(width); if (debug){ std::cout << "WIDTH_CM " << width << std::endl; std::cout << "SCALE " << scale << std::endl; } ir->scale = std::atof(scale); ir->open(argv[1]); } std::string fullname(argv[1]); boost::filesystem::path bpath(argv[1]); std::string fname = bpath.filename().c_str(); std::string kundenid = ""; std::string product = ""; std::string bbs_check_sql = ""; std::vector<int> params; params.push_back(CV_IMWRITE_JPEG_QUALITY); params.push_back(80); std::vector<std::string> strs; boost::split(strs,fname,boost::is_any_of("N")); if (strs.size()==2){ kundenid=strs[0]; fname=strs[1]; } if (strs.size()==3){ kundenid=strs[0]; product=strs[1]; fname=strs[2]; } if (force_customer.length()>0){ kundenid = force_customer; } std::string sql_modell = "set @svmodell='"+modell+"'"; if (mysql_query(con, sql_modell.c_str())){ } if ( (forceaddress==1)||(ir->code.length()>4)){ if ((forceaddress==1)&&(ir->code.length()<=4)){ std::string fcode = fname; boost::replace_all(fcode, "nocode.", ""); boost::replace_all(fcode, "noaddress.", ""); boost::replace_all(fcode, ".tiff", ""); boost::replace_all(fcode, ".jpg", ""); ir->code=fcode; } std::string sg = ""; std::string sf = "NA"; std::string login = "******"; std::string strasse = ""; std::string hausnummer = ""; std::string plz = ""; std::string ort = ""; if (ir->addresstext.length()>0){ ExtractAddress* ea = new ExtractAddress(); std::string sql_addresstext = boost::replace_all_copy(ir->addresstext, "'", " "); ea->setString(sql_addresstext); ea->extract(); sql = "delete from ocrs where code = '"+ir->code+"'; "; if (mysql_query(con, sql.c_str())){ } sql = "insert into ocrs (code,ocrtext,street,housenumber,zipcode,town) values ('"+ir->code+"','"+sql_addresstext+"','"+ea->getStreetName()+"','"+ea->getHouseNumber()+"','"+ea->getZipCode()+"','"+ea->getTown()+"') "; if (mysql_query(con, sql.c_str())){ } if (ea->getStreetName().length()>1){ std::string fuzzysql = "CALL SET_SORTBOX('" +sql_addresstext +"','"+ea->getZipCode() +"','"+ea->getHouseNumber() +"','"+kundenid +"','"+product +"','"+ir->code +"', @stortiergang" +", @stortierfach" +", @strasse" +", @plz" +", @ort" +")"; if (debug){ std::cout << "fuzzysql " << fuzzysql << std::endl; } if (mysql_query(con, fuzzysql.c_str())){ fprintf(stderr, "%s\n", mysql_error(con)); mysql_close(con); exit(1); } std::string resultsql = "SELECT @stortiergang sg,@stortierfach sf,@strasse str,@plz plz,@ort ort"; if (mysql_query(con, resultsql.c_str())){ fprintf(stderr, "%s\n", mysql_error(con)); mysql_close(con); exit(1); } sf = "NT"; sg = "NT"; login = "******"; MYSQL_RES *result; MYSQL_ROW row; unsigned int num_fields; unsigned int i; result = mysql_use_result(con); num_fields = mysql_num_fields(result); while ((row = mysql_fetch_row(result))){ unsigned long *lengths; lengths = mysql_fetch_lengths(result); //sg = row[0]; //sf = row[1]; //std::cout << "sg " << row[0] << ", sf " << row[1] << std::endl; } if (debug){ std::cout << "good" << std::endl; } std::string newfile = imagepath_result+"good."+ir->code+".jpg"; cv::imwrite(newfile.c_str(),ir->resultMat,params); if (store_original!=""){ cv::imwrite( ( store_original+"good."+ir->code+".jpg" ).c_str(),ir->orignalImage); } bbs_check_sql = "call BBS_CHECK_OCR_ID('"+machine_id+"','good','','"+ir->code+"')"; if (mysql_query(con, bbs_check_sql.c_str())){ fprintf(stderr, "%s\n", mysql_error(con)); } if (keepfiles==0){ if ( remove( fullname.c_str() ) != 0 ) { perror( "Error deleting file" ); exit(1); } } }else{ // there is no streetname if (debug){ std::cout << "no address: there is no streetname " << ea->getStreetName() << ": " << ea->getZipCode() << std::endl; } std::string newfile = imagepath_result+"noaddress."+ir->code+".jpg"; cv::imwrite(newfile.c_str(),ir->resultMat,params); /* protokollsql = "update protokoll set state='noaddress' where code = '"+ir->code+"'; "; if (mysql_query(con, protokollsql.c_str())){ } */ bbs_check_sql = "call BBS_CHECK_OCR_ID('"+machine_id+"','noaddress','nostreet','"+ir->code+"')"; if (mysql_query(con, bbs_check_sql.c_str())){ fprintf(stderr, "%s\n", mysql_error(con)); } if (store_original!=""){ cv::imwrite( ( store_original+"noaddress."+ir->code+".jpg" ).c_str(),ir->orignalImage); } if (keepfiles==0){ if( remove( fullname.c_str() ) != 0 ){ perror( "Error deleting file" ); exit(1); } } } }else{ // there is no adresstext if (debug){ std::cout << "no address *" << std::endl; } std::string newfile = imagepath_result+"noaddress."+ir->code+".jpg"; if (ir->resultMat.cols>100){ cv::imwrite(newfile.c_str(),ir->resultMat,params); }else{ cv::imwrite( newfile.c_str(),ir->orignalImage,params); } bbs_check_sql = "call BBS_CHECK_OCR_ID('"+machine_id+"','noaddress','nozipcode','"+ir->code+"')"; if (mysql_query(con, bbs_check_sql.c_str())){ fprintf(stderr, "%s\n", mysql_error(con)); } if (store_original!=""){ cv::imwrite( ( store_original+"noaddress."+ir->code+".jpg" ).c_str(),ir->orignalImage); } if (keepfiles==0){ if( remove( fullname.c_str() ) != 0 ){ perror( "Error deleting file" ); exit(1); } } } }else{ // ok there is no barcode // move that file if (debug){ std::cout << "no code" << std::endl; } std::string newfile = imagepath_result+"nocode."+fname+".jpg"; cv::imwrite(newfile.c_str(),ir->orignalImage,params); if (store_original!=""){ cv::imwrite( ( store_original+"nocode."+fname+".jpg" ).c_str(),ir->orignalImage); } /* protokollsql = "update protokoll set state='nocode' where code = '"+ir->code+"'; "; if (mysql_query(con, protokollsql.c_str())){ } */ bbs_check_sql = "call BBS_CHECK_OCR('"+machine_id+"','nocode','')"; if (mysql_query(con, bbs_check_sql.c_str())){ fprintf(stderr, "%s\n", mysql_error(con)); } if (keepfiles==0){ if( remove( fullname.c_str() ) != 0 ) { perror( "Error deleting file" ); exit(1); } } } mysql_close(con); exit(0); return -1; }