本文整理汇总了C++中FileStorage::root方法的典型用法代码示例。如果您正苦于以下问题:C++ FileStorage::root方法的具体用法?C++ FileStorage::root怎么用?C++ FileStorage::root使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileStorage
的用法示例。
在下文中一共展示了FileStorage::root方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: readDetections
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 );
}
}
示例2: main
int main()
{
//vars for 120 fps
time_duration td, td1;
ptime nextFrameTimestamp, currentFrameTimestamp, initialLoopTimestamp, finalLoopTimestamp;
int delayFound = 0;
//Setting up communication with arduino
HANDLE hSerial;
hSerial = CreateFile("COM4",GENERIC_READ|GENERIC_WRITE,0,0,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0);
if(hSerial==INVALID_HANDLE_VALUE)
{
if(GetLastError()==ERROR_FILE_NOT_FOUND)
{
cout<<"File not found"<<endl;//serial port does not exist. Inform user.
}
cout<<"error :/"<<endl;//some other error occurred. Inform user.
}
DCB dcbSerialParams = {0};
dcbSerialParams.DCBlength=sizeof(dcbSerialParams);
if (!GetCommState(hSerial, &dcbSerialParams))
{
printf("error getting state\n");
}
dcbSerialParams.BaudRate=CBR_9600;
dcbSerialParams.ByteSize=8;
dcbSerialParams.StopBits=ONESTOPBIT;
dcbSerialParams.Parity=NOPARITY;
if(!SetCommState(hSerial, &dcbSerialParams))
{
printf("error setting serial port state\n");
}
int n=1;
DWORD bytesWritten;
ifstream infile("..//..//..//data.csv"); //Takes input from basic(GUI) for reading patient data and stores in the data.csv file
infile>>patdat; //reading patients first name
infile>>patdat1; //reading patients last name
infile>>patdat2; //reading patients age
infile>>patdat3; //reading patients gender
//Snippet for reading camera settings from xml file
FileStorage fs;
fs.open("file1.xml", FileStorage::READ);
FileNode q = fs.root();
for (FileNodeIterator current = q.begin(); current != q.end(); current++)
{
FileNode item = *current;
//cout<<"Success"<<endl;
item["Exposure"] >> exposure;
item["FPS"] >> framerate;
item["Framewidth"] >> framewidth;
item["Frameheight"] >> frameheight;
//cout << exposure << endl;
}
VideoCapture capture(0); //Opens the camera of the device connected
VideoCapture capture1(1);
capture.set(CV_CAP_PROP_FRAME_WIDTH, framewidth);
capture.set(CV_CAP_PROP_FRAME_HEIGHT,frameheight);
capture.set(CV_CAP_PROP_EXPOSURE, exposure);
capture1.set(CV_CAP_PROP_FRAME_WIDTH, framewidth);
capture1.set(CV_CAP_PROP_FRAME_HEIGHT,frameheight);
capture1.set(CV_CAP_PROP_EXPOSURE, exposure);
capture>>image; //Extract a frame and store in image matrix.
capture1>>image1;
strcpy(fname, "..//..//Videos//"); //declaring path for storing video
strcat(fname, patdat); //appending patients first name on the video
strcat(fname, "_"); //appending patients name on the video
strcat(fname, patdat1); //appending patients last name on the video
strcat(fname, "_");
strcat(fname, patdat2);
strcat(fname, "_");
strcat(fname, patdat3);
strcat(fname, "_");
strcat(fname, "left");
strcat(fname,".avi");
strcpy(fname1, "..//..//Videos//"); //declaring path for storing video
strcat(fname1, patdat); //appending patients first name on the video
strcat(fname1, "_"); //appending patients name on the video
strcat(fname1, patdat1); //appending patients last name on the video
strcat(fname1, "_");
strcat(fname1, patdat2);
strcat(fname1, "_");
strcat(fname1, patdat3);
strcat(fname1, "_");
strcat(fname1, "right");
strcat(fname1,".avi");
int fps1=20;
//.........这里部分代码省略.........
示例3: responses
TEST_P(ML_ANN_METHOD, Test)
{
int methodType = get<0>(GetParam());
string methodName = get<1>(GetParam());
int N = get<2>(GetParam());
String folder = string(cvtest::TS::ptr()->get_data_path());
String original_path = folder + "waveform.data";
String dataname = folder + "waveform" + '_' + methodName;
Ptr<TrainData> tdata2 = TrainData::loadFromCSV(original_path, 0);
Mat samples = tdata2->getSamples()(Range(0, N), Range::all());
Mat responses(N, 3, CV_32FC1, Scalar(0));
for (int i = 0; i < N; i++)
responses.at<float>(i, static_cast<int>(tdata2->getResponses().at<float>(i, 0))) = 1;
Ptr<TrainData> tdata = TrainData::create(samples, ml::ROW_SAMPLE, responses);
ASSERT_FALSE(tdata.empty()) << "Could not find test data file : " << original_path;
RNG& rng = theRNG();
rng.state = 0;
tdata->setTrainTestSplitRatio(0.8);
Mat testSamples = tdata->getTestSamples();
#ifdef GENERATE_TESTDATA
{
Ptr<ml::ANN_MLP> xx = ml::ANN_MLP_ANNEAL::create();
Mat_<int> layerSizesXX(1, 4);
layerSizesXX(0, 0) = tdata->getNVars();
layerSizesXX(0, 1) = 30;
layerSizesXX(0, 2) = 30;
layerSizesXX(0, 3) = tdata->getResponses().cols;
xx->setLayerSizes(layerSizesXX);
xx->setActivationFunction(ml::ANN_MLP::SIGMOID_SYM);
xx->setTrainMethod(ml::ANN_MLP::RPROP);
xx->setTermCriteria(TermCriteria(TermCriteria::COUNT, 1, 0.01));
xx->train(tdata, ml::ANN_MLP::NO_OUTPUT_SCALE + ml::ANN_MLP::NO_INPUT_SCALE);
FileStorage fs;
fs.open(dataname + "_init_weight.yml.gz", FileStorage::WRITE + FileStorage::BASE64);
xx->write(fs);
fs.release();
}
#endif
{
FileStorage fs;
fs.open(dataname + "_init_weight.yml.gz", FileStorage::READ);
Ptr<ml::ANN_MLP> x = ml::ANN_MLP_ANNEAL::create();
x->read(fs.root());
x->setTrainMethod(methodType);
if (methodType == ml::ANN_MLP::ANNEAL)
{
x->setAnnealEnergyRNG(RNG(CV_BIG_INT(0xffffffff)));
x->setAnnealInitialT(12);
x->setAnnealFinalT(0.15);
x->setAnnealCoolingRatio(0.96);
x->setAnnealItePerStep(11);
}
x->setTermCriteria(TermCriteria(TermCriteria::COUNT, 100, 0.01));
x->train(tdata, ml::ANN_MLP::NO_OUTPUT_SCALE + ml::ANN_MLP::NO_INPUT_SCALE + ml::ANN_MLP::UPDATE_WEIGHTS);
ASSERT_TRUE(x->isTrained()) << "Could not train networks with " << methodName;
string filename = dataname + ".yml.gz";
Mat r_gold;
#ifdef GENERATE_TESTDATA
x->save(filename);
x->predict(testSamples, r_gold);
{
FileStorage fs_response(dataname + "_response.yml.gz", FileStorage::WRITE + FileStorage::BASE64);
fs_response << "response" << r_gold;
}
#else
{
FileStorage fs_response(dataname + "_response.yml.gz", FileStorage::READ);
fs_response["response"] >> r_gold;
}
#endif
ASSERT_FALSE(r_gold.empty());
Ptr<ml::ANN_MLP> y = Algorithm::load<ANN_MLP>(filename);
ASSERT_TRUE(y != NULL) << "Could not load " << filename;
Mat rx, ry;
for (int j = 0; j < 4; j++)
{
rx = x->getWeights(j);
ry = y->getWeights(j);
double n = cvtest::norm(rx, ry, NORM_INF);
EXPECT_LT(n, FLT_EPSILON) << "Weights are not equal for layer: " << j;
}
x->predict(testSamples, rx);
y->predict(testSamples, ry);
double n = cvtest::norm(ry, rx, NORM_INF);
EXPECT_LT(n, FLT_EPSILON) << "Predict are not equal to result of the saved model";
n = cvtest::norm(r_gold, rx, NORM_INF);
EXPECT_LT(n, FLT_EPSILON) << "Predict are not equal to 'gold' response";
}
}