bool Calibration::load(string filename, bool absolute) { imagePoints.clear(); //FileStorage fs(ofToDataPath(filename, absolute), FileStorage::READ); FileStorage fs(filename, FileStorage::READ); if (!fs.isOpened()) return false; cv::Size imageSize, sensorSize; Mat cameraMatrix; fs["cameraMatrix"] >> cameraMatrix; fs["imageSize_width"] >> imageSize.width; fs["imageSize_height"] >> imageSize.height; fs["sensorSize_width"] >> sensorSize.width; fs["sensorSize_height"] >> sensorSize.height; fs["distCoeffs"] >> distCoeffs; fs["reprojectionError"] >> reprojectionError; FileNode features = fs["features"]; for(FileNodeIterator it = features.begin(); it != features.end(); it++) { vector<Point2f> cur; (*it) >> cur; imagePoints.push_back(cur); } addedImageSize = imageSize; distortedIntrinsics.setup(cameraMatrix, imageSize, sensorSize); updateUndistortion(); ready = true; return true; }
void CvCascadeBoostTree::read( const FileNode &node, CvBoost* _ensemble, CvDTreeTrainData* _data ) { int maxCatCount = ((CvCascadeBoostTrainData*)_data)->featureEvaluator->getMaxCatCount(); int subsetN = (maxCatCount + 31)/32; int step = 3 + ( maxCatCount>0 ? subsetN : 1 ); queue<CvDTreeNode*> internalNodesQueue; FileNodeIterator internalNodesIt, leafValsuesIt; CvDTreeNode* prntNode, *cldNode; clear(); data = _data; ensemble = _ensemble; pruned_tree_idx = 0; // read tree nodes FileNode rnode = node[CC_INTERNAL_NODES]; internalNodesIt = rnode.end(); leafValsuesIt = node[CC_LEAF_VALUES].end(); internalNodesIt--; leafValsuesIt--; for( size_t i = 0; i < rnode.size()/step; i++ ) { prntNode = data->new_node( 0, 0, 0, 0 ); if ( maxCatCount > 0 ) { prntNode->split = data->new_split_cat( 0, 0 ); for( int j = subsetN-1; j>=0; j--) { *internalNodesIt >> prntNode->split->subset[j]; internalNodesIt--; } } else {
void ReadRightRects(vector<ImageRecognition::SlidingRect> &rightRects, const string &xml_filename, RecognitionStatistics &stat) { using namespace Utils; FileStorage file_storage(xml_filename, FileStorage::READ); FileNode images = file_storage["images"]; rightRects.reserve(images.size()); for (FileNodeIterator it = images.begin(); it != images.end(); ++it) { string part_filename = string(*it); int dot_pos = part_filename.find_first_of('.'); if (dot_pos != -1) part_filename = part_filename.substr(0, dot_pos); stringstream ss(part_filename); vector<string> parts; string part; while (getline(ss, part, '_')) parts.push_back(part); rightRects.push_back(ImageRecognition::SlidingRect()); int last = parts.size() - 1; rightRects.back().rect.x = str2int(parts[last - 3]); rightRects.back().rect.y = str2int(parts[last - 2]); rightRects.back().rect.width = str2int(parts[last - 1]); rightRects.back().rect.height = str2int(parts[last]); } }
static bool readModelViews( const string& filename, vector<Point3f>& box, vector<string>& imagelist, vector<Rect>& roiList, vector<Vec6f>& poseList ) { imagelist.resize(0); roiList.resize(0); poseList.resize(0); box.resize(0); FileStorage fs(filename, FileStorage::READ); if( !fs.isOpened() ) return false; fs["box"] >> box; FileNode all = fs["views"]; if( all.type() != FileNode::SEQ ) return false; FileNodeIterator it = all.begin(), it_end = all.end(); for(; it != it_end; ++it) { FileNode n = *it; imagelist.push_back((string)n["image"]); FileNode nr = n["rect"]; roiList.push_back(Rect((int)nr[0], (int)nr[1], (int)nr[2], (int)nr[3])); FileNode np = n["pose"]; poseList.push_back(Vec6f((float)np[0], (float)np[1], (float)np[2], (float)np[3], (float)np[4], (float)np[5])); } return true; }
/* * Like runTests, but using the quantized lookup table * instead of the support vector machine directly. */ void runTestsSVMTable() { ColonyCounter colonyCounter; colonyCounter.loadTrainingQuantized(svmLookup, svmQuants); FileStorage fs("samples/tests.yml", FileStorage::READ); double absErrorSum = 0; FileNode features = fs["tests"]; FileNodeIterator it = features.begin(), it_end = features.end(); int idx = 0; for( ; it != it_end; ++it, idx++ ) { string path; (*it)["path"] >> path; int red = (int)(*it)["red"]; int blue = (int)(*it)["blue"]; double error; runTest(colonyCounter, "samples/" + path, red, blue, error); absErrorSum += fabs(error); } fs.release(); printf("Error %f\n", absErrorSum); }
int main(int, char** argv){ FileStorage fs2("test.xml", FileStorage::READ); if (!fs2.isOpened()){ cout << "failed to open test.xml :(" << endl; return 1; } // first method: use (type) operator on FileNode. int frameCount = (int)fs2["frameCount"]; std::string date; // second method: use FileNode::operator >> fs2["calibrationDate"] >> date; Mat camera_intrinsics_1, camera_intrinsics_2, camera_intrinsics_3, camera_intrinsics_4; Mat camera_extrinsics_1, camera_extrinsics_2, camera_extrinsics_3, camera_extrinsics_4; fs2["camera_intrinsics_1"] >> camera_intrinsics_1; fs2["camera_intrinsics_2"] >> camera_intrinsics_2; fs2["camera_intrinsics_3"] >> camera_intrinsics_3; fs2["camera_intrinsics_4"] >> camera_intrinsics_4; fs2["camera_extrinsics_1"] >> camera_extrinsics_1; fs2["camera_extrinsics_2"] >> camera_extrinsics_2; fs2["camera_extrinsics_3"] >> camera_extrinsics_3; fs2["camera_extrinsics_4"] >> camera_extrinsics_4; cout << camera_extrinsics_4 << endl; cout << camera_intrinsics_4 << endl; //fs2["distCoeffs"] >> distCoeffs2; //cout << "frameCount: " << frameCount << endl // << "calibration date: " << date << endl // << "camera matrix: " << cameraMatrix2 << endl // << "distortion coeffs: " << distCoeffs2 << endl; FileNode features = fs2["features"]; FileNodeIterator it = features.begin(), it_end = features.end(); int idx = 0; std::vector<uchar> lbpval; // iterate through a sequence using FileNodeIterator for( ; it != it_end; ++it, idx++ ) { cout << "feature #" << idx << ": "; cout << "x=" << (int)(*it)["x"] << ", y=" << (int)(*it)["y"] << ", lbp: ("; // you can also easily read numerical arrays using FileNode >> std::vector operator. (*it)["lbp"] >> lbpval; for( int i = 0; i < (int)lbpval.size(); i++ ) cout << " " << (int)lbpval[i]; cout << ")" << endl; } fs2.release(); }
inline void readFileNodeList(const FileNode& fn, vector<_Tp>& result) { if (fn.type() == FileNode::SEQ) { for (FileNodeIterator it = fn.begin(); it != fn.end();) { _Tp item; it >> item; result.push_back(item); } } }
void read(const FileNode& node, vector<KeyPoint>& keypoints) { keypoints.resize(0); FileNodeIterator it = node.begin(), it_end = node.end(); for( ; it != it_end; ) { KeyPoint kpt; it >> kpt.pt.x >> kpt.pt.y >> kpt.size >> kpt.angle >> kpt.response >> kpt.octave; keypoints.push_back(kpt); } }
bool HOGEvaluator::read( const FileNode& node ) { features->resize(node.size()); featuresPtr = &(*features)[0]; FileNodeIterator it = node.begin(), it_end = node.end(); for(int i = 0; it != it_end; ++it, i++) { if(!featuresPtr[i].read(*it)) return false; } return true; }
static void readDetections( FileStorage fs, const string& nodeName, vector<LatentSvmDetector::ObjectDetection>& detections ) { detections.clear(); FileNode fn = fs.root()[nodeName]; FileNodeIterator fni = fn.begin(); while( fni != fn.end() ) { LatentSvmDetector::ObjectDetection d; fni >> d.rect.x >> d.rect.y >> d.rect.width >> d.rect.height >> d.score >> d.classID; detections.push_back( d ); } }
static bool readStringList( const string& filename, vector<string>& l ) { l.resize(0); FileStorage fs(filename, FileStorage::READ); if( !fs.isOpened() ) return false; FileNode n = fs.getFirstTopLevelNode(); if( n.type() != FileNode::SEQ ) return false; FileNodeIterator it = n.begin(), it_end = n.end(); for( ; it != it_end; ++it ) l.push_back((string)*it); return true; }
int main( ) { //改变console字体颜色 system("color 6F"); ShowHelpText(); //初始化 FileStorage fs2("test.yaml", FileStorage::READ); // 第一种方法,对FileNode操作 int frameCount = (int)fs2["frameCount"]; std::string date; // 第二种方法,使用FileNode运算符> > fs2["calibrationDate"] >> date; Mat cameraMatrix2, distCoeffs2; fs2["cameraMatrix"] >> cameraMatrix2; fs2["distCoeffs"] >> distCoeffs2; cout << "frameCount: " << frameCount << endl << "calibration date: " << date << endl << "camera matrix: " << cameraMatrix2 << endl << "distortion coeffs: " << distCoeffs2 << endl; FileNode features = fs2["features"]; FileNodeIterator it = features.begin(), it_end = features.end(); int idx = 0; std::vector<uchar> lbpval; //使用FileNodeIterator遍历序列 for( ; it != it_end; ++it, idx++ ) { cout << "feature #" << idx << ": "; cout << "x=" << (int)(*it)["x"] << ", y=" << (int)(*it)["y"] << ", lbp: ("; // 我们也可以使用使用filenode > > std::vector操作符很容易的读数值阵列 (*it)["lbp"] >> lbpval; for( int i = 0; i < (int)lbpval.size(); i++ ) cout << " " << (int)lbpval[i]; cout << ")" << endl; } fs2.release(); //程序结束,输出一些帮助文字 printf("\n文件读取完毕,请输入任意键结束程序~"); getchar(); return 0; }
bool DataSetVOC::loadBBoxes(CStr &nameNE, vector<Vec4i> &boxes, vecI &clsIdx) { string fName = format(_S(annoPathW), _S(nameNE)); FileStorage fs(fName, FileStorage::READ); FileNode fn = fs["annotation"]["object"]; boxes.clear(); clsIdx.clear(); if (fn.isSeq()){ for (FileNodeIterator it = fn.begin(), it_end = fn.end(); it != it_end; it++) loadBox(*it, boxes, clsIdx); } else loadBox(fn, boxes, clsIdx); return true; }
int Map::getMapFromFile(string filename) { FileStorage fs; fs.open(filename, FileStorage::READ); FileNode n = fs["Map"]; if (n.type() != FileNode::SEQ) return -1; // Map n'est pas une séquence FileNodeIterator it = n.begin(), it_end = n.end(); // Itérateur pour lire la séquence for (; it != it_end; ++it) cout << (string)*it << endl; fs.release(); // énoncer la fermeture return 0; }
void readVectorOfVector(FileStorage &fns, string name, vector<vector<KeyPoint> > &vov) { vov.clear(); FileNode fn = fns[name]; if (fn.empty()){ return; } FileNodeIterator current = fn.begin(), it_end = fn.end(); // Go through the node for (; current != it_end; ++current) { vector<KeyPoint> tmp; FileNode item = *current; read(item, tmp); vov.push_back(tmp); } }
int imageDB::readKeyMap(const FileStorage& cvfs, const FileNode& node) { keypoint_map.clear(); int keypoint_id; FileNodeIterator it = node.begin(); while(it != node.end()){ vector<KeyPoint> keypt_vec; keypoint_id = (int)(*it)["keypoint_id"]; cv::read((*it)["KeyPoint"], keypt_vec); keypoint_map.insert(pair<int,KeyPoint>(keypoint_id,keypt_vec[0])); it++; } return 0; }
int imageDB::readFeatureKptMap(const FileStorage& cvfs, const FileNode& node) { feature_KPT_map.clear(); int feature_id; featureInfo feature_info; FileNodeIterator it = node.begin(); while(it != node.end()){ feature_id = (int)(*it)["feature_id"]; feature_info.keypoint_id = (int)(*it)["keypoint_id"]; feature_info.img_id = (int)(*it)["img_id"]; feature_KPT_map.insert(pair<int, featureInfo>(feature_id,feature_info)); it++; } return 0; }
void ICFDetector::read(const FileNode& node) { waldboost_ = Ptr<WaldBoost>(createWaldBoost(WaldBoostParams())); String f_temp; node["model_n_rows"] >> model_n_rows_; node["model_n_cols"] >> model_n_cols_; f_temp = (String)node["ftype"]; this->ftype_ = (string)f_temp.c_str(); waldboost_->read(node["waldboost"]); FileNode features = node["features"]; features_.clear(); vector<int> p; for( FileNodeIterator n = features.begin(); n != features.end(); ++n ) { (*n) >> p; features_.push_back(p); } }
static bool readStringList(const string &filename, vector<string> &l) { l.resize(0); FileStorage fs(filename, FileStorage::READ); if (!fs.isOpened()) return false; FileNode n = fs.getFirstTopLevelNode(); if (n.type() != FileNode::SEQ) return false; FileNodeIterator it = n.begin(), it_end = n.end(); string temp = filename; int pos = temp.find_last_of('/') + 1; temp = temp.substr(0, pos); for (; it != it_end; ++it) l.push_back(temp + (string)*it); return true; }
bool load(const String &fn) { FileStorage fs(fn, FileStorage::READ); if (! fs.isOpened()) return false; bool ok = classifier->load(fs); FileNode pers = fs["persons"]; FileNodeIterator it = pers.begin(); for( ; it != pers.end(); ++it ) { int id; (*it) >> id; string s =(*it).name(); persons[id] = s; } fs.release(); return ok; }
void UndistortImages::loadImages( char* images_list ){ FileStorage fs; fs.open(images_list,FileStorage::READ); if( !fs.isOpened() ){ cerr << " Fail to open " << images_list << endl; exit(EXIT_FAILURE); } cout << " Images size = " << fs["images"].size() << endl; FileNode imagesPathNode = fs["images"]; for(FileNodeIterator it = imagesPathNode.begin(); it != imagesPathNode.end(); ++it){ inputImagesPaths.push_back( *it ); } fs.release(); }
void loadBins(float* out){ FileStorage fs("txtDict.xml", FileStorage::READ); FileNode n = fs["binArray"]; if(n.type() != FileNode::SEQ){ cout << "incorrect filetype: " << n.type() << endl; fs.release(); return; } FileNodeIterator it = n.begin(), it_end = n.end(); int cnt =0; for(;it != it_end;++it){ out[cnt] = (float)*it; cnt++; } cout << "finished reading Bins..\n\n"; fs.release(); }
void loadTex(vector<float>& out){ FileStorage fs("txtDict.xml", FileStorage::READ); FileNode n = fs["TextonDictionary"]; if(n.type() != FileNode::SEQ){ cout << "incorrect filetype: " << n.type() << endl; fs.release(); return; } FileNodeIterator it = n.begin(), it_end = n.end(); int cnt =0; for(;it != it_end;++it){ out.push_back((float)*it); cnt++; } cout << "finished reading Textons..\n\n"; fs.release(); }
bool HaarEvaluator::Feature :: read( const FileNode& node ) { FileNode rnode = node[CC_RECTS]; FileNodeIterator it = rnode.begin(), it_end = rnode.end(); int ri; for( ri = 0; ri < RECT_NUM; ri++ ) { rect[ri].r = Rect(); rect[ri].weight = 0.f; } for(ri = 0; it != it_end; ++it, ri++) { FileNodeIterator it2 = (*it).begin(); it2 >> rect[ri].r.x >> rect[ri].r.y >> rect[ri].r.width >> rect[ri].r.height >> rect[ri].weight; } tilted = (int)node[CC_TILTED] != 0; return true; }
bool ChessCalibration::loadExtrinsics() { FileStorage fs(calibrationExtrinsicsFilePath, FileStorage::READ); if (!fs.isOpened()) return false; imagePoints.clear(); found = true; fs["rvec"] >> rvec; fs["tvec"] >> tvec; FileNode features = fs["features"]; for(FileNodeIterator it = features.begin(); it != features.end(); it++) { vector<Point2f> cur; (*it) >> cur; imagePoints.push_back(cur[0]); } fs["mapping"] >> mapping; cout << "Extrinsics loaded from file" << endl; // createTransformImageExtrinsicMap(camMat); // fs.release(); // FileStorage fs2(calibrationExtrinsicsFilePath, FileStorage::APPEND); // fs2 << "mapping" << mapping; return true; }
/**Reads board info from a file */ void BoardConfiguration::readFromFile(cv::FileStorage &fs) throw(cv::Exception) { int aux = 0; // look for the nmarkers if (fs["aruco_bc_nmarkers"].name() != "aruco_bc_nmarkers") throw cv::Exception(81818, "BoardConfiguration::readFromFile", "invalid file type", __FILE__, __LINE__); fs["aruco_bc_nmarkers"] >> aux; resize(aux); fs["aruco_bc_mInfoType"] >> mInfoType; cv::FileNode markers = fs["aruco_bc_markers"]; int i = 0; for (FileNodeIterator it = markers.begin(); it != markers.end(); ++it, i++) { at(i).id = (*it)["id"]; FileNode FnCorners = (*it)["corners"]; for (FileNodeIterator itc = FnCorners.begin(); itc != FnCorners.end(); ++itc) { vector< float > coordinates3d; (*itc) >> coordinates3d; if (coordinates3d.size() != 3) throw cv::Exception(81818, "BoardConfiguration::readFromFile", "invalid file type 3", __FILE__, __LINE__); cv::Point3f point(coordinates3d[0], coordinates3d[1], coordinates3d[2]); at(i).push_back(point); } } }
static bool readStringList( const string& filename, const string& tempFile, vector<string>& l ) { /* // Immediately generate the file name that we will read from FileStorage fs(tempFile, FileStorage::WRITE); fs << "images" << "["; fs << string(filename); fs << "]"; */ l.resize(0); FileStorage fs(filename, FileStorage::READ); if( !fs.isOpened() ) return false; FileNode n = fs.getFirstTopLevelNode(); if( n.type() != FileNode::SEQ ) return false; FileNodeIterator it = n.begin(), it_end = n.end(); for( ; it != it_end; ++it ) l.push_back((string)*it); return true; }
void CameraCalibration::ReadMonoCalibParams( string &img_xml ) { calib_params = new CalibParams; FileStorage fs(img_xml, FileStorage::READ); // Read the settings if (!fs.isOpened()) { cout << "Could not open the configuration file: \"" << img_xml << "\"" << endl; exit(EXIT_FAILURE); } BoardSize = Size((int)fs["BoardSizeWidth"], (int)fs["BoardSizeHeight"]); SquareSize = (float)fs["SquareSize"]; BoardTexWdith = SquareSize*BoardSize.width; BoardTexHeight = SquareSize*BoardSize.height; FileNode imgs = fs["Images"]; for(FileNodeIterator itr = imgs.begin(); itr != imgs.end(); itr++) calib_params->ImageList.push_back((string)*itr); // Check if all image data have the same size. Mat img = imread(calib_params->ImageList.front(), CV_LOAD_IMAGE_GRAYSCALE); ImageSize = Size(img.rows, img.cols); for(int i=1; i<calib_params->ImageList.size(); i++) { img = imread(calib_params->ImageList.at(i), CV_LOAD_IMAGE_GRAYSCALE); assert(ImageSize == Size(img.rows, img.cols)); ImageSize = Size(img.rows, img.cols); } NumFrames = calib_params->ImageList.size(); fs.release(); }
/* * Run tests to make sure that quantization is working. */ void runQuantTests() { ColonyCounter colonyCounter; colonyCounter.loadTraining("svm_params.yml"); FileStorage fs("samples/tests.yml", FileStorage::READ); FileNode features = fs["tests"]; FileNodeIterator it = features.begin(), it_end = features.end(); int idx = 0; for( ; it != it_end; ++it, idx++ ) { string path; (*it)["path"] >> path; Mat img = imread("samples/" + path); // Find petri img Rect petriRect = findPetriRect(img); Mat petri = img(petriRect); // Preprocess image petri = colonyCounter.preprocessImage(petri); colonyCounter.testQuantization(petri, quants); // Classify image Mat debugImg, debugImgq; colonyCounter.classifyImage(petri, true, &debugImg); colonyCounter.classifyImageQuant(petri, true, &debugImgq, quants); imshow("normal", debugImg); imshow("quant", debugImgq); waitKey(0); } fs.release(); }
int imageDB::readImgInfoMap(const FileStorage& cvfs, const FileNode& node) { imgInfo_map.clear(); releaseImgVoteMap(); int img_id; imageInfo img_info; FileNodeIterator it = node.begin(); while(it != node.end()){ img_id = (int)(*it)[0]; img_info.feature_num = (int)(*it)[1]; img_info.img_size = Size((int)(*it)[2],(int)(*it)[3]); imgInfo_map.insert(pair<int,imageInfo>(img_id,img_info)); // create voteTable vector<featureVote>* voteTable = new vector<featureVote>; imgVote_map.insert(pair<int,vector<featureVote>*>(img_id, voteTable)); it++; } return 0; }