char imgpath[256];
int* cube = new int[500 * 500 * 500 * 3];
for (int s = 0; s < 500; s++)
{
sprintf_s(imgpath, "D:\\cubeimg\\%d.png", s + 2150);
Mat img = imread(imgpath);
if (!img.data)
{
cout << "载入失败" << endl;
}
Mat img_resize;
resize(img, img_resize, Size(1000, 500), 0, 0, CV_INTER_LINEAR);
Mat submat(500, 500, CV_8UC3);
img_resize.colRange(499, 999).copyTo(submat);
for (int i = 0; i < 500; i++)
{
for (int j = 0; j < 500; j++)
{
{
int t = submat.at<Vec3b>(i, j)[ch];
int index = 500 * 500 * 3 * s + 500 * 3 * i + 3 * j + ch;
cube[index] = t;
}
}
}
}
FILE *fp;
if ((fp = fopen("d:\\image.pixel", "wb")) == 0)
{
printf("open failed!");
exit(1);
}
fwrite(cube, sizeof(int), 500 * 500 * 500 * 3, fp);
fclose(fp);