I have a vector of matrices with the same number of columns, i.e. std::vector<cv::Mat> v
and I want to apply a cv::PCA
(without dimensionality reduction) using all of them. Finally, I want that the result is applied to original matrices too.
Code speaking, this is the only solution that I came so far:
std::vector<cv::Mat> v;
//fill v
cv::Mat bigMat;
for(size_t i=0; i<v.size(); i++)
bigMat.push_back(v[i]);
cv::PCA pca(bigMat, cv::Mat(), CV_PCA_DATA_AS_ROW);
for(size_t i=0; i<v.size(); i++)
bigMat = pca.project(bigMat);
But this doesn't effect v[i]
. How can I do this efficiently? Notice that I have to use the projected version of bigMat
later. This is the only solution that came to my mind:
cv::PCA pca(bigMat, cv::Mat(), CV_PCA_DATA_AS_ROW);
bigMat.release();
for (size_t i=0; i<v.size(); i++){
v[i] = pca.project(v[i]);
bigMat.push_back(v[i]);
}
But this is kinda ugly and I don't know how efficient could be. Is there any better solution (where efficiency is the top priority)?
If you wander, v[i]
is the set of descriptors of the i-th
image. If you ask yourself why there is no dimensionality reduction in my PCA, give a look at this paper.