简体   繁体   English

内存不足opencv

[英]Insufficient memory opencv

I am beginner to OpenCV and C++.我是 OpenCV 和 C++ 的初学者。 I am trying to write PCA code for face recognition using 3 different faces.我正在尝试使用 3 个不同的面孔编写用于人脸识别的 PCA 代码。 For this, each image(of size d=mxn) is reshaped to a column vector of d elements.为此,每个图像(大小为 d=mxn)都被重新整形为包含 d 个元素的列向量。

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 OpenCV 错误:OutOfMemoryError 中的内存不足(无法分配 144004 字节)

My image size is 180x200.我的图像大小是 180x200。 I don't know what to do?我不知道该怎么办? Also how can I form a row vector in opencv using C++?另外,如何使用 C++ 在 opencv 中形成行向量? (For calculating covariance I need to multiply difference vector with its traspose). (为了计算协方差,我需要将差分向量与其转置相乘)。

I don't know OpenCV and its types.我不知道 OpenCV 及其类型。 But your typedef looks suspicious.但是你的typedef看起来很可疑。

My guess is that the error occurs while creating the imgXv instances of Row .我的猜测是在创建RowimgXv实例时发生错误。 For each call of Row imgXv(36000,img1);对于Row imgXv(36000,img1);每次调用Row imgXv(36000,img1); a vector is created that consists of 36000 instances of Mat that are all copies of the imgX instances.创建一个向量,由 36000 个Mat实例组成,这些实例都是imgX实例的副本。 See constructor 2) of std::vector::vector in cppreference.com :参见cppreference.comstd::vector::vector构造函数2)

vector( size_type count, const T& value, const Allocator& alloc = Allocator()); (2) (2)

2) Constructs the container with count copies of elements with value value. 2) 构造具有值 value 元素的 count 个副本的容器。

So you`re trying to keep 108003 images in memory.所以你试图在内存中保留108003 张图像 Each of your images consists of 36000 pixels.您的每张图片均由 36000 像素组成。 If each pixel is represented by at least 1 byte, this would occupy a minimum of 3.6 GB of memory.如果每个像素至少由 1 个字节表示,则这将占用最少3.6 GB的内存。

From what I get of your approach you don't want that, but rather a typedef vector<float> Row;根据我对你的方法的了解,你不想要那个,而是一个typedef vector<float> Row; and Row imgXv(36000);Row imgXv(36000);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM