|
|
@@ -300,6 +300,8 @@ int main(int argc, char* argv[]) {
|
|
|
|
|
|
// ========== 本机画面输出(HDMI显示器) ==========
|
|
|
string app_name = cfg.value("app_name", "钢包工位视频监测系统");
|
|
|
+ // 工位功能总开关(临时关闭可禁用钢包位/工位切换/空闲检测)
|
|
|
+ bool enable_bucket = cfg.value("enable_bucket", true);
|
|
|
// 两个独立显示器输出: 网格(普通通道) + 钢包位(工位左右摄像头)
|
|
|
bool grid_output = cfg.value("grid_output", true);
|
|
|
bool steel_output = cfg.value("steel_output", true);
|
|
|
@@ -307,6 +309,7 @@ int main(int argc, char* argv[]) {
|
|
|
bool hdmi_fullscreen = cfg.value("hdmi_fullscreen", true);
|
|
|
cout << "[Display] 网格输出: " << (grid_output ? "启用" : "禁用")
|
|
|
<< " 钢包位输出: " << (steel_output ? "启用" : "禁用")
|
|
|
+ << " 工位功能: " << (enable_bucket ? "启用" : "禁用")
|
|
|
<< " 网格列=" << hdmi_grid_cols
|
|
|
<< " 全屏=" << (hdmi_fullscreen ? "是" : "否") << endl;
|
|
|
|
|
|
@@ -318,6 +321,7 @@ int main(int argc, char* argv[]) {
|
|
|
float pose_nms_thresh = cfg.value("pose_nms_thresh", 0.45f);
|
|
|
float fall_thresh = cfg.value("fall_thresh", 0.5f);
|
|
|
int fall_frames = cfg.value("fall_frames", 3);
|
|
|
+ bool target_enabled = cfg.value("target_enabled", true);
|
|
|
bool pose_enabled = cfg.value("pose_enabled", false);
|
|
|
vector<string> pose_alarm_classes;
|
|
|
if (cfg.contains("pose_alarm_classes") && cfg["pose_alarm_classes"].is_array())
|
|
|
@@ -331,6 +335,7 @@ int main(int argc, char* argv[]) {
|
|
|
for (auto& c : cfg["fall_relays"])
|
|
|
if (c.is_string()) fall_relays.push_back(c.get<string>());
|
|
|
if (fall_relays.empty()) fall_relays = {"y01"};
|
|
|
+ cout << "[Target] 目标识别: " << (target_enabled ? "启用" : "禁用") << endl;
|
|
|
cout << "[Pose] 姿态识别: " << (pose_enabled ? "启用" : "禁用")
|
|
|
<< " 模型=" << pose_model_path
|
|
|
<< " 跌倒阈值=" << fall_thresh
|
|
|
@@ -410,7 +415,7 @@ int main(int argc, char* argv[]) {
|
|
|
cout << "========================================" << endl;
|
|
|
|
|
|
YoloDetector detector;
|
|
|
- if (!detector.load(model_path, input_size, conf_thresh, nms_thresh)) {
|
|
|
+ if (target_enabled && !detector.load(model_path, input_size, conf_thresh, nms_thresh)) {
|
|
|
cerr << "RKNN模型加载失败!" << endl;
|
|
|
return 1;
|
|
|
}
|
|
|
@@ -466,7 +471,7 @@ int main(int argc, char* argv[]) {
|
|
|
rfidClient->setConfig(rfidCfg);
|
|
|
rfidClient->setTagCallback([&](const string& tag) {
|
|
|
idleDetector.feed(tag);
|
|
|
- if (!tag.empty()) {
|
|
|
+ if (!tag.empty() && enable_bucket) {
|
|
|
bucketManager.checkAutoSwitch(tag);
|
|
|
}
|
|
|
});
|
|
|
@@ -488,7 +493,7 @@ int main(int argc, char* argv[]) {
|
|
|
modbusClient->setConfig(modbusCfg);
|
|
|
modbusClient->setDataCallback([&](const vector<bool>& coils) {
|
|
|
idleDetector.feed(coils);
|
|
|
- bucketManager.checkAutoSwitch(coils);
|
|
|
+ if (enable_bucket) bucketManager.checkAutoSwitch(coils);
|
|
|
});
|
|
|
modbusClient->setStateCallback([&](bool online) {
|
|
|
cout << "[Modbus] 状态: " << (online ? "在线" : "离线") << endl;
|
|
|
@@ -573,19 +578,23 @@ int main(int argc, char* argv[]) {
|
|
|
<< kMaxChannels << " 路" << endl;
|
|
|
|
|
|
// 钢包位专用通道(占位创建, 工位激活时替换为工位左右摄像头)
|
|
|
- {
|
|
|
+ if (enable_bucket) {
|
|
|
auto chL = makeChannel(kBucketLeftId, "钢包位左", "");
|
|
|
auto chR = makeChannel(kBucketRightId, "钢包位右", "");
|
|
|
lock_guard<mutex> lk(bucket_channels_mtx);
|
|
|
bucket_channels.push_back(chL);
|
|
|
bucket_channels.push_back(chR);
|
|
|
+ cout << "[Main] 钢包位专用通道: 左CH" << kBucketLeftId
|
|
|
+ << " 右CH" << kBucketRightId << endl;
|
|
|
}
|
|
|
- cout << "[Main] 钢包位专用通道: 左CH" << kBucketLeftId
|
|
|
- << " 右CH" << kBucketRightId << endl;
|
|
|
|
|
|
// ========== 工位切换回调 ==========
|
|
|
// 钢包位专用通道跟随工位切换(左右摄像头), 普通rtsp通道不受影响
|
|
|
bucketManager.setActivateCallback([&](const BucketInfo* old, const BucketInfo* cur) {
|
|
|
+ if (!enable_bucket) {
|
|
|
+ idleDetector.reset();
|
|
|
+ return;
|
|
|
+ }
|
|
|
cerr << "[Bucket] 回调触发: old=" << (old ? old->description : "null")
|
|
|
<< " cur=" << (cur ? cur->description : "null") << endl;
|
|
|
// 停止旧工位钢包位摄像头
|
|
|
@@ -632,7 +641,9 @@ int main(int argc, char* argv[]) {
|
|
|
s["conf_thresh"] = conf_thresh;
|
|
|
s["alarm_retention_days"] = alarm_retention_days;
|
|
|
s["alarm_classes"] = alarm_classes;
|
|
|
+ s["target_enabled"] = target_enabled;
|
|
|
s["pose_enabled"] = pose_ok;
|
|
|
+ s["pose_cfg_enabled"] = pose_enabled;
|
|
|
s["pose_model"] = pose_model_path;
|
|
|
s["fall_thresh"] = fall_thresh;
|
|
|
s["fall_frames"] = fall_frames;
|
|
|
@@ -1281,6 +1292,13 @@ int main(int argc, char* argv[]) {
|
|
|
}
|
|
|
if (j.contains("conf_thresh"))
|
|
|
full["conf_thresh"] = j["conf_thresh"];
|
|
|
+ if (j.contains("target_enabled")) {
|
|
|
+ bool en = j["target_enabled"].get<bool>();
|
|
|
+ full["target_enabled"] = en;
|
|
|
+ target_enabled = en;
|
|
|
+ cout << "[Target] 目标识别: " << (en ? "启用" : "禁用")
|
|
|
+ << " (重启后生效)" << endl;
|
|
|
+ }
|
|
|
if (j.contains("pose_enabled")) {
|
|
|
bool en = j["pose_enabled"].get<bool>();
|
|
|
full["pose_enabled"] = en;
|
|
|
@@ -1533,12 +1551,12 @@ int main(int argc, char* argv[]) {
|
|
|
int grid_fixed = (int)channels.size();
|
|
|
displayGrid.start(grid_output, hdmi_grid_cols, app_name + " - 通道网格",
|
|
|
hdmi_fullscreen, 100, grid_fixed);
|
|
|
- displayBucket.start(steel_output, 2, app_name + " - 钢包位",
|
|
|
+ displayBucket.start(steel_output && enable_bucket, 2, app_name + " - 钢包位",
|
|
|
hdmi_fullscreen, 100, 2);
|
|
|
cout << "[Main] Ctrl+C 退出" << endl;
|
|
|
|
|
|
// 自动激活第一个工位(如果有配置)
|
|
|
- {
|
|
|
+ if (enable_bucket) {
|
|
|
auto bs = bucketManager.getBuckets();
|
|
|
if (!bs.empty()) {
|
|
|
cout << "[Main] 自动激活第一个工位: " << bs[0].description << endl;
|
|
|
@@ -1597,7 +1615,7 @@ int main(int argc, char* argv[]) {
|
|
|
|
|
|
// RFID/Modbus空闲检测
|
|
|
if (rfidClient) rfidClient->checkIdle();
|
|
|
- if (idleDetector.isIdle() && bucketManager.getActiveBucketId() >= 0) {
|
|
|
+ if (enable_bucket && idleDetector.isIdle() && bucketManager.getActiveBucketId() >= 0) {
|
|
|
cout << "[Bucket] 空闲超时,取消激活" << endl;
|
|
|
bucketManager.activateBucket(-1);
|
|
|
}
|
|
|
@@ -1711,9 +1729,11 @@ int main(int argc, char* argv[]) {
|
|
|
if (ch->frame_count <= 4)
|
|
|
cout << "[CH" << ch->id << "] infer frame=" << ch->frame_count
|
|
|
<< " rgb=" << ch->rgb_buf.size() << endl;
|
|
|
- auto dets = detector.detect(ch->rgb_buf.data(),
|
|
|
- nv12.width, nv12.height,
|
|
|
- scale, pad_x, pad_y);
|
|
|
+ vector<Detection> dets;
|
|
|
+ if (target_enabled)
|
|
|
+ dets = detector.detect(ch->rgb_buf.data(),
|
|
|
+ nv12.width, nv12.height,
|
|
|
+ scale, pad_x, pad_y);
|
|
|
|
|
|
vector<cv::Point2f> centers;
|
|
|
vector<int> cids;
|