Fix segmentation fault by adjust precise face location
This commit is contained in:
parent
84836f6ec9
commit
b3fe017b21
@ -46,8 +46,6 @@ FaceNvInferServerManager::FaceNvInferServerManager() {
|
|||||||
config["inferserver_face_config_file"].get<std::string>();
|
config["inferserver_face_config_file"].get<std::string>();
|
||||||
FACE_NET_WIDTH = config["FACE_NET_WIDTH"];
|
FACE_NET_WIDTH = config["FACE_NET_WIDTH"];
|
||||||
FACE_NET_HEIGHT = config["FACE_NET_HEIGHT"];
|
FACE_NET_HEIGHT = config["FACE_NET_HEIGHT"];
|
||||||
// FACE_NET_WIDTH = config["PGIE_NET_WIDTH"];
|
|
||||||
// FACE_NET_HEIGHT = config["PGIE_NET_HEIGHT"];
|
|
||||||
MUXER_OUTPUT_WIDTH = config["MUXER_OUTPUT_WIDTH"];
|
MUXER_OUTPUT_WIDTH = config["MUXER_OUTPUT_WIDTH"];
|
||||||
MUXER_OUTPUT_HEIGHT = config["MUXER_OUTPUT_HEIGHT"];
|
MUXER_OUTPUT_HEIGHT = config["MUXER_OUTPUT_HEIGHT"];
|
||||||
threshold_face_detection = config["threshold_face_detection"];
|
threshold_face_detection = config["threshold_face_detection"];
|
||||||
@ -1434,6 +1432,8 @@ GstPadProbeReturn FaceNvInferServerManager::sgie_pad_buffer_probe(
|
|||||||
NvOSD_RectParams *updated_bbox = allign_postprocess(
|
NvOSD_RectParams *updated_bbox = allign_postprocess(
|
||||||
obj_meta->rect_params, face_location);
|
obj_meta->rect_params, face_location);
|
||||||
|
|
||||||
|
clamp_rect_params(frame_meta, updated_bbox);
|
||||||
|
|
||||||
NvDsObjectMeta *final_face_obj =
|
NvDsObjectMeta *final_face_obj =
|
||||||
nvds_acquire_obj_meta_from_pool(batch_meta);
|
nvds_acquire_obj_meta_from_pool(batch_meta);
|
||||||
|
|
||||||
@ -1670,4 +1670,48 @@ void FaceNvInferServerManager::release_user_meta(gpointer data,
|
|||||||
// }
|
// }
|
||||||
// // use_device_mem = 1 - use_device_mem;
|
// // use_device_mem = 1 - use_device_mem;
|
||||||
// return GST_PAD_PROBE_OK;
|
// return GST_PAD_PROBE_OK;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
void FaceNvInferServerManager::clamp_rect_params(
|
||||||
|
NvDsFrameMeta *frame_meta, NvOSD_RectParams *rect_params) {
|
||||||
|
guint frame_width = frame_meta->source_frame_width;
|
||||||
|
guint frame_height = frame_meta->source_frame_height;
|
||||||
|
|
||||||
|
// read values (DeepStream stores rect params as floats)
|
||||||
|
float left = rect_params->left;
|
||||||
|
float top = rect_params->top;
|
||||||
|
float width = rect_params->width;
|
||||||
|
float height = rect_params->height;
|
||||||
|
float right = left + width;
|
||||||
|
float bottom = top + height;
|
||||||
|
|
||||||
|
// CHECK for invalid numbers (NaN/inf) or out-of-bounds
|
||||||
|
bool invalid = false;
|
||||||
|
if (!std::isfinite(left) || !std::isfinite(top) || !std::isfinite(width) ||
|
||||||
|
!std::isfinite(height)) {
|
||||||
|
invalid = true;
|
||||||
|
} else if (width <= 0.0f || height <= 0.0f) {
|
||||||
|
invalid = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// clamp coordinates into frame (clip)
|
||||||
|
float clamped_left =
|
||||||
|
std::max(0.0f, std::min(left, (float)frame_width - 1.0f));
|
||||||
|
float clamped_top =
|
||||||
|
std::max(0.0f, std::min(top, (float)frame_height - 1.0f));
|
||||||
|
float clamped_right = abs(std::min(right, (float)frame_width - 1.0f));
|
||||||
|
float clamped_bottom = abs(std::min(bottom, (float)frame_height - 1.0f));
|
||||||
|
|
||||||
|
float clamped_w = clamped_right - clamped_left;
|
||||||
|
float clamped_h = clamped_bottom - clamped_top;
|
||||||
|
if (clamped_w <= 0.0f || clamped_h <= 0.0f) {
|
||||||
|
invalid = true;
|
||||||
|
}
|
||||||
|
(void)invalid;
|
||||||
|
|
||||||
|
rect_params->left = clamped_left;
|
||||||
|
rect_params->top = clamped_top;
|
||||||
|
rect_params->width = clamped_w;
|
||||||
|
rect_params->height = clamped_h;
|
||||||
|
return;
|
||||||
|
}
|
||||||
@ -76,4 +76,5 @@ class FaceNvInferServerManager {
|
|||||||
NvDsFrameMeta *, NvDsObjectMeta *);
|
NvDsFrameMeta *, NvDsObjectMeta *);
|
||||||
static std::unordered_map<guint, NvDsObjectMeta *> collect_body_objects(
|
static std::unordered_map<guint, NvDsObjectMeta *> collect_body_objects(
|
||||||
NvDsFrameMeta *, gint);
|
NvDsFrameMeta *, gint);
|
||||||
|
static void clamp_rect_params(NvDsFrameMeta *, NvOSD_RectParams *);
|
||||||
};
|
};
|
||||||
Loading…
x
Reference in New Issue
Block a user