diff --git a/src/face_nv_infer_server_manager.cpp b/src/face_nv_infer_server_manager.cpp index 051c3f3..1ccee04 100644 --- a/src/face_nv_infer_server_manager.cpp +++ b/src/face_nv_infer_server_manager.cpp @@ -1038,91 +1038,50 @@ NvOSD_RectParams *FaceNvInferServerManager::allign_postprocess( float y0 = parent_bbox.top; float w0 = parent_bbox.width; float h0 = parent_bbox.height; - // std::cout << "x = " << x0 - // << " y = " << y0 - // << " w = " << w0 - // << " h = " << h0 - // << std::endl; + float scale = std::min(target_w / w0, target_h / h0); int new_w = int(w0 * scale); int new_h = int(h0 * scale); int pad_w = target_w - new_w; int pad_h = target_h - new_h; - // std::cout << "scale = " << scale - // << " new_w = " << new_w - // << " new_h = " << new_h - // << " pad_w = " << pad_w - // << " pad_h = " << pad_h - // << std::endl; int left = (int)pad_w / 2; // int right = pad_w - left; int top = (int)pad_h / 2; // int bottom = pad_h - top; // int _pad =(left, top); // int _scale = scale; - // std::cout << "left = " << left - // << " top = " << top - // << std::endl; float x1n = numpy_clip(face_location[0], 0.0f, 1.0f); float y1n = numpy_clip(face_location[1], 0.0f, 1.0f); float x2n = numpy_clip(face_location[2], 0.0f, 1.0f); float y2n = numpy_clip(face_location[3], 0.0f, 1.0f); - // std::cout << "x1n = " << x1n - // << " y1n = " << y1n - // << " x2n = " << x2n - // << " y2n = " << y2n - // << std::endl; - float x1_p = x1n * target_w; float y1_p = y1n * target_h; float x2_p = x2n * target_w; float y2_p = y2n * target_h; - // std::cout << "x1_p = " << x1_p - // << " y1_p = " << y1_p - // << " x2_p = " << x2_p - // << " y2_p = " << y2_p - // << std::endl; int pad_x = left; int pad_y = top; - // std::cout << "pad_x = " << pad_x - // << " pad_y = " << pad_y - // << std::endl; + float x1 = (x1_p - pad_x) / scale; float y1 = (y1_p - pad_y) / scale; float x2 = (x2_p - pad_x) / scale; float y2 = (y2_p - pad_y) / scale; - // std::cout << "x1 = " << x1 - // << " y1 = " << y1 - // << " x2 = " << x2 - // << " y2 = " << y2 - // << std::endl; x1 += x0; y1 += y0; x2 += x0; y2 += y0; - // std::cout << "x1 = " << x1 - // << " y1 = " << y1 - // << " x2 = " << x2 - // << " y2 = " << y2 - // << std::endl; NvOSD_RectParams *updated_bbox = new NvOSD_RectParams(); updated_bbox->left = x1; updated_bbox->top = y1; updated_bbox->width = x2 - x1; updated_bbox->height = y2 - y1; - // std::cout << "x = " << updated_bbox->left - // << " y = " << updated_bbox->top - // << " w = " << updated_bbox->width - // << " h = " << updated_bbox->height - // << std::endl; + // box = [int(x1), int(y1), int(x2), int(y2)]; - // std::quick_exit(0); return updated_bbox; } @@ -1135,7 +1094,6 @@ void FaceNvInferServerManager::add_face_body(int object_id, float face_score) { if (((*iter).face_score > face_score)) { // std::cout<<(*iter).face_score; (*iter).face_score = face_score; - // std::cout<<" "<<(*iter).face_score<(ctx), &objData, ip_surf, obj_meta, frame_meta); - if (obj_meta->unique_component_id == 1) { - std::cout << "obj_meta->unique_component_id = " - << obj_meta->unique_component_id - << " obj_meta->rect_params.width = " - << obj_meta->rect_params.width - << " obj_meta->rect_params.height = " - << obj_meta->rect_params.height << std::endl; - std::quick_exit(0); - } } void FaceNvInferServerManager::encode_full_frame_attach_meta( @@ -1262,6 +1209,29 @@ bool FaceNvInferServerManager::all_zero(const float *data, size_t size) { return true; } +/** + * @brief Collect all BODY objects in the frame and return a map + * from object_id to NvDsObjectMeta*. + * + * @param frame_meta Frame metadata containing objects + * @param body_component_id unique_component_id used for BODY objects (e.g., 1) + * @return std::unordered_map map of body objects + */ +std::unordered_map +FaceNvInferServerManager::collect_body_objects(NvDsFrameMeta *frame_meta, + gint body_component_id = 1) { + std::unordered_map body_map; + for (NvDsMetaList *l_obj = frame_meta->obj_meta_list; l_obj != nullptr; + l_obj = l_obj->next) { + NvDsObjectMeta *obj = static_cast(l_obj->data); + if (!obj) continue; + if (obj->unique_component_id == body_component_id) { + body_map[obj->object_id] = obj; + } + } + return body_map; +} + /* This is the buffer probe function that we have registered on the sink pad * of the tiler element. All SGIE infer elements in the pipeline shall attach * their NvDsInferTensorMeta to each object's metadata of each frame, here we @@ -1294,52 +1264,26 @@ GstPadProbeReturn FaceNvInferServerManager::sgie_pad_buffer_probe( gst_buffer_get_nvds_batch_meta(GST_BUFFER(info->data)); if (!batch_meta) return GST_PAD_PROBE_OK; bool is_zero_embedding_vector = false; - bool current_full_frame_is_captured = false; + // bool current_full_frame_is_captured = false; + bool find_body = false; /* Iterate each frame metadata in batch */ for (NvDsMetaList *l_frame = batch_meta->frame_meta_list; l_frame != NULL; l_frame = l_frame->next) { NvDsFrameMeta *frame_meta = (NvDsFrameMeta *)l_frame->data; - current_full_frame_is_captured = false; + // current_full_frame_is_captured = false; + + std::unordered_map body_map = + collect_body_objects(frame_meta); /* Iterate object metadata in frame */ for (NvDsMetaList *l_obj = frame_meta->obj_meta_list; l_obj != NULL; l_obj = l_obj->next) { NvDsObjectMeta *obj_meta = (NvDsObjectMeta *)l_obj->data; - if (obj_meta->unique_component_id == 1 && - obj_meta->obj_user_meta_list != NULL) { - // body object obj_user_meta_list list is empty so - // for loop : Iterate user metadata in object to search SGIE's - // tensor data could not execute. - std::cout << "obj_meta->unique_component_id = " - << obj_meta->unique_component_id - << " obj_meta->rect_params.width = " - << obj_meta->rect_params.width - << " obj_meta->rect_params.height = " - << obj_meta->rect_params.height << std::endl; - } - // if (obj_meta->unique_component_id == 2) { - // body = obj_meta->parent; + if (!obj_meta) continue; - // // if(body) - // // { - // // std::cout<<"body->class_id = "<class_id - // // << " body->unique_component_id = - // "<unique_component_id<unique_component_id==1){ - // // std::quick_exit(0); - // // } - // // } - - // } - // (void)parent; - // if (obj_meta->unique_component_id != - // IMPRECISE_FACE_COMPONENT_ID){ - // continue; - // } - // 1 , 41 for face - // 0 for body + // 1 , 41 for face 0 for body if (obj_meta->class_id == 1) { if (obj_meta->rect_params.width > obj_meta->rect_params.height) { @@ -1362,13 +1306,7 @@ GstPadProbeReturn FaceNvInferServerManager::sgie_pad_buffer_probe( // body_obj->rect_params.height); } } - // else{ - // // std::cout<<"obj_meta->class_id =" - // <class_id<class_id = "<class_id - // << " obj_meta->unique_component_id = - // "<unique_component_id<obj_user_meta_list; l_user != NULL; l_user = l_user->next) { @@ -1381,7 +1319,6 @@ GstPadProbeReturn FaceNvInferServerManager::sgie_pad_buffer_probe( NvDsInferTensorMeta *meta = (NvDsInferTensorMeta *)user_meta->user_meta_data; - // from here // std::cout << "meta->num_output_layers: " // << meta->num_output_layers << std::endl; for (unsigned int i = 0; i < meta->num_output_layers; i++) { @@ -1498,25 +1435,15 @@ GstPadProbeReturn FaceNvInferServerManager::sgie_pad_buffer_probe( } if (score_face > threshold_face_detection) { - // std::cout<<"obj_meta->rect_params left = - // "<rect_params.left - // <<" top = "<rect_params.top - // <<" width = "<rect_params.width - // <<" height = - // "<rect_params.height<rect_params, face_location); - // std::cout<<"updated_bbox left = "<left - // <<" top = "<top - // <<" width = "<width - // <<" height = "<height<obj_label, "FINAL_FACE", - sizeof(final_face_obj->obj_label) - 1); + strncpy( + final_face_obj->obj_label, sgie_class_str[0], + sizeof(final_face_obj->obj_label) - 1); //"FINAL_FACE" final_face_obj ->obj_label[sizeof(final_face_obj->obj_label) - 1] = '\0'; // Ensure null termination @@ -1525,12 +1452,7 @@ GstPadProbeReturn FaceNvInferServerManager::sgie_pad_buffer_probe( final_face_obj->confidence = score_face; add_face_body(obj_meta->object_id, score_face); - // std::cout << "body_obj->object_id = " << - // body_obj->object_id - // << " score_face= "<object_id << std::endl; + } + + if (find_body == true) { + // if (current_full_frame_is_captured == false) { + // encode_full_frame_attach_meta(ctx, ip_surf, + // frame_meta); + // current_full_frame_is_captured = true; + // } encode_full_frame_attach_meta(ctx, ip_surf, frame_meta); - current_full_frame_is_captured = true; + + encode_objects_attach_meta(ctx, ip_surf, frame_meta, + final_face_obj); } - encode_objects_attach_meta(ctx, ip_surf, frame_meta, - obj_meta); - encode_objects_attach_meta(ctx, ip_surf, frame_meta, - final_face_obj); } nvds_add_obj_meta_to_frame(frame_meta, final_face_obj, obj_meta); @@ -1615,27 +1551,13 @@ GstPadProbeReturn FaceNvInferServerManager::sgie_pad_buffer_probe( // unsigned int numDims = layer.inferDims.numDims; // unsigned int numElements = layer.inferDims.numElements; - // std::cout << "Layer " << jkl << " (" << layer.layerName - // << - // "):\n"; std::cout << " Num Dims: " << numDims << "\n"; - // std::cout << " Num Elements: " << numElements << "\n"; - // std::cout << " Dims: ["; - // for (unsigned int mno = 0; mno < numDims; ++mno) { - // std::cout << layer.inferDims.d[mno]; - // if (mno < numDims - 1) - // std::cout << ", "; - // } - // std::cout << "]\n"; - // float *data_face = static_cast(layer.buffer); // } - // std::quick_exit(0); // const NvDsInferLayerInfo &layer = // outputLayersInfo[0]; // or loop over all - // std::cout<<"meta->num_output_layers: "<< - // meta->num_output_layers<num_output_layers; i++) { // NvDsInferLayerInfo *info = &meta->output_layers_info[i]; // info->buffer = meta->out_buf_ptrs_host[i]; @@ -1652,7 +1574,6 @@ GstPadProbeReturn FaceNvInferServerManager::sgie_pad_buffer_probe( getDimsCHWFromDims(dims_chw, meta->output_layers_info[0].inferDims); unsigned int numClasses = dims_chw.c; - // std::cout << "numClasses: " << numClasses << std::endl; (void)numClasses; // float *outputCoverageBuffer = // (float *) meta->output_layers_info[0].buffer; diff --git a/src/face_nv_infer_server_manager.hpp b/src/face_nv_infer_server_manager.hpp index cd3b32b..06ecb26 100644 --- a/src/face_nv_infer_server_manager.hpp +++ b/src/face_nv_infer_server_manager.hpp @@ -9,6 +9,8 @@ // #include "nvdsinfer_custom_impl.h" #include // for AVX intrinsics +#include + #include "config_manager.hpp" #include "custom_gstnvdsinfer.hpp" #include "nvdsmeta.h" @@ -72,4 +74,6 @@ class FaceNvInferServerManager { NvDsFrameMeta *); static void encode_objects_attach_meta(gpointer, NvBufSurface *, NvDsFrameMeta *, NvDsObjectMeta *); + static std::unordered_map collect_body_objects( + NvDsFrameMeta *, gint); }; \ No newline at end of file diff --git a/src/nv_osd_manager.cpp b/src/nv_osd_manager.cpp index 6c4c6c5..e04a3ec 100644 --- a/src/nv_osd_manager.cpp +++ b/src/nv_osd_manager.cpp @@ -63,8 +63,6 @@ void NvOsdManager::save_full_frame(NvDsFrameMeta *frame_meta) { int stream_num = 0; while (usrMetaList != NULL) { NvDsUserMeta *usrMetaData = (NvDsUserMeta *)usrMetaList->data; - // std::cout<<"usrMetaData->base_meta.meta_type frame = - // "<base_meta.meta_type<base_meta.meta_type == NVDS_CROP_IMAGE_META) { snprintf(fileFrameNameString, FILE_NAME_SIZE, "%s_frame_%d_%d.jpg", osd_string, frame_number, stream_num++); @@ -75,8 +73,6 @@ void NvOsdManager::save_full_frame(NvDsFrameMeta *frame_meta) { fwrite(enc_jpeg_image->outBuffer, sizeof(uint8_t), enc_jpeg_image->outLen, file); fclose(file); - // std::cout<<"fileFrameNameString = - // "<next; } @@ -86,21 +82,15 @@ void NvOsdManager::save_cropped_objects(NvDsFrameMeta *frame_meta, NvDsObjectMeta *obj_meta, guint num_rects) { const char *osd_string = "OSD"; - // std::cout<<"obj_meta->unique_component_id = - // "<unique_component_id<obj_user_meta_list; FILE *file; while (usrMetaList != NULL) { NvDsUserMeta *usrMetaData = (NvDsUserMeta *)usrMetaList->data; - // std::cout<<"usrMetaData->base_meta.meta_type object = - // "<base_meta.meta_type<base_meta.meta_type == NVDS_CROP_IMAGE_META) { NvDsObjEncOutParams *enc_jpeg_image = (NvDsObjEncOutParams *)usrMetaData->user_meta_data; @@ -113,9 +103,6 @@ void NvOsdManager::save_cropped_objects(NvDsFrameMeta *frame_meta, fwrite(enc_jpeg_image->outBuffer, sizeof(uint8_t), enc_jpeg_image->outLen, file); fclose(file); - std::cout << "fileObjNameString = " << fileObjNameString - << " obj_meta->class_id =" << obj_meta->class_id - << std::endl; usrMetaList = NULL; } else { usrMetaList = usrMetaList->next; @@ -153,14 +140,6 @@ GstPadProbeReturn NvOsdManager::osd_src_pad_buffer_probe(GstPad *pad, if (obj_meta->class_id == PGIE_CLASS_ID_PERSON) { person_count++; num_rects++; - // std::cout << "In OSD sink " - // << "x = " << obj_meta->rect_params.left - // << " y = " << obj_meta->rect_params.top - // << " w = " << obj_meta->rect_params.width - // << " h = " << obj_meta->rect_params.height - // << " score = " << obj_meta->confidence - // << " Object ID: " << obj_meta->object_id - // << std::endl; } if (write_cropped_objects_to_disk == true) save_cropped_objects(frame_meta, obj_meta, num_rects);