c++ 图片HWC格式转CHW格式
vector<uint8_t> fileData(channels * height * width);
float* hostInputBuffer = static_cast<float*>(channels * height * width);
// Convert HWC to CHW and Normalize
for (int c = 0; c < channels; ++c)
{
for (int h = 0; h < height; ++h)
{
for (int w = 0; w < width; ++w)
{
int dstIdx = c * height * width + h * width + w;
int srcIdx = h * width * channels + w * channels + c;
hostInputBuffer[dstIdx] = static_cast<const float>(fileData[srcIdx]);
}
}
}