0

我确实有一个 Matrix 类,我通过两个循环访问它,并在其中存储了我想要的所有值。

Matrix MatriceJ(width, height);
for (int i=0;i<width;i++)
{
    for (int j=0;j<height;j++)
    {
        MatriceJ.at(i,j)=....
    }
}

但是现在,我想将 MatriceJ 存储在 IplImage* 中,因为我可以将它的不同元素与其他 IplImage 一个接一个地相乘。

你能帮我解决这个问题吗?

4

1 回答 1

1

这应该让你开始。我假设数据是无符号字符和一个通道,请相应调整。

// Create the image
int depth = IPL_DEPTH_8U; // please adjust
int channels = 1;         // please adjust
IplImage* img = cvCreateImage(cvSize(width,height), depth, channels);

// Now assume there is a matrix MatriceJ
// Copy the data to our newly created IplImage*
for (int i=0;i<height;i++)
{
    uchar* ptr = (uchar*)(img->imageData + i*img->widthStep);
    for (int j=0;j<width;j++)
    {
        ptr[j] = MatriceJ(i,j);
    }
}
于 2013-03-14T15:24:16.940 回答