本文整理汇总了C++中FileStorage::release方法的典型用法代码示例。如果您正苦于以下问题:C++ FileStorage::release方法的具体用法?C++ FileStorage::release怎么用?C++ FileStorage::release使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileStorage
的用法示例。
在下文中一共展示了FileStorage::release方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: FileInputOutput
KDvoid FileInputOutput ( KDint nIdx )
{
string filename = "/data/outputfile.xml.gz";
string sOuput;
// write
{
Mat R = Mat_<uchar>::eye(3, 3),
T = Mat_<double>::zeros(3, 1);
MyData m(1);
FileStorage fs ( filename, FileStorage::WRITE );
fs << "iterationNr" << 100;
fs << "strings" << "["; // text - string sequence
fs << "image1.jpg" << "Awesomeness" << "baboon.jpg";
fs << "]"; // close sequence
fs << "Mapping"; // text - mapping
fs << "{" << "One" << 1;
fs << "Two" << 2 << "}";
fs << "R" << R; // cv::Mat
fs << "T" << T;
fs << "MyData" << m; // your own data structures
fs.release(); // explicit close
}
// read
{
sOuput += "Reading: \n";
FileStorage fs;
fs.open ( filename, FileStorage::READ );
int itNr;
itNr = (int) fs [ "iterationNr" ];
sOuput += itNr;
if (!fs.isOpened())
{
return;
}
FileNode n = fs["strings"]; // Read string sequence - Get node
if (n.type() != FileNode::SEQ)
{
return;
}
n = fs["Mapping"]; // Read mappings from a sequence
MyData m;
Mat R, T;
fs["R"] >> R; // Read cv::Mat
fs["T"] >> T;
fs["MyData"] >> m; // Read your own structure_
//cout << endl
// << "R = " << R << endl;
//cout << "T = " << T << endl << endl;
//cout << "MyData = " << endl << m << endl << endl;
//Show default behavior for non existing nodes
//cout << "Attempt to read NonExisting (should initialize the data structure with its default).";
fs["NonExisting"] >> m;
}
g_pController->setMessage ( "See Data Folder" );
}
示例2: main
//.........这里部分代码省略.........
barcode_present = true;
barcode_format.push_back("UPC_A");
}
else if(dir_flag == 3) //manduchi
{
f_name = basename(temp);
decode_out.push_back(f_name.substr(0,f_name.find("_")));
f_name = "./gt/" + f_name + ".yml";
cout << "Filename is " << f_name << endl;
cout << "The decode output is " << decode_out[0] << endl;
barcode_present = true;
barcode_format.push_back("UPC_A");
}
else if(dir_flag == 4) //zxing
{
f_name = "./gt/" + basename(temp) + ".yml";
cout << "Filename is " << f_name << endl;
string inStr = temp.substr(0,temp.size()-3) + "txt";
cout << inStr << endl;
ifstream inFile;
inFile.open(inStr.c_str());
string one_line;
getline(inFile,one_line);
cout << one_line << endl;
inFile.close();
decode_out.push_back(one_line);
barcode_format.push_back(format_temp);
barcode_present = true;
}
else if(dir_flag == 5)
{
// if(flgg == 0)
// {
// if(basename(temp) == "Foto(507)")
// flgg = 1;
// continue;
// }
f_name = "./gt/" + basename(temp) + ".yml";
cout << "Output file name is " << f_name << endl;
string inStr = temp + ".txt";
cout << "Input file name is " << inStr << endl;
ifstream inFile;
inFile.open(inStr.c_str());
string one_line;
getline(inFile,one_line);
cout << one_line << endl;
inFile.close();
decode_out.push_back(one_line);
barcode_present = true;
barcode_format.push_back("ean13");
}
else
{
cout << "NOT A DATASET DIRECTORY" << endl;
return 0;
}
Mat img = imread(temp);
imshow("AnnotateGT",img);
cvWaitKey(0);
fs.open(f_name,FileStorage::WRITE);
fs << "barcode_present" << barcode_present;
fs << "barcode_format" << "[";
for(int i=0;i < barcode_format.size();i++)
fs << "[:" << barcode_format[i] << "]";
fs << "]";
fs << "decode_out" << "[:";
for(int i=0;i < decode_out.size();i++)
fs << "[:" << decode_out[i] << "]";
fs << "]";
cout << corner_points[0].size() << " ******************* " << corner_points[0].size() << endl;
fs << "corner_points" << "[";
for(int i=0;i < corner_points.size();i++)
{
fs << "[:";
for(int j=0;j < corner_points[i].size();j++)
{
// cout << corner_points[i][j];
fs << "[:" << corner_points[i][j].x << corner_points[i][j].y << "]";
}
fs << "]";
}
fs << "]";
fs.release();
// if(!parse_with_zxing(img))
// {
// cout << "Zxing Failed in decoding" << endl;
// }
}
}
cvDestroyWindow("AnnotateGT");
}
else
示例3: main
int main(int argc, char* argv[])
{
SURF extractor;
Mat train_descr;
SurfFeatureDetector detector(700);
BFMatcher match(NORM_L2); //Try to replace with FLANN
vector<vector<DMatch> > matches;
//namedWindow("Image", CV_WINDOW_AUTOSIZE );
vector<KeyPoint> keypoints;
Mat descriptors;
FileStorage train;
train.open("Train.xml", FileStorage::READ);
int correct = 0;
float mean_error = 0;
float min = 0;
int m = 0;
string name = argv[1];
for(int x = 2;x<argc;x++)
{
Mat img = imread(argv[x]);
detector.detect(img, keypoints);
//drawKeypoints(img,keypoints,img,255);
//imshow("Image",img);
//waitKey(0);
extractor.compute(img, keypoints, descriptors);
//Compute errors
mean_error = 0;
min = 0;
m = 0;
for(int n = 0; n <CLASSES; n++)
{
train[set[n]]>>train_descr;
match.knnMatch(descriptors,train_descr,matches,NEIGHBOURS);
for(int j=0;j<NEIGHBOURS;j++)
for(int i=0;i<KEYPOINTS;i++)
{
mean_error+=matches.at(i).at(j).distance;
}
mean_error = mean_error/(NEIGHBOURS*KEYPOINTS);
if(n==0)
min = mean_error;
if(min>mean_error)
{
min = mean_error;
m = n;
}
}
if(!name.compare(set[m]))
correct+=1;
}
cout<<"Classification accuracy for "<<name<<" is:"<<(((float)correct)/(argc-2)) * 100<<endl;
train.release();
return 0;
}
示例4: main
//.........这里部分代码省略.........
drawChessboardCorners( view, boardSize, Mat(ptvec), found );
if( found )
{
imgpt[k1][i].resize(ptvec.size());
std::copy(ptvec.begin(), ptvec.end(), imgpt[k1][i].begin());
}
//imshow("view", view);
//int c = waitKey(0) & 255;
//if( c == 27 || c == 'q' || c == 'Q' )
// return -1;
}
}
}
printf("Running calibration ...\n");
run3Calibration(imgpt[0], imgpt[1], imgpt[2], imageSize,
boardSize, squareSize, aspectRatio, flags|CALIB_FIX_K4|CALIB_FIX_K5,
cameraMatrix[0], distCoeffs[0],
cameraMatrix[1], distCoeffs[1],
cameraMatrix[2], distCoeffs[2],
R12, T12, R13, T13);
fs.open(outputFilename, FileStorage::WRITE);
fs << "cameraMatrix1" << cameraMatrix[0];
fs << "cameraMatrix2" << cameraMatrix[1];
fs << "cameraMatrix3" << cameraMatrix[2];
fs << "distCoeffs1" << distCoeffs[0];
fs << "distCoeffs2" << distCoeffs[1];
fs << "distCoeffs3" << distCoeffs[2];
fs << "R12" << R12;
fs << "T12" << T12;
fs << "R13" << R13;
fs << "T13" << T13;
fs << "imageWidth" << imageSize.width;
fs << "imageHeight" << imageSize.height;
Mat Q;
// step 3: find rectification transforms
double ratio = rectify3Collinear(cameraMatrix[0], distCoeffs[0], cameraMatrix[1],
distCoeffs[1], cameraMatrix[2], distCoeffs[2],
imgpt[0], imgpt[2],
imageSize, R12, T12, R13, T13,
R[0], R[1], R[2], P[0], P[1], P[2], Q, -1.,
imageSize, 0, 0, CALIB_ZERO_DISPARITY);
Mat map1[3], map2[3];
fs << "R1" << R[0];
fs << "R2" << R[1];
fs << "R3" << R[2];
fs << "P1" << P[0];
fs << "P2" << P[1];
fs << "P3" << P[2];
fs << "disparityRatio" << ratio;
fs.release();
printf("Disparity ratio = %g\n", ratio);
for( k = 0; k < 3; k++ )
initUndistortRectifyMap(cameraMatrix[k], distCoeffs[k], R[k], P[k], imageSize, CV_16SC2, map1[k], map2[k]);
Mat canvas(imageSize.height, imageSize.width*3, CV_8UC3), small_canvas;
destroyWindow("view");
canvas = Scalar::all(0);
for( i = 0; i < (int)(imageList.size()/3); i++ )
{
canvas = Scalar::all(0);
for( k = 0; k < 3; k++ )
{
int k1 = k == 0 ? 2 : k == 1 ? 0 : 1;
int k2 = k == 0 ? 1 : k == 1 ? 0 : 2;
view = imread(imageList[i*3+k], 1);
if(view.empty())
continue;
Mat rview = canvas.colRange(k2*imageSize.width, (k2+1)*imageSize.width);
remap(view, rview, map1[k1], map2[k1], INTER_LINEAR);
}
printf("%s %s %s\n", imageList[i*3].c_str(), imageList[i*3+1].c_str(), imageList[i*3+2].c_str());
resize( canvas, small_canvas, Size(1500, 1500/3) );
for( k = 0; k < small_canvas.rows; k += 16 )
line(small_canvas, Point(0, k), Point(small_canvas.cols, k), Scalar(0,255,0), 1);
imshow("rectified", small_canvas);
int c = waitKey(0);
if( c == 27 || c == 'q' || c == 'Q' )
break;
}
return 0;
}
示例5: 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";
}
}