void ViewController::initialize( DisplayContext* context ) { context_ = context; std::stringstream ss; static int count = 0; ss << "ViewControllerCamera" << count++; camera_ = context_->getSceneManager()->createCamera( ss.str() ); context_->getSceneManager()->getRootSceneNode()->attachObject( camera_ ); setValue( formatClassId( getClassId() )); setReadOnly( true ); // Do subclass initialization. onInitialize(); cursor_ = getDefaultCursor(); standard_cursors_[Default] = getDefaultCursor(); standard_cursors_[Rotate2D] = makeIconCursor( "package://rviz/icons/rotate.svg" ); standard_cursors_[Rotate3D] = makeIconCursor( "package://rviz/icons/rotate_cam.svg" ); standard_cursors_[MoveXY] = makeIconCursor( "package://rviz/icons/move2d.svg" ); standard_cursors_[MoveZ] = makeIconCursor( "package://rviz/icons/move_z.svg" ); standard_cursors_[Zoom] = makeIconCursor( "package://rviz/icons/zoom.svg" ); standard_cursors_[Crosshair] = makeIconCursor( "package://rviz/icons/crosshair.svg" ); updateNearClipDistance(); updateStereoProperties(); if (!RenderSystem::get()->isStereoSupported()) { stereo_enable_->setBool(false); stereo_enable_->hide(); } }
// Loading and saving the flags // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ // // Tools with a fixed set of Property objects representing adjustable // parameters are typically just created in the tool's constructor and // added to the Property container (getPropertyContainer()). In that // case, the Tool subclass does not need to override load() and save() // because the default behavior is to read all the Properties in the // container from the Config object. // // Here however, we have a list of named flag positions of unknown // length, so we need to implement save() and load() ourselves. // // We first save the class ID to the config object so the // rviz::ToolManager will know what to instantiate when the config // file is read back in. void FlagTool3D::save( rviz::Config config ) const { config.mapSetValue( "Class", getClassId() ); // The top level of this tool's Config is a map, but our flags // should go in a list, since they may or may not have unique keys. // Therefore we make a child of the map (``flags_config``) to store // the list. rviz::Config flags_config = config.mapMakeChild( "Flags" ); // To read the positions and names of the flags, we loop over the // the children of our Property container: rviz::Property* container = getPropertyContainer(); int num_children = container->numChildren(); for( int i = 0; i < num_children; i++ ) { rviz::Property* position_prop = container->childAt( i ); // For each Property, we create a new Config object representing a // single flag and append it to the Config list. rviz::Config flag_config = flags_config.listAppendNew(); // Into the flag's config we store its name: flag_config.mapSetValue( "Name", position_prop->getName() ); // ... and its position. position_prop->save( flag_config ); } }
//Get a binary code associated to a class cv::Mat annTrain::getClassCode(const std::set<std::string>& classes, const std::string& classname) { cv::Mat code = cv::Mat::zeros(cv::Size((int)classes.size(), 1), CV_32F); int index = getClassId(classes, classname); code.at<float>(index) = 1; return code; }
void ViewController::save( Config config ) const { config.mapSetValue( "Class", getClassId() ); config.mapSetValue( "Name", getName() ); Property::save( config ); }
// ###################################################################### void RecurBayes::learn(std::vector<double> &fv, const char *name, uint fix) { //get the class id int cls = getClassId(name); if (cls == -1) //this is a new class, add it to the network cls = addClass(name); ASSERT(fv.size() == itsNumFeatures); //update the class freq ASSERT((uint)cls < itsNumClasses); itsClassFreq[cls]++; //compute the stddev and mean of each feature //This algorithm is due to Knuth (The Art of Computer Programming, volume 2: // Seminumerical Algorithms, 3rd edn., p. 232. Boston: Addison-Wesley.) for (uint i=0; i<fv.size(); i++){ double val = fv[i]; double delta = val - itsMean[cls][fix][i]; itsMean[cls][fix][i] += delta/itsClassFreq[cls]; if (itsClassFreq[cls] > 3) { itsVar[cls][fix][i] = (itsVar[cls][fix][i]*(itsClassFreq[cls]-2)) + delta*(val - itsMean[cls][fix][i]); } if (itsClassFreq[cls] > 1) //watch for divide by 0 itsVar[cls][fix][i] /= double(itsClassFreq[cls]-1); } }
// ###################################################################### int RecurBayes::addClass(const char *name) { //Add a new class //check if the class exsists if (getClassId(name) == -1) { itsClassNames.push_back(std::string(name)); itsMean.push_back(std::vector<std::vector<double> > (itsNumFix, std::vector<double>(itsNumFeatures,0))); itsVar.push_back(std::vector<std::vector<double> > (itsNumFix, std::vector<double>(itsNumFeatures,0.01))), itsClassFreq.push_back(1); return itsNumClasses++; } return -1; }
void OrthoViewControllerCustom::initialize( DisplayContext* context, rviz::RenderPanel* panel ) { //ROS_INFO("INITIALIZE"); bool initialized = false; if(context != NULL) context_ = context; else initialized = true; panel_ = panel; if(!camera_) camera_ = panel_->getCamera(); setValue( formatClassId( getClassId() )); setReadOnly( true ); // Do subclass initialization. if(!initialized) onInitialize(); /*cursor_ = getDefaultCursor(); standard_cursors_[Default] = getDefaultCursor(); standard_cursors_[Rotate2D] = makeIconCursor( "package://rviz/icons/rotate.svg" ); standard_cursors_[Rotate3D] = makeIconCursor( "package://rviz/icons/rotate_cam.svg" ); standard_cursors_[MoveXY] = makeIconCursor( "package://rviz/icons/move2d.svg" ); standard_cursors_[MoveZ] = makeIconCursor( "package://rviz/icons/move_z.svg" ); standard_cursors_[Zoom] = makeIconCursor( "package://rviz/icons/zoom.svg" ); standard_cursors_[Crosshair] = makeIconCursor( "package://rviz/icons/crosshair.svg" ); updateNearClipDistance();*/ }
void annTrain::processClassAndDescForTest(const std::string& classname, const cv::Mat& descriptors) { // Get histogram of visual words using bag of words technique cv::Mat bowFeatures = getBOWFeatures(descriptors, networkInputSize); cv::normalize(bowFeatures, bowFeatures, 0, bowFeatures.rows, cv::NORM_MINMAX, -1, cv::Mat()); testSamples.push_back(bowFeatures); testOutputExpected.push_back(getClassId(classes, classname)); };
void MaxEntTrainer::Add_Event(EventSet &events, const char *name, const char *data) { const string delims(" "); MaxEntEvent *event = new MaxEntEvent; getIds(data, *event, delims); event->classId(getClassId(name)); event->count(1); events.push_back(event); }
void MaxEntTrainer::readEvents(istream& istrm, EventSet& events) { string line, cls; const string delims(" "); while ((istrm>>cls) && getline(istrm, line)) { MaxEntEvent* event = new MaxEntEvent; getIds(line, *event, delims); event->classId(getClassId(cls)); event->count(1); events.push_back(event); } }
void annTrain::saveModels(const cv::Mat& vocabulary, const std::set<std::string>& classes) { mlp->save(ofToDataPath("mlp.yaml", true)); cv::FileStorage fs(ofToDataPath("vocabulary.yaml", true), cv::FileStorage::WRITE); fs << "vocabulary" << vocabulary; fs.release(); std::ofstream classesOutput(ofToDataPath("classes.txt", true)); for (auto it = classes.begin(); it != classes.end(); ++it) { classesOutput << getClassId(classes, *it) << "\t" << *it << std::endl; } classesOutput.close(); }
QString FailedDisplay::getDescription() const { return "The class required for this display, '" + getClassId() + "', could not be loaded.<br><b>Error:</b><br>" + error_message_; }
void Tool::save( Config config ) const { property_container_->save( config ); config.mapSetValue( "Class", getClassId() ); }
// ###################################################################### void Bayes::learn(const std::vector<double> &fv, const char *name) { //get the class id int cls = getClassId(name); if (cls == -1) //this is a new class, add it to the network cls = addClass(name); if(fv.size() != itsNumFeatures) { LINFO("NOTE: deleting the .net file may fix this if you are"); LINFO("training with a different set of features."); LFATAL("fv.size() != itsNumFeatures: %d != %d",(int)fv.size(), itsNumFeatures); } //ASSERT(fv.size() == itsNumFeatures); //update the class freq ASSERT((uint)cls < itsNumClasses); itsClassFreq[cls]++; //compute the stddev and mean of each feature //This algorithm is due to Knuth (The Art of Computer Programming, volume 2: // Seminumerical Algorithms, 3rd edn., p. 232. Boston: Addison-Wesley.) /* for (uint i=0; i<fv.size(); i++){ const double val = fv[i]; const double delta = val - itsMean[cls][i]; itsMean[cls][i] += delta/itsClassFreq[cls]; if (itsClassFreq[cls] > 3) { itsStdevSq[cls][i] = (itsStdevSq[cls][i]*(itsClassFreq[cls]-2)) + delta*(val - itsMean[cls][i]); } if (itsClassFreq[cls] > 1) //watch for divide by 0 itsStdevSq[cls][i] /= double(itsClassFreq[cls]-1); } */ //watch for divide by 0 if(itsClassFreq[cls] > 3) { const double freq1 = 1.0F/(double)itsClassFreq[cls]; const double freq2 = 1.0F/(double)(itsClassFreq[cls]-1); const uint64 freq = itsClassFreq[cls]; for (uint i=0; i<fv.size(); i++) { const double val = fv[i]; const double delta = val - itsMean[cls][i]; itsMean[cls][i] += delta * freq1; itsStdevSq[cls][i] = (itsStdevSq[cls][i]*(freq-2)) + delta*(val - itsMean[cls][i]); itsStdevSq[cls][i] *= freq2; } } else if(itsClassFreq[cls] > 1) { const double freq1 = 1.0F/(double)itsClassFreq[cls]; const double freq2 = 1.0F/(double)(itsClassFreq[cls]-1); for (uint i=0; i<fv.size(); i++) { const double val = fv[i]; const double delta = val - itsMean[cls][i]; itsMean[cls][i] += delta * freq1; itsStdevSq[cls][i] *= freq2; } } else { const double freq1 = 1.0F/(double)itsClassFreq[cls]; for (uint i=0; i<fv.size(); i++) { const double val = fv[i]; const double delta = val - itsMean[cls][i]; itsMean[cls][i] += delta * freq1; } } }
void Tool::saveChildren( YAML::Emitter& emitter ) { emitter << YAML::Key << "Class" << YAML::Value << getClassId(); property_container_->saveChildren( emitter ); }
int Classifier::loadData(string testConf, string pathToSil) { // Open file with testing configuration ifstream tcStream(testConf.c_str()); if (!tcStream.is_open()) { fprintf (stderr, "Could not open %s\n", testConf.c_str()); return 1; } string classId; string folderName; set<string> testImgsNames; while (tcStream.good()) { // Skip comments and empty lines string line; getline(tcStream, line); if (!hasData(line)) continue; else { folderName = line; // Get folder name classId = getClassId(folderName); // Get classId testImgsNames.clear(); while (tcStream.good()) // Get names of test images { getline(tcStream, line); if(!hasData(line)) break; testImgsNames.insert(line); } } // Get pictures from folder string dirPath = pathToSil + folderName; const vector<string>& filenames = getFilesFromFolder(dirPath); #ifdef WIN32 dirPath += "\\"; #else dirPath += "/"; #endif for (int i = 0; i < (int) filenames.size(); i++) { // Store image to corresponding set (test or learning) string imgName = filenames[i]; string imgPath = dirPath + imgName; Mat imgMat = imread(imgPath, 1); if (inSet(imgName, testImgsNames)) { testData[classId].push_back(imgMat); } else { learningData[classId].push_back(imgMat); } } if (testData[classId].size() != testImgsNames.size()) fprintf(stderr, "Warning: Test set for %s is badly defined!\n", classId.c_str()); } // Everything went ok return 0; }