void read_from_yaml(FileNode node, cv::Vec2f& v) { CvMat* c_m; c_m = (CvMat*)node.readObj(); ntk_throw_exception_if(!c_m, std::string("Could not read field ") + node.name() + " from yml file."); cv::Mat1f m (c_m); ntk_assert(m.cols == 2, "Bad vector."); std::copy(m.ptr<float>(), m.ptr<float>()+2, &v[0]); }
void read_from_yaml(FileNode node, cv::Rect& r) { CvMat* c_m; c_m = (CvMat*)node.readObj(); ntk_throw_exception_if(!c_m, std::string("Could not read field ") + node.name() + " from yml file."); cv::Mat1f m (c_m); ntk_assert(m.cols == 4, "Bad Rect."); r = cv::Rect(m(0,0), m(0,1), m(0,2), m(0,3)); }
void Object::read(const FileNode& node) { if (node.isNamed()) name_ = node.name(); else cout << "Warning : no name for this object." << endl; node["number_views"] >> number_views_; node["features_type"] >> features_type_; views_.resize(number_views_); for ( int i = 0; i < number_views_; ++i ) { ostringstream view_stream; view_stream << "view_" << i; node[view_stream.str()] >> views_[i]; } }
void loadDescriptorsFromOpenCVFilestorage( Mat& descriptors, string& filePath ) { VerboseOutput::println(string("train"), "Loading descriptors from OpenCV Filestorage"); try { VerboseOutput::println(string("train"), "...open filestorage"); FileStorage fs1(filePath, FileStorage::READ); VerboseOutput::println(string("train"), "...filestorage opened"); try { VerboseOutput::println(string("train"), "...read root node"); FileNode features1 = fs1.root(); VerboseOutput::println(string("train"), "...find SIFTComparison node"); for( FileNodeIterator it = features1.begin() ; it != features1.end(); ++it ) { FileNode node = *it; if (node.name().compare(SIFTComparison::TASK_NAME) == 0) { read(node["descriptors"], descriptors); } } } catch (exception& e) { stringstream ss; ss << "*** WARNING: failed to load descriptors from OpenCV FileStorage: " << e.what(); VerboseOutput::println(string("train"), ss.str() ); } if (fs1.isOpened()) { fs1.release(); } } catch(exception& e) { stringstream ss; ss << "*** WARNING: failed to close Filestorage: " << e.what(); VerboseOutput::println(string("train"), ss.str() ); } }