问题描述
我正在尝试将一个3通道IPL_DEPTH_8U
图像存储到一个数组中,以便可以在内存中存储100张图像.
I am trying to store a IPL_DEPTH_8U
, 3 channel image into an array so that I can store 100 images in memory.
要初始化我的4D数组,我使用了以下代码(行,列,通道,存储的):
To initialise my 4D array I used the following code (rows,cols,channel,stored):
int size[] = { 324, 576, 3, 100 };
CvMatND* cvImageBucket; = cvCreateMatND(3, size, CV_8U);
然后我创建了一个矩阵,并将图像转换为矩阵
I then created a matrix and converted the image into the matrix
CvMat *matImage = cvCreateMat(Image->height,Image->width,CV_8UC3 );
cvConvert(Image, matImage );
我如何/访问CvMatND将CvMat复制到存储位置?
How would I / access the CvMatND to copy the CvMat into it at the position of stored?
例如cvImageBucket(:,:,:,0) = matImage; // copied first image into array
推荐答案
您已将其标记为C和C ++.如果您想使用C ++,可以(我认为)使用更简单的 cv :: Mat结构来存储每个图像,然后使用它们填充带有所有图像的矢量.
You've tagged this as both C and C++. If you want to work in C++, you could use the (in my opinion) simpler cv::Mat structure to store each of the images, and then use these to populate a vector with all the images.
例如:
std::vector<cv::Mat> imageVector;
cv::Mat newImage;
newImage = getImage(); // where getImage() returns the next image,
// or an empty cv::Mat() if there are no more images
while (!newImage.empty())
{
// Add image to vector
imageVector.push_back(image);
// get next image
newImage = getImage();
}
这篇关于OpenCV图像阵列,4D矩阵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!