Ask Your Question
0

How to read a folder of images and save as a single xml file?

asked 2017-02-19 01:24:50 -0500

Nuz gravatar image

I want to read a folder of images in sequence and then save them as a single normalisation.xml file. But, the code below is reading only one image. How to do this?

#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;


  int main(int argc, char** argv)
 {
Mat img = imread("C:/Proj/folder/images/Canny.jpg"); //load outline image
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.setSVMDetector(HOGDescriptor::getDefaultPeopleDetector());
//HOG parameters
hog.cellSize = Size(8, 8);
hog.blockSize = Size(16, 16);
hog.nbins = 9;
//namedWindow("HOG");
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.
waitKey(0);


return 0;
    }
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2017-02-19 01:45:02 -0500

LBerger gravatar image

updated 2017-02-19 01:45:22 -0500

you can use videocapture or glob. A good example is this post

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2017-02-19 01:24:50 -0500

Seen: 191 times

Last updated: Feb 19 '17