0

图像来自一维数组数据。需要将其迁移到二维数据。二维数组的大小必须为 640 行和 1176 列,并且必须最终写入带有 .pgm 标头的文件。

void saveFile(unsigned short* mImStack)  // Image to be accessed
{
    std::ofstream f("D:\\tester.txt", ios::out);

    int rows = 0;
    int cols = 0;

    int t_rows = (mImageRaw->m_ImageHeight); // height of image (640)
    int t_cols = (mImageRaw->m_ImageWidth); // width of image (1176)

    int ncells = t_rows * t_cols; // total cells of the 1D array which has the image data

    unsigned short** mImage2D = new unsigned short*[cols];  // defining a 2D array
    for (int i = 0; i < t_cols; ++i)
    {
        mImage2D[i] = new unsigned short[rows];
    }
    for (int n = 0; n < ncells; n++)
    {
        mImage2D[rows][cols] = mImStack[n];  // Error ocuring here as Access violation reading location 
        cols++;
        if (cols == t_cols && rows != t_rows + 1)
        {
            rows++;
            cols = 0;
        }
    }

    f << "P2\n" << t_rows << " " << t_cols << "\n4096\n" << mImage2D[rows][cols];
    f.close();
}
4

0 回答 0