void *VC_FaceThreadFnc(void* param) { ImageThread_S *pFaceThread; PFRectS viRect;…
- User
void VC_FaceThreadFnc(void param) { ImageThread_S *pFaceThread; PF_Rect_S viRect; PF_Rect_S faceRect = {0}; Uapi_ExpWin_t expWin; HNY_AiFaceRectInfo_S *pAiFaceRectInfo = NULL; char threadName[64]; char *pBuf = NULL; int i, id, faceRect, width, height, ret, cnt = 0; PF_Rect_S stRect = {0};
sprintf(threadName, "FaceFnc"); prctl(PR_SET_NAME, (unsigned long)threadName, 0, 0, 0); pBuf = (char *)malloc(sizeof(HNY_FrameHeader_S) + sizeof(HNY_AiFaceRectInfo_S)); if(pBuf == NULL) { DEBUG_ERROR(MODULE_CODEC, "Call malloc func err!"); return NULL; } memset(&viRect, 0x0, sizeof(PF_Rect_S)); VC_GetViRect(0, &viRect); pFaceThread = (ImageThread_S *)param; while(pFaceThread->threadRun) { memset(pBuf, 0x00, sizeof(HNY_FrameHeader_S) + sizeof(HNY_AiFaceRectInfo_S)); ret = SHB_ShareBufGetOneFrame(g_imageManager.metaDataBuf, sizeof(HNY_FrameHeader_S) + sizeof(HNY_AiFaceRectInfo_S), pBuf); if(ret <= 0) { usleep(50*1000); cnt ++; if(cnt < 3) continue; } if(cnt >= 3) { cnt = 0; expWin.h_offs = 0; expWin.v_offs = 0; expWin.h_size = 1920; expWin.v_size = 1080; } else { pAiFaceRectInfo = (HNY_AiFaceRectInfo_S *)(pBuf + sizeof(HNY_FrameHeader_S)); if(pAiFaceRectInfo->faceCnt <= 0) { usleep(50*1000); continue; } //查找最大人脸 id = -1; faceRect = 0; for(i=0; i<pAiFaceRectInfo->faceCnt; i++) { width = pAiFaceRectInfo->faceRect[i].faceRect.right - pAiFaceRectInfo->faceRect[i].faceRect.left; height = pAiFaceRectInfo->faceRect[i].faceRect.bottom - pAiFaceRectInfo->faceRect[i].faceRect.top; if(faceRect < width*height) { id = i; faceRect = width*height; } } if(id >= 0) { PF_Rect_S curFaceRect = pAiFaceRectInfo->faceRect[id].faceRect; if(stRect.x == 0 && stRect.width == 0 && stRect.y == 0 && stRect.height == 0) { stRect = curFaceRect; } else { int curWidth = curFaceRect.width; int curHeight = curFaceRect.height; int maxWidth = stRect.width; int maxHeight = stRect.height; if(curWidth < maxWidth * 0.8 || curHeight < maxHeight * 0.8) //新检测到人脸大小太小 { if(cnt == 0) { cnt = 3; //直接使用上一次稳定的人脸框 } continue; } else { stRect.x = (stRect.x + curFaceRect.x) / 2; stRect.width = (stRect.width + curFaceRect.width) / 2; stRect.y = (stRect.y + curFaceRect.y) / 2; stRect.height = (stRect.height + curFaceRect.height) / 2; //限制人脸框的范围 if(stRect.x < 0) {stRect.x = 0;} if(stRect.y < 0) {stRect.y = 0;} if(stRect.width > viRect.width) {stRect.width = viRect.width;} if(stRect.height > viRect.height) {stRect.height = viRect.height;} } } //更新当前使用的人脸框 id = -1; for(i=0; i<pAiFaceRectInfo->faceCnt; i++) { if(stRect.x >= pAiFaceRectInfo->faceRect[i].faceRect.left && (stRect.x + stRect.width) <= pAiFaceRectInfo->faceRect[i].faceRect.right && stRect.y >= pAiFaceRectInfo->faceRect[i].faceRect.top && (stRect.y+stRect.height) <= pAiFaceRectInfo->faceRect[i].faceRect.bottom) { id = i; break; } } if(id >= 0) { pAiFaceRectInfo->faceCnt = 1; pAiFaceRectInfo->faceRect[0] = pAiFaceRectInfo->faceRect[id]; } else { continue; } } //获取人脸框 if(pAiFaceRectInfo->faceCnt > 0) { faceRect = pAiFaceRectInfo->faceRect[0].faceRect; } else { usleep(50*1000); continue; } expWin.h_offs = pAiFaceRectInfo->faceRect[id].faceRect.left * viRect.width / 10000; expWin.v_offs = pAiFaceRectInfo->faceRect[id].faceRect.top * viRect.height / 10000; expWin.h_size = (pAiFaceRectInfo->faceRect[id].faceRect.right - pAiFaceRectInfo->faceRect[id].faceRect.left) * viRect.width / 10000; expWin.v_size = (pAiFaceRectInfo->faceRect[id].faceRect.bottom - pAiFaceRectInfo->faceRect[id].faceRect.top) * viRect.height / 10000; stRect.x = expWin.h_offs; stRect.y = expWin.v_offs; stRect.width = expWin.h_size; stRect.height = expWin.v_size; ret = VC_SetFaceExp(stRect); } if(ret < 0) { DEBUG_ERROR(MODULE_CODEC, "SAMPLE_COMM_ISP_SET_ExpWinAttr failed[%d]!", ret); } } DEBUG_ERROR(MODULE_CODEC, "thread[%s] exit!", threadName); free(pBuf); return NULL; - Assistant
在代码中,定义了多个名为faceRect的变量。此外,在第390行的if语句中,PF_Rect_S类型的结构体变量stRect的初始化方式存在问题。在第451行,将HNY_Rect_S类型的结构体变量赋值给int类型的变量id,导致类型不兼容的错误。
为了解决这些问题,可以采取以下措施:
-
修改代码中名为faceRect的变量名,避免命名冲突。
-
在第390行修改if语句中PF_Rect_S类型的结构体变量stRect的初始化方式,例如改为stRect = {0}。
-
在第451行修改赋值语句,将HNY_Rect_S类型的结构体变量赋值给与之兼容的变量类型。
-