Refine shoe selection and color debug workflow
This commit is contained in:
parent
767ad97803
commit
346db28cee
531
configs/full_pipeline_1080p_test_alarm.json
Normal file
531
configs/full_pipeline_1080p_test_alarm.json
Normal file
@ -0,0 +1,531 @@
|
||||
{
|
||||
"queue": {
|
||||
"size": 8,
|
||||
"strategy": "drop_oldest"
|
||||
},
|
||||
"graphs": [
|
||||
{
|
||||
"name": "cam1_full_pipeline",
|
||||
"executor": {
|
||||
"batch_size": 2,
|
||||
"run_budget": 8
|
||||
},
|
||||
"nodes": [
|
||||
{
|
||||
"id": "in_cam1",
|
||||
"type": "input_rtsp",
|
||||
"role": "source",
|
||||
"enable": true,
|
||||
"url": "rtsp://10.0.0.49:8554/cam",
|
||||
"fps": 30,
|
||||
"width": 1920,
|
||||
"height": 1080,
|
||||
"use_ffmpeg": true,
|
||||
"use_mpp": false,
|
||||
"force_tcp": true,
|
||||
"reconnect_sec": 5,
|
||||
"reconnect_backoff_max_sec": 30
|
||||
},
|
||||
{
|
||||
"id": "pre_rgb",
|
||||
"type": "preprocess",
|
||||
"role": "filter",
|
||||
"enable": true,
|
||||
"cpu_affinity": [
|
||||
2
|
||||
],
|
||||
"dst_w": 1920,
|
||||
"dst_h": 1080,
|
||||
"dst_format": "rgb",
|
||||
"dst_packed": true,
|
||||
"resize_mode": "stretch",
|
||||
"keep_ratio": false,
|
||||
"rga_gate": "full_pipeline_1080p",
|
||||
"use_rga": true
|
||||
},
|
||||
{
|
||||
"id": "face_det",
|
||||
"type": "ai_scrfd_sliding",
|
||||
"role": "filter",
|
||||
"enable": true,
|
||||
"cpu_affinity": [
|
||||
4
|
||||
],
|
||||
"infer_fps": 3,
|
||||
"model_path": "./models/scrfd_500m_640.rknn",
|
||||
"model_w": 640,
|
||||
"model_h": 640,
|
||||
"windows": [
|
||||
{
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"w": 960,
|
||||
"h": 1080
|
||||
},
|
||||
{
|
||||
"x": 960,
|
||||
"y": 0,
|
||||
"w": 960,
|
||||
"h": 1080
|
||||
}
|
||||
],
|
||||
"conf_thresh": 0.5,
|
||||
"nms_thresh": 0.4,
|
||||
"max_faces": 50,
|
||||
"debug": {
|
||||
"stats": true,
|
||||
"stats_interval": 30
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "face_recog",
|
||||
"type": "ai_face_recog",
|
||||
"role": "filter",
|
||||
"enable": true,
|
||||
"cpu_affinity": [
|
||||
4
|
||||
],
|
||||
"infer_fps": 2,
|
||||
"infer_phase_ms": 120,
|
||||
"model_path": "./models/mobilefacenet_arcface.rknn",
|
||||
"align": true,
|
||||
"emit_embedding": false,
|
||||
"max_faces": 50,
|
||||
"input_format": "rgb",
|
||||
"input_dtype": "uint8",
|
||||
"threshold": {
|
||||
"accept": 0.45,
|
||||
"margin": 0.05
|
||||
},
|
||||
"gallery": {
|
||||
"backend": "sqlite",
|
||||
"path": "./models/face_gallery.db",
|
||||
"load_on_start": true,
|
||||
"expected_dim": 512,
|
||||
"dtype": "auto"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "person_det",
|
||||
"type": "ai_yolo",
|
||||
"role": "filter",
|
||||
"enable": true,
|
||||
"cpu_affinity": [
|
||||
5
|
||||
],
|
||||
"use_rga": true,
|
||||
"rga_gate": "full_pipeline_1080p",
|
||||
"rga_max_inflight": 4,
|
||||
"dst_packed": true,
|
||||
"use_dma_input": true,
|
||||
"infer_fps": 2,
|
||||
"infer_phase_ms": 0,
|
||||
"model_path": "./models/yolov8n-640.rknn",
|
||||
"model_version": "v8",
|
||||
"model_w": 640,
|
||||
"model_h": 640,
|
||||
"num_classes": 80,
|
||||
"conf": 0.35,
|
||||
"nms": 0.45,
|
||||
"class_filter": [
|
||||
0
|
||||
],
|
||||
"bbox_expand": {
|
||||
"enable": true,
|
||||
"class_id": 0,
|
||||
"left": 0.06,
|
||||
"right": 0.06,
|
||||
"top": 0.04,
|
||||
"bottom": 0.16
|
||||
},
|
||||
"debug": {
|
||||
"stats": true,
|
||||
"stats_interval": 30,
|
||||
"detections": false
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "person_trk",
|
||||
"type": "tracker",
|
||||
"role": "filter",
|
||||
"enable": true,
|
||||
"cpu_affinity": [
|
||||
5
|
||||
],
|
||||
"mode": "bytetrack_lite",
|
||||
"per_class": true,
|
||||
"state_key": "full_pipeline_1080p_workshoe",
|
||||
"track_classes": [
|
||||
0
|
||||
],
|
||||
"ignore_classes": [],
|
||||
"high_th": 0.55,
|
||||
"low_th": 0.1,
|
||||
"iou_th": 0.3,
|
||||
"max_age_ms": 900,
|
||||
"min_hits": 1,
|
||||
"max_tracks": 128
|
||||
},
|
||||
{
|
||||
"id": "shoe_det",
|
||||
"type": "ai_shoe_det",
|
||||
"role": "filter",
|
||||
"enable": true,
|
||||
"cpu_affinity": [
|
||||
6
|
||||
],
|
||||
"use_rga": true,
|
||||
"rga_gate": "full_pipeline_1080p",
|
||||
"rga_max_inflight": 4,
|
||||
"dst_packed": true,
|
||||
"use_dma_input": false,
|
||||
"infer_fps": 2,
|
||||
"infer_phase_ms": 150,
|
||||
"model_path": "./models/yolov8s_shoe_640-rk3588.rknn",
|
||||
"model_w": 640,
|
||||
"model_h": 640,
|
||||
"conf": 0.22,
|
||||
"nms": 0.45,
|
||||
"v8_box_format": "cxcywh",
|
||||
"append_detections": true,
|
||||
"dynamic_roi": {
|
||||
"enable": true,
|
||||
"person_class_id": 0,
|
||||
"shoe_class_id": 1,
|
||||
"debug_roi_class_id": -1,
|
||||
"max_rois": 3,
|
||||
"min_person_height": 60,
|
||||
"max_box_area_ratio": 0.6,
|
||||
"x_offset": -0.24,
|
||||
"y_offset": 0.64,
|
||||
"width_scale": 1.48,
|
||||
"height_scale": 0.58
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "shoe_assoc",
|
||||
"type": "logic_gate",
|
||||
"role": "filter",
|
||||
"enable": true,
|
||||
"cpu_affinity": [
|
||||
6
|
||||
],
|
||||
"mode": "person_shoe_check",
|
||||
"debug": true,
|
||||
"person_shoe_check": {
|
||||
"person_class": 0,
|
||||
"shoe_class": 1,
|
||||
"violation_class": 2,
|
||||
"min_person_score": 0.3,
|
||||
"min_shoe_score": 0.22,
|
||||
"require_person_track_id": true,
|
||||
"attach_person_track_to_shoe": true,
|
||||
"emit_missing_violation": false,
|
||||
"foot_region": {
|
||||
"x_offset": -0.24,
|
||||
"y_offset": 0.64,
|
||||
"width_scale": 1.48,
|
||||
"height_scale": 0.58
|
||||
},
|
||||
"enable_size_preferred": true,
|
||||
"max_shoe_height_ratio": 0.28,
|
||||
"max_shoe_width_ratio": 0.6,
|
||||
"max_shoe_area_ratio": 0.15
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "shoe_color",
|
||||
"type": "logic_gate",
|
||||
"role": "filter",
|
||||
"enable": true,
|
||||
"cpu_affinity": [
|
||||
6
|
||||
],
|
||||
"mode": "ppe_boots_check",
|
||||
"anchor_class": 0,
|
||||
"boots_class": 1,
|
||||
"violation_class": 2,
|
||||
"debug": true,
|
||||
"color_check": {
|
||||
"enable": true,
|
||||
"method": "brightness",
|
||||
"dark_threshold": 90,
|
||||
"roi_expand": 1.0,
|
||||
"enable_size_filter": true,
|
||||
"max_shoe_height_ratio": 0.28,
|
||||
"max_shoe_width_ratio": 0.6,
|
||||
"max_shoe_area_ratio": 0.15
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "pre_osd",
|
||||
"type": "preprocess",
|
||||
"role": "filter",
|
||||
"enable": true,
|
||||
"cpu_affinity": [
|
||||
7
|
||||
],
|
||||
"dst_w": 1920,
|
||||
"dst_h": 1080,
|
||||
"dst_format": "nv12",
|
||||
"resize_mode": "stretch",
|
||||
"rga_gate": "full_pipeline_1080p",
|
||||
"use_rga": true
|
||||
},
|
||||
{
|
||||
"id": "osd",
|
||||
"type": "osd",
|
||||
"role": "filter",
|
||||
"enable": true,
|
||||
"cpu_affinity": [
|
||||
7
|
||||
],
|
||||
"draw_bbox": true,
|
||||
"draw_text": true,
|
||||
"draw_face_det": false,
|
||||
"draw_face_recog": true,
|
||||
"draw_face_bbox": true,
|
||||
"line_width": 2.0,
|
||||
"font_scale": 1.0,
|
||||
"use_rga_bbox": false,
|
||||
"labels": [
|
||||
"person",
|
||||
"shoe",
|
||||
"non_black_shoe"
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "publish",
|
||||
"type": "publish",
|
||||
"role": "filter",
|
||||
"enable": true,
|
||||
"cpu_affinity": [
|
||||
3
|
||||
],
|
||||
"queue": {
|
||||
"size": 2,
|
||||
"policy": "drop_oldest"
|
||||
},
|
||||
"codec": "h264",
|
||||
"fps": 30,
|
||||
"gop": 60,
|
||||
"bitrate_kbps": 4000,
|
||||
"mpp_output_timeout_ms": 50,
|
||||
"mpp_packet_wait_ms": 10,
|
||||
"use_mpp": true,
|
||||
"use_ffmpeg_mux": true,
|
||||
"outputs": [
|
||||
{
|
||||
"proto": "hls",
|
||||
"path": "./web/hls/cam1/index.m3u8",
|
||||
"segment_sec": 2
|
||||
},
|
||||
{
|
||||
"proto": "rtsp_server",
|
||||
"port": 8555,
|
||||
"path": "/live/cam1"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "alarm",
|
||||
"type": "alarm",
|
||||
"role": "sink",
|
||||
"enable": true,
|
||||
"eval_fps": 2,
|
||||
"labels": [
|
||||
"person",
|
||||
"shoe",
|
||||
"non_black_shoe"
|
||||
],
|
||||
"rules": [
|
||||
{
|
||||
"name": "non_compliant_workshoe",
|
||||
"class_ids": [
|
||||
2
|
||||
],
|
||||
"roi": {
|
||||
"x": 0.0,
|
||||
"y": 0.0,
|
||||
"w": 1.0,
|
||||
"h": 1.0
|
||||
},
|
||||
"min_score": 0.1,
|
||||
"min_box_area_ratio": 0.0,
|
||||
"require_track_id": false,
|
||||
"min_duration_ms": 0,
|
||||
"min_hits": 1,
|
||||
"hit_window_ms": 3000,
|
||||
"cooldown_ms": 1000,
|
||||
"per_track_cooldown_ms": 0
|
||||
}
|
||||
],
|
||||
"face_rules": [
|
||||
{
|
||||
"name": "unknown_face",
|
||||
"type": "unknown",
|
||||
"cooldown_ms": 7000,
|
||||
"min_sim": 0.35,
|
||||
"min_hits": 1,
|
||||
"hit_window_ms": 1500,
|
||||
"min_face_area_ratio": 0.01,
|
||||
"min_face_aspect": 0.6,
|
||||
"max_face_aspect": 1.6
|
||||
},
|
||||
{
|
||||
"name": "known_person",
|
||||
"type": "person",
|
||||
"cooldown_ms": 7000,
|
||||
"min_sim": 0.6,
|
||||
"min_hits": 1,
|
||||
"hit_window_ms": 1500,
|
||||
"min_face_area_ratio": 0.01,
|
||||
"min_face_aspect": 0.6,
|
||||
"max_face_aspect": 1.6
|
||||
}
|
||||
],
|
||||
"actions": {
|
||||
"log": {
|
||||
"enable": true,
|
||||
"level": "info",
|
||||
"include_detections": true,
|
||||
"min_interval_ms": 2000
|
||||
},
|
||||
"snapshot": {
|
||||
"enable": true,
|
||||
"format": "jpg",
|
||||
"quality": 85,
|
||||
"upload": {
|
||||
"type": "minio",
|
||||
"endpoint": "http://10.0.0.49:9000",
|
||||
"bucket": "myminio",
|
||||
"region": "us-east-1",
|
||||
"access_key": "admin",
|
||||
"secret_key": "password"
|
||||
}
|
||||
},
|
||||
"clip": {
|
||||
"enable": true,
|
||||
"pre_sec": 5,
|
||||
"post_sec": 10,
|
||||
"format": "mp4",
|
||||
"fps": 30,
|
||||
"upload": {
|
||||
"type": "minio",
|
||||
"endpoint": "http://10.0.0.49:9000",
|
||||
"bucket": "myminio",
|
||||
"region": "us-east-1",
|
||||
"access_key": "admin",
|
||||
"secret_key": "password"
|
||||
}
|
||||
},
|
||||
"external_api": {
|
||||
"enable": true,
|
||||
"getTokenUrl": "http://10.0.0.49:8080/api/getToken",
|
||||
"putMessageUrl": "http://10.0.0.49:8080/api/putMessage",
|
||||
"tenantCode": "32",
|
||||
"channelNo": "cam1",
|
||||
"timeout_ms": 3000,
|
||||
"include_media_url": true,
|
||||
"token_header": "X-Access-Token",
|
||||
"token_json_path": "responseBody.token",
|
||||
"token_cache_sec": 1200
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"edges": [
|
||||
[
|
||||
"in_cam1",
|
||||
"pre_rgb"
|
||||
],
|
||||
[
|
||||
"pre_rgb",
|
||||
"face_det"
|
||||
],
|
||||
[
|
||||
"face_det",
|
||||
"face_recog"
|
||||
],
|
||||
[
|
||||
"face_recog",
|
||||
"person_det"
|
||||
],
|
||||
[
|
||||
"person_det",
|
||||
"person_trk"
|
||||
],
|
||||
[
|
||||
"person_trk",
|
||||
"shoe_det",
|
||||
{
|
||||
"queue": {
|
||||
"size": 16,
|
||||
"strategy": "drop_oldest"
|
||||
}
|
||||
}
|
||||
],
|
||||
[
|
||||
"shoe_det",
|
||||
"shoe_assoc",
|
||||
{
|
||||
"queue": {
|
||||
"size": 16,
|
||||
"strategy": "drop_oldest"
|
||||
}
|
||||
}
|
||||
],
|
||||
[
|
||||
"shoe_assoc",
|
||||
"shoe_color",
|
||||
{
|
||||
"queue": {
|
||||
"size": 16,
|
||||
"strategy": "drop_oldest"
|
||||
}
|
||||
}
|
||||
],
|
||||
[
|
||||
"shoe_color",
|
||||
"osd",
|
||||
{
|
||||
"queue": {
|
||||
"size": 16,
|
||||
"strategy": "drop_oldest"
|
||||
}
|
||||
}
|
||||
],
|
||||
[
|
||||
"osd",
|
||||
"pre_osd",
|
||||
{
|
||||
"queue": {
|
||||
"size": 32,
|
||||
"strategy": "drop_oldest"
|
||||
}
|
||||
}
|
||||
],
|
||||
[
|
||||
"pre_osd",
|
||||
"publish",
|
||||
{
|
||||
"queue": {
|
||||
"size": 64,
|
||||
"strategy": "drop_oldest"
|
||||
}
|
||||
}
|
||||
],
|
||||
[
|
||||
"publish",
|
||||
"alarm",
|
||||
{
|
||||
"queue": {
|
||||
"size": 64,
|
||||
"strategy": "drop_oldest"
|
||||
}
|
||||
}
|
||||
]
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@ -32,12 +32,26 @@ ColorResult ColorAnalyzer::Analyze(const Frame& frame, const Rect& bbox) {
|
||||
" h=" + std::to_string(frame.height));
|
||||
return result;
|
||||
}
|
||||
|
||||
const float center_w_scale = std::clamp(config_.center_w_scale, 0.1f, 1.0f);
|
||||
const float center_h_scale = std::clamp(config_.center_h_scale, 0.1f, 1.0f);
|
||||
const int inner_w = std::max(1, static_cast<int>(crop_w * center_w_scale));
|
||||
const int inner_h = std::max(1, static_cast<int>(crop_h * center_h_scale));
|
||||
const int inner_x = std::max(0, (crop_w - inner_w) / 2);
|
||||
const int inner_y = std::max(0, (crop_h - inner_h) / 2);
|
||||
|
||||
std::vector<uint8_t> center(inner_w * inner_h * 3);
|
||||
for (int row = 0; row < inner_h; ++row) {
|
||||
const uint8_t* src_row = cropped.data() + ((inner_y + row) * crop_w + inner_x) * 3;
|
||||
uint8_t* dst_row = center.data() + row * inner_w * 3;
|
||||
std::memcpy(dst_row, src_row, inner_w * 3);
|
||||
}
|
||||
|
||||
// 保存调试图像(用于检查裁剪区域)
|
||||
if (config_.debug_output) {
|
||||
static int save_count = 0;
|
||||
if (save_count++ % 30 == 0) { // 每30帧保存一次
|
||||
SaveDebugImage(cropped.data(), crop_w, crop_h, "/tmp/boot_debug_" + std::to_string(save_count) + ".ppm");
|
||||
SaveDebugImage(center.data(), inner_w, inner_h, "/tmp/boot_debug_" + std::to_string(save_count) + ".ppm");
|
||||
LogInfo("[ColorAnalyzer] Saved debug image: /tmp/boot_debug_" + std::to_string(save_count) + ".ppm");
|
||||
}
|
||||
}
|
||||
@ -45,16 +59,16 @@ ColorResult ColorAnalyzer::Analyze(const Frame& frame, const Rect& bbox) {
|
||||
// 根据方法进行分析
|
||||
switch (config_.method) {
|
||||
case ColorMethod::HSV:
|
||||
result = AnalyzeHSV(cropped.data(), crop_w, crop_h, 3);
|
||||
result = AnalyzeHSV(center.data(), inner_w, inner_h, 3);
|
||||
break;
|
||||
case ColorMethod::RGB:
|
||||
result = AnalyzeRGB(cropped.data(), crop_w, crop_h, 3);
|
||||
result = AnalyzeRGB(center.data(), inner_w, inner_h, 3);
|
||||
break;
|
||||
case ColorMethod::BRIGHTNESS:
|
||||
result = AnalyzeBrightness(cropped.data(), crop_w, crop_h, 3);
|
||||
result = AnalyzeBrightness(center.data(), inner_w, inner_h, 3);
|
||||
break;
|
||||
default:
|
||||
result = AnalyzeHSV(cropped.data(), crop_w, crop_h, 3);
|
||||
result = AnalyzeHSV(center.data(), inner_w, inner_h, 3);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -68,7 +82,9 @@ ColorResult ColorAnalyzer::Analyze(const Frame& frame, const Rect& bbox) {
|
||||
" region=" + std::to_string(static_cast<int>(expanded.x)) + "," +
|
||||
std::to_string(static_cast<int>(expanded.y)) + "," +
|
||||
std::to_string(static_cast<int>(expanded.w)) + "x" +
|
||||
std::to_string(static_cast<int>(expanded.h)));
|
||||
std::to_string(static_cast<int>(expanded.h)) +
|
||||
" center=" + std::to_string(inner_x) + "," + std::to_string(inner_y) + "," +
|
||||
std::to_string(inner_w) + "x" + std::to_string(inner_h));
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
@ -17,6 +17,8 @@ struct ColorConfig {
|
||||
ColorMethod method = ColorMethod::HSV;
|
||||
int dark_threshold = 80; // 深色阈值(亮度0-255)
|
||||
float roi_expand = 1.0f; // ROI扩大系数
|
||||
float center_w_scale = 0.6f; // 中心区域宽度比例
|
||||
float center_h_scale = 0.6f; // 中心区域高度比例
|
||||
bool debug_output = false; // 是否输出调试信息
|
||||
};
|
||||
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
#include <cmath>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include "color_analyzer.h"
|
||||
@ -22,6 +23,10 @@ struct PersonShoeCheckConfig {
|
||||
bool use_person_bbox_for_violation = true;
|
||||
bool attach_person_track_to_shoe = true;
|
||||
bool emit_missing_violation = true;
|
||||
bool enable_size_preferred = false;
|
||||
float max_shoe_height_ratio = 0.28f;
|
||||
float max_shoe_width_ratio = 0.60f;
|
||||
float max_shoe_area_ratio = 0.15f;
|
||||
float match_iou = 0.02f;
|
||||
float x_offset = -0.20f;
|
||||
float y_offset = 0.64f;
|
||||
@ -35,6 +40,10 @@ struct LogicGateConfig {
|
||||
int boots_class = 3;
|
||||
int violation_class = 10;
|
||||
bool enable_color_check = true;
|
||||
bool enable_size_filter = false;
|
||||
float max_shoe_height_ratio = 1.0f / 6.0f;
|
||||
float max_shoe_width_ratio = 1.0f;
|
||||
float max_shoe_area_ratio = 0.15f;
|
||||
bool pass_through = true;
|
||||
bool debug = false;
|
||||
std::string violation_key = "ppe_violation";
|
||||
@ -133,6 +142,12 @@ private:
|
||||
else if (method == "brightness") config.color.method = ColorMethod::BRIGHTNESS;
|
||||
config.color.dark_threshold = color->ValueOr<int>("dark_threshold", 80);
|
||||
config.color.roi_expand = color->ValueOr<float>("roi_expand", 1.0f);
|
||||
config.color.center_w_scale = color->ValueOr<float>("center_w_scale", 0.6f);
|
||||
config.color.center_h_scale = color->ValueOr<float>("center_h_scale", 0.6f);
|
||||
config.enable_size_filter = color->ValueOr<bool>("enable_size_filter", false);
|
||||
config.max_shoe_height_ratio = color->ValueOr<float>("max_shoe_height_ratio", config.max_shoe_height_ratio);
|
||||
config.max_shoe_width_ratio = color->ValueOr<float>("max_shoe_width_ratio", config.max_shoe_width_ratio);
|
||||
config.max_shoe_area_ratio = color->ValueOr<float>("max_shoe_area_ratio", config.max_shoe_area_ratio);
|
||||
config.color.debug_output = config.debug;
|
||||
}
|
||||
|
||||
@ -150,6 +165,14 @@ private:
|
||||
config.person_shoe.emit_missing_violation = ps->ValueOr<bool>(
|
||||
"emit_missing_violation", config.person_shoe.emit_missing_violation);
|
||||
config.person_shoe.match_iou = ps->ValueOr<float>("match_iou", config.person_shoe.match_iou);
|
||||
config.person_shoe.enable_size_preferred = ps->ValueOr<bool>(
|
||||
"enable_size_preferred", config.person_shoe.enable_size_preferred);
|
||||
config.person_shoe.max_shoe_height_ratio = ps->ValueOr<float>(
|
||||
"max_shoe_height_ratio", config.person_shoe.max_shoe_height_ratio);
|
||||
config.person_shoe.max_shoe_width_ratio = ps->ValueOr<float>(
|
||||
"max_shoe_width_ratio", config.person_shoe.max_shoe_width_ratio);
|
||||
config.person_shoe.max_shoe_area_ratio = ps->ValueOr<float>(
|
||||
"max_shoe_area_ratio", config.person_shoe.max_shoe_area_ratio);
|
||||
if (const SimpleJson* fr = ps->Find("foot_region"); fr && fr->IsObject()) {
|
||||
config.person_shoe.x_offset = fr->ValueOr<float>("x_offset", config.person_shoe.x_offset);
|
||||
config.person_shoe.y_offset = fr->ValueOr<float>("y_offset", config.person_shoe.y_offset);
|
||||
@ -222,8 +245,25 @@ private:
|
||||
if (config_.person_shoe.require_person_track_id && person.track_id < 0) continue;
|
||||
|
||||
const Rect foot_region = BuildFootRegion(person.bbox, img_w, img_h);
|
||||
if (config_.debug) {
|
||||
LogInfo("[logic_gate] person track_id=" + std::to_string(person.track_id) +
|
||||
" bbox=(" + std::to_string(static_cast<int>(person.bbox.x)) + "," +
|
||||
std::to_string(static_cast<int>(person.bbox.y)) + "," +
|
||||
std::to_string(static_cast<int>(person.bbox.w)) + "," +
|
||||
std::to_string(static_cast<int>(person.bbox.h)) + ")" +
|
||||
" foot_region=(" + std::to_string(static_cast<int>(foot_region.x)) + "," +
|
||||
std::to_string(static_cast<int>(foot_region.y)) + "," +
|
||||
std::to_string(static_cast<int>(foot_region.w)) + "," +
|
||||
std::to_string(static_cast<int>(foot_region.h)) + ")");
|
||||
}
|
||||
int best_shoe_local = -1;
|
||||
float best_match_score = 0.0f;
|
||||
float best_width_ratio = 0.0f;
|
||||
float best_height_ratio = 0.0f;
|
||||
float best_area_ratio = 0.0f;
|
||||
bool best_size_preferred = false;
|
||||
bool best_center_inside = false;
|
||||
int candidate_count = 0;
|
||||
|
||||
for (size_t si = 0; si < shoe_indices.size(); ++si) {
|
||||
if (shoe_used[si]) continue;
|
||||
@ -232,18 +272,73 @@ private:
|
||||
|
||||
const float iou = IoU(foot_region, shoe.bbox);
|
||||
const bool center_inside = CenterInside(foot_region, shoe.bbox);
|
||||
if (!center_inside && iou < config_.person_shoe.match_iou) continue;
|
||||
const bool pass_gate = center_inside || iou >= config_.person_shoe.match_iou;
|
||||
const float person_area = std::max(1.0f, person.bbox.w * person.bbox.h);
|
||||
const float width_ratio = shoe.bbox.w / std::max(1.0f, person.bbox.w);
|
||||
const float height_ratio = shoe.bbox.h / std::max(1.0f, person.bbox.h);
|
||||
const float area_ratio = (shoe.bbox.w * shoe.bbox.h) / person_area;
|
||||
const bool size_preferred = !config_.person_shoe.enable_size_preferred ||
|
||||
(width_ratio <= config_.person_shoe.max_shoe_width_ratio &&
|
||||
height_ratio <= config_.person_shoe.max_shoe_height_ratio &&
|
||||
area_ratio <= config_.person_shoe.max_shoe_area_ratio);
|
||||
const float match_score = shoe.score * 10.0f + (center_inside ? 1.0f : 0.0f) + iou;
|
||||
if (config_.debug) {
|
||||
LogInfo("[logic_gate] shoe candidate person_track=" + std::to_string(person.track_id) +
|
||||
" local_idx=" + std::to_string(static_cast<int>(si)) +
|
||||
" det_idx=" + std::to_string(static_cast<int>(shoe_indices[si])) +
|
||||
" used=" + std::string(shoe_used[si] ? "true" : "false") +
|
||||
" bbox=(" + std::to_string(static_cast<int>(shoe.bbox.x)) + "," +
|
||||
std::to_string(static_cast<int>(shoe.bbox.y)) + "," +
|
||||
std::to_string(static_cast<int>(shoe.bbox.w)) + "," +
|
||||
std::to_string(static_cast<int>(shoe.bbox.h)) + ")" +
|
||||
" score=" + std::to_string(shoe.score) +
|
||||
" iou=" + std::to_string(iou) +
|
||||
" center_inside=" + std::string(center_inside ? "true" : "false") +
|
||||
" pass_gate=" + std::string(pass_gate ? "true" : "false") +
|
||||
" size_preferred=" + std::string(size_preferred ? "true" : "false") +
|
||||
" ratios=(w:" + std::to_string(width_ratio) +
|
||||
",h:" + std::to_string(height_ratio) +
|
||||
",a:" + std::to_string(area_ratio) + ")" +
|
||||
" match_score=" + std::to_string(match_score));
|
||||
}
|
||||
if (!pass_gate) continue;
|
||||
|
||||
const float match_score = (center_inside ? 1.0f : 0.0f) + iou + shoe.score * 0.1f;
|
||||
if (best_shoe_local < 0 || match_score > best_match_score) {
|
||||
++candidate_count;
|
||||
const bool should_replace =
|
||||
best_shoe_local < 0 ||
|
||||
(size_preferred && !best_size_preferred) ||
|
||||
(size_preferred == best_size_preferred && match_score > best_match_score);
|
||||
if (should_replace) {
|
||||
best_shoe_local = static_cast<int>(si);
|
||||
best_match_score = match_score;
|
||||
best_width_ratio = width_ratio;
|
||||
best_height_ratio = height_ratio;
|
||||
best_area_ratio = area_ratio;
|
||||
best_size_preferred = size_preferred;
|
||||
best_center_inside = center_inside;
|
||||
}
|
||||
}
|
||||
|
||||
if (best_shoe_local >= 0) {
|
||||
shoe_used[static_cast<size_t>(best_shoe_local)] = true;
|
||||
Detection& matched_shoe = items[shoe_indices[static_cast<size_t>(best_shoe_local)]];
|
||||
if (config_.debug) {
|
||||
LogInfo("[logic_gate] shoe selected person_track=" + std::to_string(person.track_id) +
|
||||
" candidate_count=" + std::to_string(candidate_count) +
|
||||
" local_idx=" + std::to_string(best_shoe_local) +
|
||||
" det_idx=" + std::to_string(static_cast<int>(shoe_indices[static_cast<size_t>(best_shoe_local)])) +
|
||||
" bbox=(" + std::to_string(static_cast<int>(matched_shoe.bbox.x)) + "," +
|
||||
std::to_string(static_cast<int>(matched_shoe.bbox.y)) + "," +
|
||||
std::to_string(static_cast<int>(matched_shoe.bbox.w)) + "," +
|
||||
std::to_string(static_cast<int>(matched_shoe.bbox.h)) + ")" +
|
||||
" score=" + std::to_string(matched_shoe.score) +
|
||||
" center_inside=" + std::string(best_center_inside ? "true" : "false") +
|
||||
" size_preferred=" + std::string(best_size_preferred ? "true" : "false") +
|
||||
" ratios=(w:" + std::to_string(best_width_ratio) +
|
||||
",h:" + std::to_string(best_height_ratio) +
|
||||
",a:" + std::to_string(best_area_ratio) + ")" +
|
||||
" match_score=" + std::to_string(best_match_score));
|
||||
}
|
||||
if (config_.person_shoe.attach_person_track_to_shoe &&
|
||||
matched_shoe.track_id < 0 && person.track_id >= 0) {
|
||||
matched_shoe.track_id = person.track_id;
|
||||
@ -251,6 +346,11 @@ private:
|
||||
continue;
|
||||
}
|
||||
|
||||
if (config_.debug) {
|
||||
LogInfo("[logic_gate] no shoe selected person_track=" + std::to_string(person.track_id) +
|
||||
" candidate_count=" + std::to_string(candidate_count));
|
||||
}
|
||||
|
||||
if (config_.person_shoe.emit_missing_violation) {
|
||||
Detection no_shoe;
|
||||
no_shoe.cls_id = config_.person_shoe.violation_class;
|
||||
@ -278,12 +378,53 @@ private:
|
||||
auto& detections = frame->det->items;
|
||||
std::vector<Detection> boots;
|
||||
boots.reserve(detections.size());
|
||||
std::unordered_map<int, Rect> person_boxes_by_track;
|
||||
for (const auto& det : detections) {
|
||||
if (det.cls_id == config_.boots_class) boots.push_back(det);
|
||||
if (det.cls_id == config_.person_shoe.person_class && det.track_id >= 0) {
|
||||
person_boxes_by_track[det.track_id] = det.bbox;
|
||||
}
|
||||
}
|
||||
|
||||
for (const auto& boot : boots) {
|
||||
if (!config_.enable_color_check || !color_analyzer_) continue;
|
||||
if (boot.track_id < 0) {
|
||||
if (config_.debug) {
|
||||
LogInfo("[logic_gate] skip unmatched shoe bbox=(" +
|
||||
std::to_string(static_cast<int>(boot.bbox.x)) + "," +
|
||||
std::to_string(static_cast<int>(boot.bbox.y)) + "," +
|
||||
std::to_string(static_cast<int>(boot.bbox.w)) + "," +
|
||||
std::to_string(static_cast<int>(boot.bbox.h)) + ")");
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (config_.enable_size_filter) {
|
||||
auto it = person_boxes_by_track.find(boot.track_id);
|
||||
if (it != person_boxes_by_track.end()) {
|
||||
const Rect& person_bbox = it->second;
|
||||
const float person_area = std::max(1.0f, person_bbox.w * person_bbox.h);
|
||||
const float width_ratio = boot.bbox.w / std::max(1.0f, person_bbox.w);
|
||||
const float height_ratio = boot.bbox.h / std::max(1.0f, person_bbox.h);
|
||||
const float area_ratio = (boot.bbox.w * boot.bbox.h) / person_area;
|
||||
if (width_ratio > config_.max_shoe_width_ratio ||
|
||||
height_ratio > config_.max_shoe_height_ratio ||
|
||||
area_ratio > config_.max_shoe_area_ratio) {
|
||||
if (config_.debug) {
|
||||
LogInfo("[logic_gate] size filter skip track_id=" + std::to_string(boot.track_id) +
|
||||
" shoe=(" + std::to_string(static_cast<int>(boot.bbox.w)) + "x" +
|
||||
std::to_string(static_cast<int>(boot.bbox.h)) + ")" +
|
||||
" person=(" + std::to_string(static_cast<int>(person_bbox.w)) + "x" +
|
||||
std::to_string(static_cast<int>(person_bbox.h)) + ")" +
|
||||
" ratios=(w:" + std::to_string(width_ratio) +
|
||||
",h:" + std::to_string(height_ratio) +
|
||||
",a:" + std::to_string(area_ratio) + ")");
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const Rect mapped_bbox = MapDetCoordToFrame(boot.bbox, frame);
|
||||
const auto color_result = color_analyzer_->Analyze(*frame, mapped_bbox);
|
||||
if (color_result.is_dark) continue;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user