本文整理汇总了C++中FileNode::begin方法的典型用法代码示例。如果您正苦于以下问题:C++ FileNode::begin方法的具体用法?C++ FileNode::begin怎么用?C++ FileNode::begin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileNode
的用法示例。
在下文中一共展示了FileNode::begin方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: read
void read(const FileNode& fn)
{
clear();
read_params(fn["training_params"]);
fn["weights"] >> weights;
fn["means"] >> means;
FileNode cfn = fn["covs"];
FileNodeIterator cfn_it = cfn.begin();
int i, n = (int)cfn.size();
covs.resize(n);
for( i = 0; i < n; i++, ++cfn_it )
(*cfn_it) >> covs[i];
decomposeCovs();
computeLogWeightDivDet();
}
示例2: read
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;
}
示例3: loadExtrinsics
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;
}
示例4: load
void Calibration::load(string filename, bool absolute) {
imagePoints.clear();
FileStorage fs(ofToDataPath(filename, absolute), FileStorage::READ);
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();
}
示例5: readFromFile
/**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);
}
}
}
示例6: read_params
int CV_MLBaseTest::read_params( CvFileStorage* __fs )
{
FileStorage _fs(__fs, false);
if( !_fs.isOpened() )
test_case_count = -1;
else
{
FileNode fn = _fs.getFirstTopLevelNode()["run_params"][modelName];
test_case_count = (int)fn.size();
if( test_case_count <= 0 )
test_case_count = -1;
if( test_case_count > 0 )
{
dataSetNames.resize( test_case_count );
FileNodeIterator it = fn.begin();
for( int i = 0; i < test_case_count; i++, ++it )
{
dataSetNames[i] = (string)*it;
}
}
}
return cvtest::TS::OK;;
}
示例7: readStringList
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;
}
示例8: ReadMonoCalibParams
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();
}
示例9: runQuantTests
/*
* 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();
}
示例10: readImgInfoMap
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;
}
示例11: visualize
void visualize(){
cout << endl << "Reading: " << endl;
FileStorage fs("PointCloudFoun.xml ", FileStorage::READ ); //PointCloud_SURF_Foun_1K.xml
if (fs.isOpened())
cout<<"File is opened\n";
else
cout << "error in opening" << endl;
FileNode n = fs["CloudPoint"];
int row;
row = (int) (n["rows"]);
cout << "Row:" << row << endl;
unsigned int count;
FileNode nd = n["data"];
vector< double > pointcloud;
FileNodeIterator it = nd.begin(), it_end = nd.end(); // Go through the node
for (; it != it_end; ++it)
{
pointcloud.push_back( (double)*it );
// cout << (double)*it;
count += 1;
}
cout << count/3 <<endl;
fs.release();
cout << "\n" << pointcloud.size()/3 <<endl;
//--------------------
// Visualization
//--------------------
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>);
std::cout << "Genarating point clouds.\n\n";
cloud.reset(new pcl::PointCloud<pcl::PointXYZ>);
for(unsigned int i = 0; i < pointcloud.size() ; i = i+3)
{
if(isnan( pointcloud[i] ) )
continue;
pcl::PointXYZ p;
p.x = pointcloud[i];
p.y = pointcloud[i+1];
p.z = pointcloud[i+2];
cloud->push_back(p);
//cloud->points.push_back(p);
}
cloud->width = (int) cloud->points.size();
cloud->height = 1;
for (size_t i = 0; i < cloud->points.size (); ++i)
std::cerr << " " << cloud->points[i].x << " " << cloud->points[i].y << " " << cloud->points[i].z << std::endl;
boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer;
viewer = customColourVis(cloud);
while (!viewer->wasStopped ())
{
viewer->spinOnce (100);
boost::this_thread::sleep (boost::posix_time::microseconds (100000));
}
}
示例12: parseCascade
static Fields* parseCascade(const FileNode &root, const float mins, const float maxs, const int totals, const int method)
{
static const char *const SC_STAGE_TYPE = "stageType";
static const char *const SC_BOOST = "BOOST";
static const char *const SC_FEATURE_TYPE = "featureType";
static const char *const SC_ICF = "ICF";
static const char *const SC_ORIG_W = "width";
static const char *const SC_ORIG_H = "height";
static const char *const SC_FEATURE_FORMAT = "featureFormat";
static const char *const SC_SHRINKAGE = "shrinkage";
static const char *const SC_OCTAVES = "octaves";
static const char *const SC_OCT_SCALE = "scale";
static const char *const SC_OCT_WEAKS = "weaks";
static const char *const SC_TREES = "trees";
static const char *const SC_WEAK_THRESHOLD = "treeThreshold";
static const char *const SC_FEATURES = "features";
static const char *const SC_INTERNAL = "internalNodes";
static const char *const SC_LEAF = "leafValues";
static const char *const SC_F_CHANNEL = "channel";
static const char *const SC_F_RECT = "rect";
// only Ada Boost supported
std::string stageTypeStr = (std::string)root[SC_STAGE_TYPE];
CV_Assert(stageTypeStr == SC_BOOST);
// only HOG-like integral channel features supported
std::string featureTypeStr = (std::string)root[SC_FEATURE_TYPE];
CV_Assert(featureTypeStr == SC_ICF);
int origWidth = (int)root[SC_ORIG_W];
int origHeight = (int)root[SC_ORIG_H];
std::string fformat = (std::string)root[SC_FEATURE_FORMAT];
bool useBoxes = (fformat == "BOX");
ushort shrinkage = cv::saturate_cast<ushort>((int)root[SC_SHRINKAGE]);
FileNode fn = root[SC_OCTAVES];
if (fn.empty()) return 0;
std::vector<device::Octave> voctaves;
std::vector<float> vstages;
std::vector<device::Node> vnodes;
std::vector<float> vleaves;
FileNodeIterator it = fn.begin(), it_end = fn.end();
for (ushort octIndex = 0; it != it_end; ++it, ++octIndex)
{
FileNode fns = *it;
float scale = powf(2.f,saturate_cast<float>((int)fns[SC_OCT_SCALE]));
bool isUPOctave = scale >= 1;
ushort nweaks = saturate_cast<ushort>((int)fns[SC_OCT_WEAKS]);
ushort2 size;
size.x = cvRound(origWidth * scale);
size.y = cvRound(origHeight * scale);
device::Octave octave(octIndex, nweaks, shrinkage, size, scale);
CV_Assert(octave.stages > 0);
voctaves.push_back(octave);
FileNode ffs = fns[SC_FEATURES];
if (ffs.empty()) return 0;
std::vector<cv::Rect> feature_rects;
std::vector<int> feature_channels;
FileNodeIterator ftrs = ffs.begin(), ftrs_end = ffs.end();
int feature_offset = 0;
for (; ftrs != ftrs_end; ++ftrs, ++feature_offset )
{
cv::FileNode ftn = (*ftrs)[SC_F_RECT];
cv::FileNodeIterator r_it = ftn.begin();
int x = (int)*(r_it++);
int y = (int)*(r_it++);
int w = (int)*(r_it++);
int h = (int)*(r_it++);
if (useBoxes)
{
if (isUPOctave)
{
w -= x;
h -= y;
}
}
else
{
if (!isUPOctave)
{
w += x;
h += y;
}
}
feature_rects.push_back(cv::Rect(x, y, w, h));
feature_channels.push_back((int)(*ftrs)[SC_F_CHANNEL]);
}
fns = fns[SC_TREES];
if (fn.empty()) return false;
//.........这里部分代码省略.........
示例13: fill
bool fill(const FileNode &root)
{
// cascade properties
static const char *const SC_STAGE_TYPE = "stageType";
static const char *const SC_BOOST = "BOOST";
static const char *const SC_FEATURE_TYPE = "featureType";
static const char *const SC_ICF = "ICF";
static const char *const SC_ORIG_W = "width";
static const char *const SC_ORIG_H = "height";
static const char *const SC_OCTAVES = "octaves";
static const char *const SC_TREES = "trees";
static const char *const SC_FEATURES = "features";
static const char *const SC_INTERNAL = "internalNodes";
static const char *const SC_LEAF = "leafValues";
static const char *const SC_SHRINKAGE = "shrinkage";
static const char *const FEATURE_FORMAT = "featureFormat";
// only Ada Boost supported
std::string stageTypeStr = (string)root[SC_STAGE_TYPE];
CV_Assert(stageTypeStr == SC_BOOST);
std::string fformat = (string)root[FEATURE_FORMAT];
bool useBoxes = (fformat == "BOX");
// only HOG-like integral channel features supported
string featureTypeStr = (string)root[SC_FEATURE_TYPE];
CV_Assert(featureTypeStr == SC_ICF);
origObjWidth = (int)root[SC_ORIG_W];
origObjHeight = (int)root[SC_ORIG_H];
shrinkage = (int)root[SC_SHRINKAGE];
FileNode fn = root[SC_OCTAVES];
if (fn.empty()) return false;
// for each octave
FileNodeIterator it = fn.begin(), it_end = fn.end();
for (int octIndex = 0; it != it_end; ++it, ++octIndex)
{
FileNode fns = *it;
Octave octave(octIndex, cv::Size(origObjWidth, origObjHeight), fns);
CV_Assert(octave.weaks > 0);
octaves.push_back(octave);
FileNode ffs = fns[SC_FEATURES];
if (ffs.empty()) return false;
fns = fns[SC_TREES];
if (fn.empty()) return false;
FileNodeIterator st = fns.begin(), st_end = fns.end();
for (; st != st_end; ++st )
{
weaks.push_back(Weak(*st));
fns = (*st)[SC_INTERNAL];
FileNodeIterator inIt = fns.begin(), inIt_end = fns.end();
for (; inIt != inIt_end;)
nodes.push_back(Node(features.size(), inIt));
fns = (*st)[SC_LEAF];
inIt = fns.begin(), inIt_end = fns.end();
for (; inIt != inIt_end; ++inIt)
leaves.push_back((float)(*inIt));
}
st = ffs.begin(), st_end = ffs.end();
for (; st != st_end; ++st )
features.push_back(Feature(*st, useBoxes));
}
return true;
}
示例14: xmlfile
void System3d::readCalibrationXML(string filename)
{
if(filename.length() > 5)
{
if( filename.substr(filename.length()-4) == ".xml" )
{
pmdPoints.clear();
webcamPoints.clear();
patternCount = 0;
cout << "opening file \"" << filename << "\" in progress...";
FileStorage xmlfile(filename, FileStorage::READ);
FileNode chessboardNode = xmlfile["chessboard_pattern_parameters"];
float vertical = (float)chessboardNode["vertical"];
float horizontal = (float)chessboardNode["horizontal"];
FileNode IFMcamNode = xmlfile["detected_corners"];
FileNodeIterator it = IFMcamNode.begin(), it_end = IFMcamNode.end();
int idx = 0;
// iterate through a sequence using FileNodeIterator
for( ; it != it_end; ++it, idx++ )
{
vector<Point2f> pts_pmd;
(*it)["IFMcam_corners"] >> pts_pmd;
pmdPoints.push_back(pts_pmd);
vector<Point2f> pts_web;
(*it)["webcam_corners"] >> pts_web;
webcamPoints.push_back(pts_web);
}
xmlfile.release();
patternCount = idx;
// write points coordinates
cout << "\n*****************************************************\n";
for(int k=0; k<pmdPoints.size(); k++)
{
cout << "pmd feature #" << k << ": ";
cout << "\n( ";
for(int i=0; i<pmdPoints[k].size(); i++)
{
cout << pmdPoints[k][i].x << " " << pmdPoints[k][i].y << " || ";
}
cout << ")\n";
}
// write points coordinates
cout << "\n*****************************************************\n";
for(int k=0; k<webcamPoints.size(); k++)
{
cout << "web feature #" << k << ": ";
cout << "\n( ";
for(int i=0; i<webcamPoints[k].size(); i++)
{
cout << webcamPoints[k][i].x << " " << webcamPoints[k][i].y << " || ";
}
cout << ")\n";
}
}
else cout << "Error: wrong file name\n";
示例15: main
int main() {
//leap motion data
Controller controller;
controller.setPolicy(Leap::Controller::POLICY_IMAGES);
controller.setPolicy(Leap::Controller::POLICY_BACKGROUND_FRAMES);
//process variables
int updateRate;
int frameAmount; //amount of frame to record
int counter;
bool done;
FileStorage fs;
vector<string> imagelist;
FileNode n;
FileNodeIterator it, it_begin, it_end;
Size boardSize;
int64 t1, t2;
double time;
Vector slopes_left, slopes_right, position;
float cameraZ, cameraY, cameraX;
//behavior options
Behaviour behaviour;
start:
//initialization
updateRate = 100;
frameAmount = 20; //amount of frame to record
counter = 0;
done = false;
imagelist.clear();
time = 0;
behaviour = CheckBehaviour();
if (behaviour == Quit) return 0;
else {
system("cls");
std::cout << "Press 'q' to quit, 'r' to restart (set focus on image window)\n";
}
char key = ' ';
while (key != 'q' && key != 'r') {
key = waitKey(updateRate); //refresh rate
//image acquisition
Frame frame = controller.frame();
if (!frame.isValid()) {
//std::cout << "Frame is Invalid" << std::endl;
continue;
}
ImageList images = frame.images();
if (images.isEmpty() || images.count() == 1) {
//std::cout << "imageList.isEmpty()" << std::endl;
continue;
}
Image imageLeft = images[0];
Image imageRight = images[1];
cvImgLeft = Mat(imageLeft.height(), imageLeft.width(), CV_8UC1);
cvImgRight = Mat(imageRight.height(), imageRight.width(), CV_8UC1);
cvImgLeft.data = (unsigned char*)imageLeft.data();
cvImgRight.data = (unsigned char*)imageRight.data();
//image output
imshow("Left image", cvImgLeft);
imshow("Right image", cvImgRight);
//behaviour check
switch (behaviour) {
case Show_images:
//do nothing
break;
case Undistort_images:
//use Leap Motion distortion map
UndistortLeap(imageLeft, "Undistorted left image", true);
UndistortLeap(imageRight, "Undistorted right image", true);
break;
case Calib_image_recording:
//record calibration images
counter++;
//done = imgSave(cvImgLeft, cvImgRight, frameAmount, counter);
done = imgSave(UndistortLeap(imageLeft, "Undistorted left image", true), UndistortLeap(imageRight, "Undistorted right image", true), frameAmount, counter);
if (done) {
system("cls");
std::cout << "Images for calibration recorded!" <<
"\nPress 'q' to quit, 'r' to restart (set focus on image window)";
behaviour = Show_images;
}
break;
case Stereo_calibration:
//read calibration names to list
fs.open(calibFileNames, FileStorage::READ);
n = fs["strings"]; // Read string sequence - Get node
if (n.type() != FileNode::SEQ)
{
cerr << "strings is not a sequence! FAIL" << endl;
//.........这里部分代码省略.........