一.原理:
static HI_S32 SAMPLE_IVE_Md_Init(SAMPLE_IVE_MD_S *pstMd,HI_U32 u32Width,HI_U32 u32Height)
{
HI_S32 s32Ret = HI_SUCCESS;
HI_S32 i;
HI_U32 u32Size;
HI_U8 u8WndSz;
for (i = 0;i < SAMPLE_IVE_MD_IMAGE_NUM;i++)
{
s32Ret = SAMPLE_COMM_IVE_CreateImage(&pstMd->astImg[i],IVE_IMAGE_TYPE_U8C1,u32Width,u32Height);
SAMPLE_CHECK_EXPR_GOTO(HI_SUCCESS != s32Ret, MD_INIT_FAIL,"Error(%#x),Create img[%d] image failed!\n", s32Ret,i);
}
u32Size = sizeof(IVE_CCBLOB_S);
s32Ret = SAMPLE_COMM_IVE_CreateMemInfo(&pstMd->stBlob,u32Size);
SAMPLE_CHECK_EXPR_GOTO(HI_SUCCESS != s32Ret, MD_INIT_FAIL,"Error(%#x),Create blob mem info failed!\n", s32Ret);
//Set attr info
pstMd->stMdAttr.enAlgMode = MD_ALG_MODE_BG;
pstMd->stMdAttr.enSadMode = IVE_SAD_MODE_MB_4X4;
pstMd->stMdAttr.enSadOutCtrl = IVE_SAD_OUT_CTRL_THRESH;
pstMd->stMdAttr.u16SadThr = 100 * (1 << 1);//100 * (1 << 2);
pstMd->stMdAttr.u32Width = u32Width;
pstMd->stMdAttr.u32Height = u32Height;
pstMd->stMdAttr.stAddCtrl.u0q16X = 32768;
pstMd->stMdAttr.stAddCtrl.u0q16Y = 32768;
pstMd->stMdAttr.stCclCtrl.enMode = IVE_CCL_MODE_4C;
u8WndSz = (1 << (2 + pstMd->stMdAttr.enSadMode));
pstMd->stMdAttr.stCclCtrl.u16InitAreaThr = u8WndSz * u8WndSz;
pstMd->stMdAttr.stCclCtrl.u16Step = u8WndSz;
s32Ret = HI_IVS_MD_Init();
SAMPLE_CHECK_EXPR_GOTO(HI_SUCCESS != s32Ret, MD_INIT_FAIL, "Error(%#x),HI_IVS_MD_Init failed!\n", s32Ret);
MD_INIT_FAIL:
if(HI_SUCCESS != s32Ret)
{
SAMPLE_IVE_Md_Uninit(pstMd);
}
return s32Ret;
2.处理过程
s32Ret = HI_IVS_MD_CreateChn(MdChn,&(pstMd->stMdAttr));
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("HI_IVS_MD_CreateChn fail,Error(%#x)\n",s32Ret);
return ;
}
while (group.running)
{
if(s_bStopSignal == FALSE)
{
s32Ret = HI_MPI_VPSS_GetChnFrame(s32VpssGrp, as32VpssChn, &stBaseFrmInfo, s32MilliSec);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("HI_MPI_VPSS_GetChnFrame fail,Error(%#x)\n",s32Ret);
continue;
}
if (HI_TRUE != bFirstFrm)
{
s32Ret = SAMPLE_COMM_IVE_DmaImage(&stBaseFrmInfo, &pstMd->astImg[s32CurIdx], bInstant);
SAMPLE_CHECK_EXPR_GOTO(HI_SUCCESS != s32Ret,EXT_RELEASE,"SAMPLE_COMM_DmaImage fail,Error(%#x)\n",s32Ret);
}
else
{
s32Ret = SAMPLE_COMM_IVE_DmaImage(&stBaseFrmInfo, &pstMd->astImg[1 - s32CurIdx], bInstant);
SAMPLE_CHECK_EXPR_GOTO(HI_SUCCESS != s32Ret, EXT_RELEASE,"SAMPLE_COMM_DmaImage fail,Error(%#x)\n",s32Ret);
bFirstFrm = HI_FALSE;
goto CHANGE_IDX;//first frame just init reference frame
}
s32Ret = HI_IVS_MD_Process(MdChn,&pstMd->astImg[s32CurIdx],&pstMd->astImg[1 - s32CurIdx],NULL,&pstMd->stBlob);
SAMPLE_CHECK_EXPR_GOTO(HI_SUCCESS != s32Ret, EXT_RELEASE,"HI_IVS_MD_Process fail,Error(%#x)\n",s32Ret);
SAMPLE_COMM_IVE_BlobToRect(SAMPLE_COMM_IVE_CONVERT_64BIT_ADDR(IVE_CCBLOB_S,pstMd->stBlob.u64VirAddr),&(pstMd->stRegion),IVE_RECT_NUM,8,
pstMdAttr->u32Width,pstMdAttr->u32Height,stBaseFrmInfo.stVFrame.u32Width,stBaseFrmInfo.stVFrame.u32Height);
pstBlob = SAMPLE_COMM_IVE_CONVERT_64BIT_ADDR(IVE_CCBLOB_S,pstMd->stBlob.u64VirAddr);
//printf("u8RegionNum:%d\n",pstBlob->u8RegionNum);
if(pstBlob->u8RegionNum > 0)
{
xTotal = 0;
st_osddrv_rect_clear(osdHandle);
for(i = 0;i < pstBlob->u8RegionNum;i++)
{
printf("(%d,%d)\n", pstMd->stRegion.astRect[i].astPoint[0].s32X,
pstMd->stRegion.astRect[i].astPoint[0].s32Y);
printf("(%d,%d)\n", pstMd->stRegion.astRect[i].astPoint[1].s32X,
pstMd->stRegion.astRect[i].astPoint[1].s32Y);
printf("(%d,%d)\n", pstMd->stRegion.astRect[i].astPoint[2].s32X,
pstMd->stRegion.astRect[i].astPoint[2].s32Y);
printf("(%d,%d)\n", pstMd->stRegion.astRect[i].astPoint[3].s32X,
pstMd->stRegion.astRect[i].astPoint[3].s32Y);
printf("\n");
st_osddrv_rect_draw(osdHandle,0,pstMd->stRegion.astRect[i].astPoint[0].s32X*3 ,
pstMd->stRegion.astRect[i].astPoint[0].s32Y*3 ,
pstMd->stRegion.astRect[i].astPoint[2].s32X*3 ,
pstMd->stRegion.astRect[i].astPoint[2].s32Y*3);
xTotal += pstMd->stRegion.astRect[i].astPoint[0].s32X + pstMd->stRegion.astRect[i].astPoint[2].s32X;
}
st_osddrv_rect_flush(osdHandle);
}
CHANGE_IDX:
//Change reference and current frame index
s32CurIdx = 1 - s32CurIdx;
EXT_RELEASE:
s32Ret = HI_MPI_VPSS_ReleaseChnFrame(s32VpssGrp, as32VpssChn, &stBaseFrmInfo);
3.结果演示