一、前言
最近在植入模型时,遇到了模型精度不准的问题,为了定位精度下降的原因,采取一个个节点排除的方法。首先就是确保输入图片无误。所以就有了这篇文章,记录一下经验,欢迎来往各位不吝指教。
二、代码
屁话不多说,直接上代码,一些基础的知识,比如海思api的介绍,bmp的介绍等等,自己去学习吧,此文不做展开了。
参考博文,可以先看看他们的:
海思 api 例子:https://blog.csdn.net/mhsszm/article/details/104946840 ;
bmp 代码 :https://blog.csdn.net/quantum7/article/details/82114750### ;
bmp详细解释:
https://blog.csdn.net/weixin_34232744/article/details/86124618?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1 ;
注:由于现实原因,不可能把代码全部贴出来,只能截取其中与主题相关的一部分,可能会有缺失,直接用时注意报错。
int main(IVE_DST_IMAGE_S *astDst) // astDst 这个有错误,其结构我记不清了,明天看看代码重新拷贝份吧
{
unsigned int dst_width = 112;
unsigned int dst_height = 112;
// 先做格式转换,用 HI_MPI_IVE_CSC 将 yvu420sp --> U8C3_PLANAR(即 bgr/rgb planner 格式 NNIE支持的格式)
// astDst 是 yvu 图片的结构体指针,里面存放了 yvu 图片的必备属性
IVE_DST_IMAGE_S csc_Dst = {
0}; // 转换格式后的 bgr 图片必备属性结构体
csc_Dst.au32Stride[0] = astDst[0].au32Stride[0]; // 给其步长赋值,步长二者肯定一致
csc_Dst.au32Stride[1] = csc_Dst.au32Stride[0];
// 文档规定,当输出数据为 U8C3_PLANAR 、 YUV420 SP 、 YUV422SP 类型时,
// 要求输出数据跨度一致。
csc_Dst.au32Stride[2] = csc_Dst.au32Stride[0];
csc_Dst.u32Width = astDst[0].u32Width;
csc_Dst.u32Height = astDst[0].u32Height;
csc_Dst.enType = IVE_IMAGE_TYPE_U8C3_PLANAR; // 选定图片格式,别填错了
// 注意是 stride * height,不是 width * height, 海思像素对齐需要
HI_U32 u32Size_csc = csc_Dst.au32Stride[0] * dst_height * 3;
// 给 bgr 图片分配内存空间,并将分配好的内存空间首地址传给 其结构体中的地址
s32Ret = HI_MPI_SYS_MmzAlloc_Cached(&csc_Dst.au64PhyAddr[0], (HI_VOID**)&csc_Dst.au64VirAddr[0], "CSC image", HI_NULL, u32Size_csc);
if (s32Ret != HI_SUCCESS)
{
SAMPLE_PRT("Mmz Alloc fail,Error(%#x) csc\n", s32Ret);
IVE_MMZ_FREE(astDst.au64PhyAddr[0], astDst.au64VirAddr[0]);
//continue;
}
// 保证 cache 与 内存 数据同步,与上面是套路写法
s32Ret = HI_MPI_SYS_MmzFlushCache(csc_Dst.au64PhyAddr[0], (HI_VOID *)csc_Dst.au64VirAddr[0], u32Size_csc);
if(HI_SUCCESS!&#