Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

the fault is not with the asRowMatrix function, but in the code where you setup your histogram vector.

your hist Mat is global, meaning, you use the same one over and over in your calculation, and in the end, all of them are the same (push_back copies only the Mat header, they all share the same "pixels", it's a "shallow" copy there)

so, use fresh Mat's for each image:

vector<mat> hists; for(int i = 0; i < names.size(); i++) { Mat img, lbp, hist; // all local now ! img = imread(names[i]); cvtColor(img, img, CV_BGR2GRAY); lbp::OLBP(img, lbp); //call OLBP function in Phillip code lbp::spatial_histogram(lbp, hist, 256, Size(10, 10)); //Call to spatial histograms function in Phillip code hists.push_back(hist); //push back histogram of this image to vector of mat }

the fault is not with the asRowMatrix function, but in the code where you setup your histogram vector.

your hist Mat is global, meaning, you use the same one over and over in your calculation, and in the end, all of them are the same (push_back copies only the Mat header, they all share the same "pixels", it's a "shallow" copy there)

so, use fresh (local) Mat's for each image:image, do not re-use them:

vector<mat>

vector<Mat> hists;
for(int i = 0; i < names.size(); i++)
{
      Mat img, lbp, hist; // all local now !
      img = imread(names[i]);
      cvtColor(img, img, CV_BGR2GRAY);
      lbp::OLBP(img, lbp); //call OLBP function in Phillip code
       lbp::spatial_histogram(lbp, hist, 256, Size(10, 10)); //Call to spatial histograms function in Phillip code
       hists.push_back(hist); //push back histogram of this image to vector of mat
}

}