【发布时间】:2017-11-21 10:57:18
【问题描述】:
我正在开发一个使用 tensorRT 的嵌入式深度学习推理 C++ 项目。 对于我的模型,有必要减去平均图像。
我使用的 api 允许我为 rgb 图像定义具有以下数据结构的平均图像:
uint8_t *data[DW_MAX_IMAGE_PLANES]; // raw image data
size_t pitch; // pitch of the image in bytes
uint32_t height; // height of the image in px
uint32_t width; // image width in px
uint32_t planeCount; // plane count of the image
到目前为止,我找到了 lib LodePNG,我认为这对这项任务非常有用。 它只需几行就可以加载 png:
// Load file and decode image.
std::vector<unsigned char> image;
unsigned width, height;
unsigned error = lodepng::decode(image, width, height, filename);
现在的问题是如何将std::vector<unsigned char> 转换为uint8_t *[DW_MAX_IMAGE_PLANES] 并计算pitch 和planeCount 值?
当我使用 rgb 图像时,DW_MAX_IMAGE_PLANES 等于 3。
【问题讨论】:
-
您的问题的标题似乎有点错误,因为您已经成功加载了 png。
-
也许
std::vector参考可能有用?有几种方法可以获取指向由向量管理的数据的指针,包括(但不限于)获取指向其第一个元素的指针。 -
至于其余的,你的库不是为你提供了元数据吗?
-
使用这里描述的 reinterpret_cast stackoverflow.com/questions/4254615/… 只要确保 unsigned char 和 uint8_t 的大小相同。
-
@MarekVitek 在存在
uint8_t的平台上,它与unsigned char不同的可能性极小。如果char不是 8 位,则实际上不可能有int8_t类型。