I am beginner to OpenCV and C++. I am trying to write PCA code for face recognition using 3 different faces. For this, each image(of size d=mxn) is reshaped to a column vector of d elements.
typedef vector<Mat> Row;
Row img1v(36000,img1);
Row img2v(36000,img2);
Row img3v(36000,img3);
I calculate the vector of mean of the images as follows:
Row meanImg;
 for(int i=0;i<img1v.size();++i)
{
  meanImg.push_back((img1v[i]+img2v[i]+img3v[i])/3);
}
cout<<meanImg.size()<<endl;
Here I get an error:
OpenCV Error: Insufficient memory (Failed to allocate 144004 bytes) in OutOfMemoryError
My image size is 180x200. I don't know what to do? Also how can I form a row vector in opencv using C++? (For calculating covariance I need to multiply difference vector with its traspose).
                        
I don't know OpenCV and its types. But your
typedeflooks suspicious.My guess is that the error occurs while creating the
imgXvinstances ofRow. For each call ofRow imgXv(36000,img1);a vector is created that consists of 36000 instances ofMatthat are all copies of theimgXinstances. See constructor 2) ofstd::vector::vectorin cppreference.com:So you`re trying to keep 108003 images in memory. Each of your images consists of 36000 pixels. If each pixel is represented by at least 1 byte, this would occupy a minimum of 3.6 GB of memory.
From what I get of your approach you don't want that, but rather a
typedef vector<float> Row;andRow imgXv(36000);