Skip to content

Commit

Permalink
formatting code
Browse files Browse the repository at this point in the history
Signed-off-by: carbon <[email protected]>
  • Loading branch information
carbonfix committed Dec 11, 2024
1 parent 9e91c2c commit b19e429
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 66 deletions.
6 changes: 3 additions & 3 deletions common/sample_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ CVI_S32 get_od_model_info(const char *model_name, CVI_TDL_SUPPORTED_MODEL_E *mod
*model_index = CVI_TDL_SUPPORTED_MODEL_MOBILEDETV2_PEDESTRIAN;
} else if (strcmp(model_name, "yolov3") == 0) {
*model_index = CVI_TDL_SUPPORTED_MODEL_YOLOV3;
} else if (strcmp(model_name, "person-pets-detection") == 0) {
} else if (strcmp(model_name, "yolov8-person-pets") == 0) {
*model_index = CVI_TDL_SUPPORTED_MODEL_PERSON_PETS_DETECTION;
} else if (strcmp(model_name, "yolox") == 0) {
*model_index = CVI_TDL_SUPPORTED_MODEL_YOLOX;
Expand All @@ -39,7 +39,7 @@ CVI_S32 get_pd_model_info(const char *model_name, CVI_TDL_SUPPORTED_MODEL_E *mod
*model_index = CVI_TDL_SUPPORTED_MODEL_MOBILEDETV2_COCO80;
} else if (strcmp(model_name, "mobiledetv2-pedestrian") == 0) {
*model_index = CVI_TDL_SUPPORTED_MODEL_MOBILEDETV2_PEDESTRIAN;
} else if (strcmp(model_name, "person-pets-detection") == 0) {
} else if (strcmp(model_name, "yolov8-person-pets") == 0) {
*model_index = CVI_TDL_SUPPORTED_MODEL_PERSON_PETS_DETECTION;
} else if (strcmp(model_name, "yolov3") == 0) {
*model_index = CVI_TDL_SUPPORTED_MODEL_YOLOV3;
Expand All @@ -63,7 +63,7 @@ CVI_S32 get_vehicle_model_info(const char *model_name, CVI_TDL_SUPPORTED_MODEL_E
*model_index = CVI_TDL_SUPPORTED_MODEL_MOBILEDETV2_VEHICLE;
} else if (strcmp(model_name, "yolov3") == 0) {
*model_index = CVI_TDL_SUPPORTED_MODEL_YOLOV3;
} else if (strcmp(model_name, "person-pets-detection") == 0) {
} else if (strcmp(model_name, "yolov8-person-pets") == 0) {
*model_index = CVI_TDL_SUPPORTED_MODEL_PERSON_PETS_DETECTION;
} else if (strcmp(model_name, "yolox") == 0) {
*model_index = CVI_TDL_SUPPORTED_MODEL_YOLOX;
Expand Down
101 changes: 38 additions & 63 deletions sample_vi_od/sample_vi_od.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ MUTEXAUTOLOCK_INIT(ResultMutex);
*/
typedef struct {
SAMPLE_TDL_MW_CONTEXT *pstMWContext;
CVI_TDL_SUPPORTED_MODEL_E enOdModelId;
cvitdl_service_handle_t stServiceHandle;
CVI_TDL_SUPPORTED_MODEL_E enOdModelId;
} SAMPLE_TDL_VENC_THREAD_ARG_S;

/**
Expand Down Expand Up @@ -64,35 +64,26 @@ void *run_venc(void *args) {
CVI_TDL_CopyObjectMeta(&g_stObjMeta, &stObjMeta);
}

if(pstArgs->enOdModelId == CVI_TDL_SUPPORTED_MODEL_PERSON_PETS_DETECTION)
{
for (uint32_t oid = 0; oid < stObjMeta.size; oid++) {
char name[256];
if (stObjMeta.info[oid].classes == 0)
{
sprintf(name, "cat: %.2f",stObjMeta.info[oid].bbox.score);
}
if (stObjMeta.info[oid].classes == 1)
{
sprintf(name, "dog: %.2f",stObjMeta.info[oid].bbox.score);
if(pstArgs->enOdModelId == CVI_TDL_SUPPORTED_MODEL_PERSON_PETS_DETECTION) {
for (uint32_t oid = 0; oid < stObjMeta.size; oid++) {
char name[256];
if (stObjMeta.info[oid].classes == 0) {
sprintf(name, "cat: %.2f",stObjMeta.info[oid].bbox.score);
}
if (stObjMeta.info[oid].classes == 1) {
sprintf(name, "dog: %.2f",stObjMeta.info[oid].bbox.score);
}
if (stObjMeta.info[oid].classes == 2) {
sprintf(name, "person: %.2f",stObjMeta.info[oid].bbox.score);
}
memcpy(stObjMeta.info[oid].name, name, sizeof(stObjMeta.info[oid].name));
}
if (stObjMeta.info[oid].classes == 2)
{
sprintf(name, "person: %.2f",stObjMeta.info[oid].bbox.score);
} else {
for (uint32_t oid = 0; oid < stObjMeta.size; oid++) {
char name[256];
sprintf(name, "%s: %.2f", stObjMeta.info[oid].name, stObjMeta.info[oid].bbox.score);
memcpy(stObjMeta.info[oid].name, name, sizeof(stObjMeta.info[oid].name));
}
memcpy(stObjMeta.info[oid].name, name, sizeof(stObjMeta.info[oid].name));
}

}


else {

for (uint32_t oid = 0; oid < stObjMeta.size; oid++) {
char name[256];
sprintf(name, "%s: %.2f", stObjMeta.info[oid].name, stObjMeta.info[oid].bbox.score);
memcpy(stObjMeta.info[oid].name, name, sizeof(stObjMeta.info[oid].name));
}
}

s32Ret = CVI_TDL_Service_ObjectDrawRect(pstArgs->stServiceHandle, &stObjMeta, &stFrame, true,
Expand Down Expand Up @@ -131,46 +122,30 @@ void *run_tdl_thread(void *args) {
goto get_frame_failed;
}




//

// }

struct timeval t0, t1;
struct timeval t0, t1;
gettimeofday(&t0, NULL);
s32Ret = pstTDLArgs->inference_func(pstTDLArgs->stTDLHandle, &stFrame, pstTDLArgs->enOdModelId,
s32Ret = pstTDLArgs->inference_func(pstTDLArgs->stTDLHandle, &stFrame, pstTDLArgs->enOdModelId,
&stObjMeta);
gettimeofday(&t1, NULL);
gettimeofday(&t1, NULL);

if (s32Ret != CVI_TDL_SUCCESS) {
printf("inference failed!, ret=%x\n", s32Ret);
if (s32Ret != CVI_TDL_SUCCESS) {
printf("inference failed!, ret=%x\n", s32Ret);
goto inf_error;
}

if(pstTDLArgs->enOdModelId == CVI_TDL_SUPPORTED_MODEL_PERSON_PETS_DETECTION)
{
for (uint32_t oid = 0; oid < stObjMeta.size; oid++) {
printf(" %.2f %.2f %.2f %.2f %d %.2f\n",
stObjMeta.info[oid].bbox.x1, stObjMeta.info[oid].bbox.y1, stObjMeta.info[oid].bbox.x2, stObjMeta.info[oid].bbox.y2, stObjMeta.info[oid].classes,
stObjMeta.info[oid].bbox.score);
}
}
else {


unsigned long execution_time = ((t1.tv_sec - t0.tv_sec) * 1000000 + t1.tv_usec - t0.tv_usec);
if (counter++ % 5 == 0)
printf("obj count: %d, take %.2f ms, width:%u\n", stObjMeta.size, (float)execution_time / 1000,
stFrame.stVFrame.u32Width);


}




if(pstTDLArgs->enOdModelId == CVI_TDL_SUPPORTED_MODEL_PERSON_PETS_DETECTION) {
for (uint32_t oid = 0; oid < stObjMeta.size; oid++) {
printf("%.2f %.2f %.2f %.2f %d %.2f\n",
stObjMeta.info[oid].bbox.x1, stObjMeta.info[oid].bbox.y1,
stObjMeta.info[oid].bbox.x2, stObjMeta.info[oid].bbox.y2,
stObjMeta.info[oid].classes, stObjMeta.info[oid].bbox.score);
}
} else {
unsigned long execution_time = ((t1.tv_sec - t0.tv_sec) * 1000000 + t1.tv_usec - t0.tv_usec);
if (counter++ % 5 == 0)
printf("obj count: %d, take %.2f ms, width:%u\n", stObjMeta.size, (float)execution_time / 1000,
stFrame.stVFrame.u32Width);
}

{
// Copy object detection results to global.
Expand Down Expand Up @@ -329,7 +304,7 @@ int main(int argc, char *argv[]) {
"mobiledetv2-coco80, "
"mobiledetv2-vehicle, "
"mobiledetv2-pedestrian, "
"person-pets-detection,"
"yolov8-person-pets, "
"yolov3, yolox}\n"
"\tMODEL_PATH, cvimodel path\n"
"\tTHRESHOLD (optional), threshold for detection model (default: 0.5)\n",
Expand Down

0 comments on commit b19e429

Please sign in to comment.