Files
nghianguyenandClaude Fable 5.1 e893be4a75 ANSCustomFireNSmokeDetection: the ANSVIS custom model is judged by ANSMIND's Fire & Smoke verifier
The DLL used to find a detection in one section of the frame, latch a crop
round it and vote on tracked boxes inside that crop. Measured on the field
recordings that was itself the main false-alarm source (the detector needs
context: a floodlight is fake_fire on the whole frame and fire on a tight
crop of the same lamp), and a PTZ tour broke the latch. ANSMIND's native
vision.fire_smoke node replaced it with a whole-frame-first verifier whose
cues are box-relative and carried by global motion, fire-only native zoom
re-checks, a look-alike filter and a ladder of gates measured on real and
false recordings.

The DLL now feeds that verifier, vendored verbatim from ANSMINDCORE dba11ac
(vendor/engine/fire_smoke.hpp, pure C++): ANSLIB runs the package's
detector on the whole frame at a low floor with class-agnostic NMS, the COCO
filter when there is a candidate to explain, and the detector again on the
few native crops the verifier plans; only confirmed tracks come back, as
fire/smoke CustomObjects with fs_seconds/fs_track/evidence in extraInfo.
Parameters: Sensitivity (slider onto low/balanced/high), SmokeSeconds,
DetectFire/DetectSmoke, ZoomChecks, MaxFps (6: evidence is per second of
scene), CandidateScore, MinObjectSize (49a53c3's knob, kept: a candidate
under that fraction of the frame is noise), ExclusiveROIs. Engines load
inside Initialize: a lazily loaded one faulted in ANSLIB's inference entry
on the first frame.

FireNSmokeDetection_Run replays a recording on the video's clock (parity
harness with firesmoke-run). Measured, same package, TensorRT:
  15.9.9.0_9.51_real_smoke   63 alarms, first at 3.0 s (node: 56, 3.0 s)
  15.9.9.51.10.51_real_smoke 113 alarms, first at 3.0 s (node: 126, 3.0 s)
  8 KA false_* clips          0 alarms (node: 0)
Unit tests updated for the new parameter schema; 9/9 pass. The headless
checker from 49a53c3 builds unchanged against the new class.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-11-01 12:15:33 +11:00

78 lines
2.8 KiB
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#pragma once
// core/detection — the detection currency of the pipeline.
//
// Coordinates are NORMALIZED [0,1] of the source frame, always. ANSCORE mixed
// pixel- and crop-relative coordinates and the ALPRChecker false-merge bug
// (§6.3) was the price; one coordinate space ends that class of bug. Pixel
// mapping happens only at the edges (pre-processing in, overlay/evidence out).
#include <cstdint>
#include <string>
#include <vector>
namespace ansmind {
struct RectF {
float x = 0, y = 0, w = 0, h = 0; // top-left + size, normalized
float area() const { return w > 0 && h > 0 ? w * h : 0.f; }
float iou(const RectF& o) const {
const float x1 = x > o.x ? x : o.x;
const float y1 = y > o.y ? y : o.y;
const float x2 = (x + w) < (o.x + o.w) ? (x + w) : (o.x + o.w);
const float y2 = (y + h) < (o.y + o.h) ? (y + h) : (o.y + o.h);
if (x2 <= x1 || y2 <= y1) return 0.f;
const float inter = (x2 - x1) * (y2 - y1);
return inter / (area() + o.area() - inter);
}
RectF clamped() const {
RectF r = *this;
if (r.x < 0) { r.w += r.x; r.x = 0; }
if (r.y < 0) { r.h += r.y; r.y = 0; }
if (r.x + r.w > 1) r.w = 1 - r.x;
if (r.y + r.h > 1) r.h = 1 - r.y;
if (r.w < 0) r.w = 0;
if (r.h < 0) r.h = 0;
return r;
}
};
// A resolved attribute attached by the TrackResolver (§6.2) — identity,
// plate, helmet… Value "unknown" is first-class (the stranger case).
struct DetAttr {
std::string key;
std::string value;
float confidence = 0;
};
struct Detection {
RectF box;
float confidence = 0;
int classId = -1;
std::string className;
std::string nodeId; // which graph node produced it
uint64_t trackId = 0; // 0 = untracked
int parentIndex = -1; // RegionNode: index of the parent detection
std::vector<DetAttr> attrs; // TrackResolver output; rules bind to these
// Landmarks in NORMALIZED frame coords (x0,y0,…x4,y4 for SCRFD's 5-point
// faces; empty when the detector has none). The embed node aligns on
// these — the ANSFR accuracy lever.
std::vector<float> kps;
// Per-keypoint confidence, parallel to kps (one per x,y pair; empty when
// the detector gives none — SCRFD's five landmarks carry no score). Pose
// models (YOLOv8-pose, RF-DETR keypoints) fill it: consumers hide a joint
// the model could not find rather than drawing it at a guessed spot.
std::vector<float> kpConf;
// Instance mask, CROPPED TO THE BOX at the seg head's proto resolution
// (0/255 bytes, row-major maskW×maskH; empty for plain detectors).
// Deliberately small — a proto crop is ≤160px per side — consumers
// upscale to the box when they need pixels.
std::vector<uint8_t> mask;
uint16_t maskW = 0, maskH = 0;
std::vector<float> embedding; // engine-internal transient (embed nodes)
};
using DetectionSet = std::vector<Detection>;
} // namespace ansmind