#include "aw_ai_eve_event_interface.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define VIDEOWIDTH 640 #define VIDEOHEIGHT 360 #define SFWIDTH 640 #define SFHEIGHT 360 #define TEST_COST 1 #define SAVE_RESULT 1 #ifdef TEST_COST /** * ��������ʱ���ļ������õ�ʱ���� * @param struct timeval* resule ���ؼ���������ʱ�� * @param struct timeval* x ��Ҫ������ǰһ��ʱ�� * @param struct timeval* y ��Ҫ�����ĺ�һ��ʱ�� * return -1 failure ,0 success **/ static int timeval_subtract(struct timeval *result, struct timeval *x, struct timeval *y) { int nsec; if (x->tv_sec > y->tv_sec) return -1; if ((x->tv_sec == y->tv_sec) && (x->tv_usec > y->tv_usec)) return -1; result->tv_sec = (y->tv_sec - x->tv_sec); result->tv_usec = (y->tv_usec - x->tv_usec); if (result->tv_usec < 0) { result->tv_sec--; result->tv_usec += 1000000; } return 0; } #endif static AW_S32 write_blob(AW_BLOB_S *blob, FILE *fs) { fwrite(&blob->s16X, sizeof(AW_S16), 1, fs); fwrite(&blob->s16Y, sizeof(AW_S16), 1, fs); fwrite(&blob->s16Width, sizeof(AW_S16), 1, fs); fwrite(&blob->s16Height, sizeof(AW_S16), 1, fs); return 0; } AW_S32 eve_kernel_dump_result_to_file(AW_BLOB_S *resPtr, AW_U32 num, FILE *fs) { AW_U32 i = 0; fwrite(&num, sizeof(AW_U32), 1, fs); for (i = 0; i < num; i++, resPtr++) { write_blob(resPtr, fs); } return 0; } void *dma_pUsr = NULL; static void dmaCallBackFunc(void *pUsr) { printf("[Dma Callback]: Run!\n"); return; } static AW_U8 *awKeyNew = "1111111111111111"; int main(int argc, char *argv[]) { // get version char *fileName = argv[1]; int flag = 0; char key[10000]; char key_0[25]; int testresult = 0; #ifdef SAVE_RESULT FILE *fileRes = NULL; #endif AW_S32 mT = 3; AW_S32 status; AW_S8 cVersion[128]; AW_S32 i; printf("start app\n"); status = AW_AI_EVE_Event_GetAlgoVersion(cVersion); if (AW_STATUS_ERROR == status) { printf("AW_AI_EVE_Event_GetAlgoVersion failure!\n"); return -1; } else { printf("AW_AI_EVE_Event_GetAlgoVersion version is %s!\n", cVersion); } // initilize AW_AI_EVE_CTRL_S sEVECtrl; sEVECtrl.addrInputType = AW_AI_EVE_ADDR_INPUT_VIR; //����������ַ sEVECtrl.scale_factor = 1; sEVECtrl.mScanStageNo = 10; sEVECtrl.yStep = 3; sEVECtrl.xStep0 = 1; sEVECtrl.xStep1 = 4; sEVECtrl.mRltNum = AW_AI_EVE_MAX_RESULT_NUM; sEVECtrl.mMidRltNum = 0; sEVECtrl.mMidRltStageNo = 50; sEVECtrl.mRltNum = AW_AI_EVE_MAX_RESULT_NUM; sEVECtrl.rltType = AW_AI_EVE_RLT_OUTPUT_DETAIL; sEVECtrl.mDmaOut.s16Width = 640; sEVECtrl.mDmaOut.s16Height = 360; sEVECtrl.mPyramidLowestLayel.s16Width = 640; sEVECtrl.mPyramidLowestLayel.s16Height = 360; sEVECtrl.dmaSrcSize.s16Width = 640; sEVECtrl.dmaSrcSize.s16Height = 360; sEVECtrl.dmaDesSize.s16Width = 640; sEVECtrl.dmaDesSize.s16Height = 360; sEVECtrl.dmaRoi.s16X = 0; sEVECtrl.dmaRoi.s16Y = 0; sEVECtrl.dmaRoi.s16Width = sEVECtrl.dmaDesSize.s16Width; sEVECtrl.dmaRoi.s16Height = sEVECtrl.dmaDesSize.s16Height; sEVECtrl.classifierNum = 1; sEVECtrl.classifierPath[0].path = (AW_S8 *)"/etc/eve/car.ld"; sEVECtrl.classifierPath[0].key = (AW_U8 *)awKeyNew; sEVECtrl.classifierPath[0].type = AW_CLASSIFIY_TYPE_LBP; /*sEVECtrl.classifierPath[1].path = (AW_S8*)"./classifier/fullprofleftface.ld"; sEVECtrl.classifierPath[1].key = (AW_U8*)awKeyNew; sEVECtrl.classifierPath[2].path = (AW_S8*)"./classifier/fullprofrightface.ld"; sEVECtrl.classifierPath[2].key = (AW_U8*)awKeyNew; sEVECtrl.classifierPath[3].path = (AW_S8*)"./classifier/halfdownface.ld"; sEVECtrl.classifierPath[3].key = (AW_U8*)awKeyNew; sEVECtrl.classifierPath[4].path = (AW_S8*)"./classifier/profileface.ld"; sEVECtrl.classifierPath[4].key = (AW_U8*)awKeyNew; sEVECtrl.classifierPath[5].path = (AW_S8*)"./classifier/rotleftface.ld"; sEVECtrl.classifierPath[5].key = (AW_U8*)awKeyNew; sEVECtrl.classifierPath[6].path = (AW_S8*)"./classifier/rotrightface.ld"; sEVECtrl.classifierPath[6].key = (AW_U8*)awKeyNew; sEVECtrl.classifierPath[7].path = (AW_S8*)"./classifier/smallface.ld"; sEVECtrl.classifierPath[7].key = (AW_U8*)awKeyNew;*/ printf("scale_factor = %d, mScanStageNo = %d, yStep = %d, xStep0 = %d,\ xStep1 = %d, MergerT = %d, mMidRltNum = %d, mMidRltStageNo = %d\n", sEVECtrl.scale_factor, sEVECtrl.mScanStageNo, sEVECtrl.yStep, sEVECtrl.xStep0, sEVECtrl.xStep1, mT, sEVECtrl.mMidRltNum, sEVECtrl.mMidRltStageNo); sEVECtrl.dmaCallBackFunc = &dmaCallBackFunc; sEVECtrl.dma_pUsr = dma_pUsr; AW_HANDLE hEveEvent = AW_AI_EVE_Event_Init(&sEVECtrl); if (AW_NULL == hEveEvent) { printf("AW_AI_EVE_Event_Init failure!\n"); return -1; } else { printf("AW_AI_EVE_Event_Init finish!\n"); } AW_AI_EVE_Event_SetEveDMAExecuteMode(hEveEvent, AW_AI_EVE_DMA_EXECUTE_SYNC); AW_IMAGE_S image; AW_S64 timestamp = 1; AW_AI_EVE_EVENT_RESULT_S faceres; // // NV21 image.mWidth = VIDEOWIDTH; image.mHeight = VIDEOHEIGHT; image.mPixelFormat = MM_PIXEL_FORMAT_YVU_SEMIPLANAR_420; image.mpVirAddr[0] = (AW_PVOID)malloc(VIDEOWIDTH * VIDEOHEIGHT); image.mpVirAddr[1] = (AW_PVOID)malloc(VIDEOWIDTH * VIDEOHEIGHT / 2); image.mpVirAddr[2] = 0; image.mPhyAddr[0] = 0; image.mPhyAddr[1] = 0; image.mPhyAddr[2] = 0; image.mStride[0] = VIDEOWIDTH; image.mStride[1] = VIDEOWIDTH; image.mStride[2] = 0; // set face event parameter AW_AI_EVE_EVENT_FACEDET_PARAM_S facedetparam; facedetparam.sRoiSet.s32RoiNum = 1; facedetparam.sRoiSet.sID[0] = 1; facedetparam.sRoiSet.sRoi[0].s16Left = 0; facedetparam.sRoiSet.sRoi[0].s16Top = 0; facedetparam.sRoiSet.sRoi[0].s16Right = VIDEOWIDTH; facedetparam.sRoiSet.sRoi[0].s16Bottom = VIDEOHEIGHT; facedetparam.s32ClassifyFlag = 0; facedetparam.s32MinFaceSize = 20; facedetparam.s32OverLapCoeff = 20; facedetparam.s32MaxFaceNum = 128; facedetparam.s32MergeThreshold = mT; status = AW_AI_EVE_Event_SetEventParam(hEveEvent, AW_AI_EVE_EVENT_FACEDETECT, (AW_PVOID)&facedetparam); if (AW_STATUS_ERROR == status) { printf("AW_AI_EVE_Event_SetEventParam failure!, errorcode = %d\n", AW_AI_EVE_Event_GetLastError(hEveEvent)); return -1; } // process FILE *fileNode = fopen(fileName, "rb"); printf("[Info]: Start detection loop!\n"); int frameNum = 0; AW_BLOB_SET_S blobsetres; #ifdef SAVE_RESULT fileRes = fopen("facevideores.txt", "wb"); #endif #ifdef TEST_COST struct timeval starttime, endtime, difftime; #endif while (1) { flag = fread(image.mpVirAddr[0], sizeof(AW_U8), VIDEOWIDTH * VIDEOHEIGHT, fileNode); if (flag == 0) { break; } fread(image.mpVirAddr[1], sizeof(AW_U8), VIDEOWIDTH * VIDEOHEIGHT / 2, fileNode); frameNum++; AW_AI_EVE_Event_SetEveSourceAddress(hEveEvent, image.mpVirAddr[0]); #ifdef TEST_COST gettimeofday(&starttime, 0); #endif status = AW_AI_EVE_Event_Process(hEveEvent, &image, timestamp, &faceres); if (faceres.sTarget.s32TargetNum > 0) { printf("total face = %d\n", faceres.sTarget.s32TargetNum); } #ifdef TEST_COST gettimeofday(&endtime, 0); timeval_subtract(&difftime, &starttime, &endtime); printf("AW_AI_EVE_Event_Process cost time = %f ms , frames:%d\n", difftime.tv_usec / 1000.f, frameNum); #endif #ifdef SAVE_RESULT fwrite(&frameNum, sizeof(AW_U32), 1, fileRes); #endif #ifdef SAVE_RESULT blobsetres.s32Num = faceres.sTarget.s32TargetNum; for (i = 0; i < blobsetres.s32Num; i++) { blobsetres.blob[i].s16X = faceres.sTarget.astTargets[i].stRect.s16Left; blobsetres.blob[i].s16Y = faceres.sTarget.astTargets[i].stRect.s16Top; blobsetres.blob[i].s16Width = faceres.sTarget.astTargets[i].stRect.s16Right - faceres.sTarget.astTargets[i].stRect.s16Left + 1; blobsetres.blob[i].s16Height = faceres.sTarget.astTargets[i].stRect.s16Bottom - faceres.sTarget.astTargets[i].stRect.s16Top + 1; } eve_kernel_dump_result_to_file(blobsetres.blob, blobsetres.s32Num, fileRes); fflush(fileRes); #endif if (AW_STATUS_ERROR == status) { printf("AW_AI_EVE_Event_Process failure!, errorcode = %d\n", AW_AI_EVE_Event_GetLastError(hEveEvent)); break; } } fclose(fileNode); #ifdef SAVE_RESULT if (fileRes != NULL) { fclose(fileRes); fileRes = NULL; } #endif // release status = AW_AI_EVE_Event_UnInit(hEveEvent); if (AW_STATUS_ERROR == status) { printf("AW_AI_EVE_Event_UnInit failure!, errorcode = %d\n", AW_AI_EVE_Event_GetLastError(hEveEvent)); return -1; } return 0; }