在做车牌识别项目,通过先对识别区域内进行目标识别,能降低CPU的占用率,在检测到有运动目标的时候,再做车牌识别。
//图像差分
s32Ret = HI_MPI_IVE_Sub(&IveHandle, &pstGmm->stSrc, &pstGmm->stbgImg, &pstGmm->stBgDiffFg, &pstGmm->stSubCtrl, bInstant);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("HI_MPI_IVE_Sub fail,Error(%#x)\n", s32Ret);
return s32Ret;
}
s32Ret = HI_MPI_IVE_Sub(&IveHandle, &pstGmm->stSrc, &pstGmm->stbgImg, &pstGmm->stBgDiffFg, &pstGmm->stSubCtrl, bInstant);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("HI_MPI_IVE_Sub fail,Error(%#x)\n", s32Ret);
return s32Ret;
}
//差分图像二值化
s32Ret = HI_MPI_IVE_Thresh(&IveHandle, &pstGmm->stBgDiffFg, &pstGmm->stBinaryImg, &pstGmm->stThrCtrl, bInstant);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("HI_MPI_IVE_Thresh fail,Error(%#x)\n", s32Ret);
return s32Ret;
}
//腐蚀操作
s32Ret = HI_MPI_IVE_Erode(&IveHandle, &pstGmm->stBinaryImg, &pstGmm->stErodeImg, &pstGmm->stErodeCtrl, bInstant);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("HI_MPI_IVE_Erode fail,Error(%#x)\n", s32Ret);
return s32Ret;
}
s32Ret = HI_MPI_IVE_Erode(&IveHandle, &pstGmm->stBinaryImg, &pstGmm->stErodeImg, &pstGmm->stErodeCtrl, bInstant);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("HI_MPI_IVE_Erode fail,Error(%#x)\n", s32Ret);
return s32Ret;
}
//对二值化图积分
s32Ret = HI_MPI_IVE_Integ(&IveHandle, &pstGmm->stErodeImg, &pstGmm->stDiffInteg, &pstGmm->stIntegCtrl, bInstant);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("HI_MPI_IVE_Integ fail,Error(%#x)\n", s32Ret);
return s32Ret;
}
pu64VirDataDiff = (HI_U32*)pstGmm->stDiffInteg.pu8VirAddr[0];
s32Ret = HI_MPI_IVE_Integ(&IveHandle, &pstGmm->stErodeImg, &pstGmm->stDiffInteg, &pstGmm->stIntegCtrl, bInstant);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("HI_MPI_IVE_Integ fail,Error(%#x)\n", s32Ret);
return s32Ret;
}
pu64VirDataDiff = (HI_U32*)pstGmm->stDiffInteg.pu8VirAddr[0];
//计算识别区域内目标的像素点
//x1-y1
HI_U32 index = (g_recogArea.y+g_recogArea.height-1)*pstGmm->stInteg.u16Stride[0]+g_recogArea.x+g_recogArea.width-1;
HI_U32 sum_x1_y1 = (HI_U32) pu64VirDataDiff[index];
//HI_U32 sum_x1_y1 = (HI_U32)
pu64VirDataDiff[pstGmm->stInteg.u16Height*pstGmm->stInteg.u16Stride[0]-1];
//x0-y0
index = g_recogArea.y*pstGmm->stInteg.u16Stride[0]+g_recogArea.x;
HI_U32 sum_x0_y0 = (HI_U32) pu64VirDataDiff[index]; // (HI_U32) pu64VirDataDiff[0];
index = g_recogArea.y*pstGmm->stInteg.u16Stride[0]+g_recogArea.x;
HI_U32 sum_x0_y0 = (HI_U32) pu64VirDataDiff[index]; // (HI_U32) pu64VirDataDiff[0];
//x0-y1
index =
(g_recogArea.y+g_recogArea.height-1)*pstGmm->stInteg.u16Stride[0]+g_recogArea.x;
HI_U32 sum_x0_y1 = (HI_U32) pu64VirDataDiff[index];
HI_U32 sum_x0_y1 = (HI_U32) pu64VirDataDiff[index];
//x1-y0
index
=g_recogArea.y*pstGmm->stInteg.u16Stride[0]+g_recogArea.x+g_recogArea.width-1;
HI_U32 sum_x1_y0 = (HI_U32) pu64VirDataDiff[index];
HI_U32 sum_x1_y0 = (HI_U32) pu64VirDataDiff[index];
HI_U32 motionArea = sum_x1_y1 + sum_x0_y0 - sum_x0_y1 - sum_x1_y0;
//printf("----------sum_x1_y1=%u---sum_x0_y0=%u----motionArea is %d
----number=%d\n",sum_x1_y1, sum_x0_y0, motionArea, sum_x1_y1);
//有运动目标
if(motionArea>300)
{
if(motionArea>300)
{
pstGmm->objectFlag =
3;
}else
{
if(pstGmm->objectFlag>0)
{
pstGmm->objectFlag--;
}
}
}else
{
if(pstGmm->objectFlag>0)
{
pstGmm->objectFlag--;
}
}
以上为实现的代码。
遇到一个问题,在海思hi3516上开发,malloc的内存进行操作比mmz分配的内存快,这个怎么解决?