//优化人脸稳定性输出代码
if(id >= 0)
{
PF_Rect_S curFaceRect = pAiFaceRectInfo->faceRect[id].faceRect;
if(stRect.left == 0 && stRect.right == 0 && stRect.top == 0 && stRect.bottom == 0)
{
stRect = curFaceRect;
}
else
{
int curWidth = curFaceRect.right - curFaceRect.left;
int curHeight = curFaceRect.bottom - curFaceRect.top;
int maxWidth = stRect.right - stRect.left;
int maxHeight = stRect.bottom - stRect.top;
if(curWidth < maxWidth * 0.8 || curHeight < maxHeight * 0.8) //新检测到人脸大小太小
{
if(cnt == 0)
{
cnt = 3; //直接使用上一次稳定的人脸框
}
continue;
}
else
{
stRect.left = (stRect.left + curFaceRect.left) / 2;
stRect.right = (stRect.right + curFaceRect.right) / 2;
stRect.top = (stRect.top + curFaceRect.top) / 2;
stRect.bottom = (stRect.bottom + curFaceRect.bottom) / 2;
//限制人脸框的范围
if(stRect.left < 0) stRect.left = 0;
if(stRect.top < 0) stRect.top = 0;
if(stRect.right > viRect.width) stRect.right = viRect.width;
if(stRect.bottom > viRect.height) stRect.bottom = viRect.height;
}
}
//更新当前使用的人脸框
id = -1;
for(i=0; i<pAiFaceRectInfo->faceCnt; i++)
{
if(stRect.left >= pAiFaceRectInfo->faceRect[i].faceRect.left
&& stRect.right <= pAiFaceRectInfo->faceRect[i].faceRect.right
&& stRect.top >= pAiFaceRectInfo->faceRect[i].faceRect.top
&& stRect.bottom <= pAiFaceRectInfo->faceRect[i].faceRect.bottom)
{
id = i;
break;
}
}
if(id >= 0)
{
pAiFaceRectInfo->faceCnt = 1;
pAiFaceRectInfo->faceRect[0] = pAiFaceRectInfo->faceRect[id];
}
else
{
continue;
}
}

//获取人脸框
PF_Rect_S faceRect = {0};
if(pAiFaceRectInfo->faceCnt > 0)
{
faceRect = pAiFaceRectInfo->faceRect[0].faceRect;
}
else
{
usleep(501000);
continue;
}

//根据人脸框位置计算VGRect
VGRect_S vgRect = {0};
float vgXRatio = 1.0 * viRect.width / VC_GetVGInfo()->VGWidth;
float vgYRatio = 1.0 * viRect.height / VC_GetVGInfo()->VGHeight;
vgRect.left = faceRect.left / vgXRatio;
vgRect.top = faceRect.top / vgYRatio;
vgRect.right = faceRect.right / vgXRatio;
vgRect.bottom = faceRect.bottom / vgYRatio;

//根据VGRect计算ExpWin
expWin.h_offs = vgRect.left - VC_GetVGInfo()->VGLeft;
expWin.v_offs = vgRect.top - VC_GetVGInfo()->VGTop;
expWin.h_size = vgRect.right - vgRect.left;
expWin.v_size = vgRect.bottom - vgRect.top;

//限制ExpWin位置和大小
if(expWin.h_offs < 0)
{
expWin.h_offs = 0;
expWin.h_size = vgRect.right - VC_GetVGInfo()->VGLeft;
}
if(expWin.v_offs < 0)
{
expWin.v_offs = 0;
expWin.v_size = vgRect.bottom - VC_GetVGInfo()->VGTop;
}
if(expWin.h_offs + expWin.h_size > viRect.width)
{
expWin.h_size = viRect.width - expWin.h_offs;
}
if(expWin.v_offs + expWin.v_size > viRect.height)
{
expWin.v_size = viRect.height - expWin.v_offs;
}

//发送ExpWin到图像处理线程
VC_ImageManagerSetExpWin(&expWin);
}//end while

free(pBuf);
pBuf = NULL;
}翻译