Refactor fix segmentation fault by adjust object location
This commit is contained in:
parent
b3fe017b21
commit
264db065eb
@ -95,6 +95,7 @@ include_directories(${PROJECT_SOURCE_DIR}/face_nv_infer_server_manager.hpp)
|
||||
include_directories(${PROJECT_SOURCE_DIR}/nv_message_converter.hpp)
|
||||
include_directories(${PROJECT_SOURCE_DIR}/nv_message_broker.hpp)
|
||||
include_directories(${PROJECT_SOURCE_DIR}/tee_manager.hpp)
|
||||
include_directories(${PROJECT_SOURCE_DIR}/clamp_rectangle_parameters.hpp)
|
||||
|
||||
|
||||
set(SOURCES src/main.cpp src/camera_manager.cpp src/pipeline_manager.cpp src/streammux_manager.cpp
|
||||
@ -107,7 +108,8 @@ set(SOURCES src/main.cpp src/camera_manager.cpp src/pipeline_manager.cpp src/st
|
||||
src/nv_infer_server_manager.cpp src/nv_tracker_manager.cpp
|
||||
src/face_candid_trace.cpp
|
||||
src/face_nv_infer_server_manager.cpp src/face_nv_infer_server_manager.cpp
|
||||
src/nv_message_converter.cpp src/nv_message_broker.cpp src/tee_manager.cpp)
|
||||
src/nv_message_converter.cpp src/nv_message_broker.cpp src/tee_manager.cpp
|
||||
src/clamp_rectangle_parameters.cpp)
|
||||
|
||||
|
||||
# missing initializer for member 'NvDsInferDims::d' [-Werror=missing-field-initializers] NvDsInferDims dims = {0};
|
||||
|
||||
45
src/clamp_rectangle_parameters.cpp
Normal file
45
src/clamp_rectangle_parameters.cpp
Normal file
@ -0,0 +1,45 @@
|
||||
#include "clamp_rectangle_parameters.hpp"
|
||||
|
||||
void ClampRectangleParameters::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;
|
||||
}
|
||||
10
src/clamp_rectangle_parameters.hpp
Normal file
10
src/clamp_rectangle_parameters.hpp
Normal file
@ -0,0 +1,10 @@
|
||||
#include <cmath>
|
||||
#include <iostream>
|
||||
|
||||
#include "gstnvdsmeta.h"
|
||||
|
||||
class ClampRectangleParameters {
|
||||
private:
|
||||
public:
|
||||
static void clamp_rect_params(NvDsFrameMeta *, NvOSD_RectParams *);
|
||||
};
|
||||
@ -1,9 +1,10 @@
|
||||
#ifndef CUSTOM_GSTNVDSINFER_HPP
|
||||
#define CUSTOM_GSTNVDSINFER_HPP
|
||||
|
||||
#include "clamp_rectangle_parameters.hpp"
|
||||
#include "gstnvdsinfer.h"
|
||||
#include "nvbufsurface.h"
|
||||
#include "nvdsinfer_custom_impl.h"
|
||||
#include "nvds_obj_encode.h"
|
||||
#include "nvdsinfer_custom_impl.h"
|
||||
|
||||
#endif
|
||||
#endif
|
||||
@ -29,6 +29,7 @@ unsigned int FaceNvInferServerManager::nvds_lib_major_version =
|
||||
NVDS_VERSION_MAJOR;
|
||||
unsigned int FaceNvInferServerManager::nvds_lib_minor_version =
|
||||
NVDS_VERSION_MINOR;
|
||||
ClampRectangleParameters *FaceNvInferServerManager::clamp_rectangle_parameters;
|
||||
|
||||
const gchar pgie_class_str[PGIE_DETECTED_CLASS_NUM][32] = {"Person_SGIE"};
|
||||
const gchar sgie_class_str[SGIE_DETECTED_CLASS_NUM][32] = {"PreciseFace_SGIE"};
|
||||
@ -1432,7 +1433,8 @@ GstPadProbeReturn FaceNvInferServerManager::sgie_pad_buffer_probe(
|
||||
NvOSD_RectParams *updated_bbox = allign_postprocess(
|
||||
obj_meta->rect_params, face_location);
|
||||
|
||||
clamp_rect_params(frame_meta, updated_bbox);
|
||||
clamp_rectangle_parameters->clamp_rect_params(frame_meta,
|
||||
updated_bbox);
|
||||
|
||||
NvDsObjectMeta *final_face_obj =
|
||||
nvds_acquire_obj_meta_from_pool(batch_meta);
|
||||
@ -1670,48 +1672,4 @@ void FaceNvInferServerManager::release_user_meta(gpointer data,
|
||||
// }
|
||||
// // use_device_mem = 1 - use_device_mem;
|
||||
// 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;
|
||||
}
|
||||
// }
|
||||
@ -18,6 +18,8 @@
|
||||
|
||||
class FaceNvInferServerManager {
|
||||
private:
|
||||
static ClampRectangleParameters *clamp_rectangle_parameters;
|
||||
|
||||
public:
|
||||
struct FACE_BODY {
|
||||
int object_id = 0;
|
||||
@ -76,5 +78,4 @@ class FaceNvInferServerManager {
|
||||
NvDsFrameMeta *, NvDsObjectMeta *);
|
||||
static std::unordered_map<guint, NvDsObjectMeta *> collect_body_objects(
|
||||
NvDsFrameMeta *, gint);
|
||||
static void clamp_rect_params(NvDsFrameMeta *, NvOSD_RectParams *);
|
||||
};
|
||||
@ -23,6 +23,7 @@ guint NvInferServerManager::use_device_mem = 0;
|
||||
float NvInferServerManager::threshold_body_detection = 0;
|
||||
unsigned int NvInferServerManager::nvds_lib_major_version = NVDS_VERSION_MAJOR;
|
||||
unsigned int NvInferServerManager::nvds_lib_minor_version = NVDS_VERSION_MINOR;
|
||||
ClampRectangleParameters *NvInferServerManager::clamp_rectangle_parameters;
|
||||
|
||||
const gchar pgie_class_str[PGIE_DETECTED_CLASS_NUM][32] = {"Person_NVINFER"};
|
||||
const gchar imprecise_face_str[PGIE_DETECTED_CLASS_NUM][32] = {
|
||||
@ -461,7 +462,8 @@ void NvInferServerManager::update_frame_with_face_body_meta(
|
||||
((left_down_shoulder.y - data[index * BODY_TENSOR_SIZE + 1]) *
|
||||
MUXER_OUTPUT_HEIGHT / PGIE_NET_HEIGHT);
|
||||
|
||||
clamp_rect_params(frame_meta, &rect_params_imprecise_face, "FACE");
|
||||
clamp_rectangle_parameters->clamp_rect_params(
|
||||
frame_meta, &rect_params_imprecise_face);
|
||||
|
||||
/* Border of width 3. */
|
||||
rect_params_imprecise_face.border_width = 3;
|
||||
@ -528,7 +530,8 @@ void NvInferServerManager::update_frame_with_face_body_meta(
|
||||
data[index * BODY_TENSOR_SIZE + 1]) *
|
||||
MUXER_OUTPUT_HEIGHT / PGIE_NET_HEIGHT);
|
||||
|
||||
clamp_rect_params(frame_meta, &rect_params_body, "BODY");
|
||||
clamp_rectangle_parameters->clamp_rect_params(frame_meta,
|
||||
&rect_params_body);
|
||||
|
||||
/* Border of width 3. */
|
||||
rect_params_body.border_width = 3;
|
||||
@ -567,52 +570,6 @@ void NvInferServerManager::update_frame_with_face_body_meta(
|
||||
}
|
||||
}
|
||||
|
||||
void NvInferServerManager::clamp_rect_params(NvDsFrameMeta *frame_meta,
|
||||
NvOSD_RectParams *rect_params,
|
||||
std::string type) {
|
||||
(void)type;
|
||||
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;
|
||||
}
|
||||
|
||||
NvInferServerManager::Point2D
|
||||
NvInferServerManager::find_left_down_corner_shoulder(float *data, uint index) {
|
||||
Point2D left_down_shoulder;
|
||||
|
||||
@ -8,13 +8,15 @@
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
|
||||
#include "gstnvdsmeta.h"
|
||||
#include "custom_gstnvdsinfer.hpp"
|
||||
#include "gstnvdsmeta.h"
|
||||
#include "nvds_version.h"
|
||||
#include "nvdsinfer_custom_impl.h"
|
||||
|
||||
class NvInferServerManager {
|
||||
private:
|
||||
static ClampRectangleParameters *clamp_rectangle_parameters;
|
||||
|
||||
public:
|
||||
struct Point2D {
|
||||
double x; // X coordinate
|
||||
@ -56,6 +58,4 @@ class NvInferServerManager {
|
||||
static uint extract_tensor_metadata(NvDsUserMeta *, NvDsInferNetworkInfo,
|
||||
NvDsBatchMeta *, NvDsFrameMeta *);
|
||||
static Point2D find_left_down_corner_shoulder(float *, uint);
|
||||
static void clamp_rect_params(NvDsFrameMeta *, NvOSD_RectParams *,
|
||||
std::string);
|
||||
};
|
||||
@ -21,6 +21,7 @@ unsigned int NvTrackerManager::MUXER_OUTPUT_HEIGHT = 1;
|
||||
std::vector<NvTrackerManager::FaceBody> NvTrackerManager::body_face_list;
|
||||
FaceCandidTraceManager *NvTrackerManager::face_candidate_trace_manager =
|
||||
new FaceCandidTraceManager();
|
||||
ClampRectangleParameters *NvTrackerManager::clamp_rectangle_parameters;
|
||||
|
||||
gint NvTrackerManager::frame_number = 0;
|
||||
const gchar face_class_str[FACE_DETECTED_CLASS_NUM][32] = {
|
||||
@ -321,7 +322,8 @@ GstPadProbeReturn NvTrackerManager::tracker_src_pad_buffer_probe(
|
||||
face_rect_params->width = x2 - x1;
|
||||
face_rect_params->height = y2 - y1;
|
||||
|
||||
clamp_rect_params(frame_meta, face_rect_params);
|
||||
clamp_rectangle_parameters->clamp_rect_params(
|
||||
frame_meta, face_rect_params);
|
||||
|
||||
NvDsObjectMeta *face_obj =
|
||||
nvds_acquire_obj_meta_from_pool(batch_meta);
|
||||
@ -550,49 +552,4 @@ GstPadProbeReturn NvTrackerManager::tracker_src_pad_buffer_probe(
|
||||
|
||||
frame_number++;
|
||||
return GST_PAD_PROBE_OK;
|
||||
}
|
||||
|
||||
void NvTrackerManager::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;
|
||||
}
|
||||
|
||||
}
|
||||
@ -9,6 +9,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include "config_manager.hpp"
|
||||
#include "custom_gstnvdsinfer.hpp"
|
||||
#include "face_candid_trace.hpp"
|
||||
#include "gstnvdsmeta.h"
|
||||
#include "nvdsmeta.h"
|
||||
@ -16,6 +17,7 @@
|
||||
|
||||
class NvTrackerManager {
|
||||
private:
|
||||
static ClampRectangleParameters *clamp_rectangle_parameters;
|
||||
struct FaceBody {
|
||||
int object_id = 0;
|
||||
int source_id = 0;
|
||||
@ -57,5 +59,4 @@ class NvTrackerManager {
|
||||
static std::optional<
|
||||
std::tuple<std::tuple<float, float, float, float>, float>>
|
||||
face_box_extract(float *);
|
||||
static void clamp_rect_params(NvDsFrameMeta *, NvOSD_RectParams *);
|
||||
};
|
||||
Loading…
x
Reference in New Issue
Block a user