Ask Your Question

Problem in saving xml files

asked 2017-02-23 12:03:46 -0500

Nuz gravatar image

I am having difficulty in saving the xml files. I am using a loop to grab all the images in a folder and then to perform HoG. However, it is not saving any of the xml files. But, when done individually it works. Please help..

#include <iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <math.h>
#include "opencv2/highgui/highgui.hpp"
#include <vector>
#include "opencv2/objdetect/objdetect.hpp"
#include <stdio.h>
#include <string.h>
#include <ctype.h>

using namespace cv;
using namespace std;

vector<String> files;

int main(int argc, char** argv)

cv::glob("C:/Desktop/Extracted Frames/Front View/Feint and Dribble/2. Shooting Move/*.jpg", files);
for (size_t i = 0; i < files.size(); i++) {
    Mat img = imread(files[i]);

    //Mat img = imread("C:/Proj//Front/7.Canny/Feint and Dribble/2. Shooting Move/Canny7.jpg");

Mat imageData;
//Hog to build feature vector
HOGDescriptor hog;
vector<float> descriptors;
hog.winSize = Size(64, 128);
resize(img, imageData, hog.winSize);//resize image 
hog.compute(img, descriptors);
//HOG parameters
hog.cellSize = Size(8, 8);
hog.blockSize = Size(16, 16);
hog.nbins = 9;
imshow("Outline Image", img);

vector<float> features1;
//Mat HogFeat;
//Mat HogFeat = Mat(features1, true).reshape(1, 1);
Mat HogFeat = Mat(descriptors, true).reshape(1, 1);
//normalising data
Mat mean, sigma; //matrices to save mean and standard deviation
                 //store descriptor vector into matrix
meanStdDev(HogFeat, mean, sigma); //get mean and std deviation
HogFeat = (HogFeat - mean) / sigma; //normalization

                                    //store normalisation
Mat meansigma;
hconcat(mean, sigma, meansigma);
cout << "mean " << mean << " sigma " << sigma << endl;
cout << "Saving the normalised HOG matrix....." << endl;
//FileStorage storage("normalisation.xml", FileStorage::WRITE);
//storage << "hogfeature" << HogFeat; // basically - it's a key-value store.
//storage.release(); // nothing will happen, unless you actually flush/close it.

                   //Save image
std::stringstream files(std::stringstream::in | std::stringstream::out);

files << "Normalisation" << i << ".xml";
std::cout << "writing " << files.str().c_str() << " to disk" << std::endl;

imwrite(files.str().c_str(), HogFeat);



return 0;
edit retag flag offensive close merge delete


is the problem now, that you need to store several hog features in a single Filestorage ?

berak gravatar imageberak ( 2017-02-24 01:37:08 -0500 )edit

I need to take a folder of images and perform hog for each images and save their xml files separately first,then use those xml files to store them in a single Filestorage @berak

Nuz gravatar imageNuz ( 2017-02-24 06:24:29 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2017-02-24 06:45:32 -0500

berak gravatar image

updated 2017-02-24 06:48:09 -0500

you cannot use imwrite() for this (float features), stick with the FileStorage !

FileStorage storage(format("normalisation.%i.xml", i), FileStorage::WRITE);
storage << "hogfeature" << HogFeat; 
edit flag offensive delete link more


@berak thank you

Nuz gravatar imageNuz ( 2017-02-24 12:14:35 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2017-02-23 12:03:46 -0500

Seen: 84 times

Last updated: Feb 24 '17