Test fire and smoke

This commit is contained in:
2026-06-18 05:57:14 +10:00
parent e70acb463e
commit 49a53c344e
196 changed files with 17854 additions and 2 deletions
@@ -3,6 +3,14 @@
bool ANSCustomFS::IsDetectedAreaValid(const cv::Rect& area) const {
return area.width > MIN_ROI_SIZE && area.height > MIN_ROI_SIZE;
}
// Reject fire/smoke boxes that are too small relative to the frame. Defined as a
// fraction of frame area so the behavior is consistent across camera resolutions.
bool ANSCustomFS::IsObjectLargeEnough(const cv::Rect& box, const cv::Size& frameSize) const {
const double frameArea = static_cast<double>(frameSize.width) * frameSize.height;
if (frameArea <= 0.0) return true; // can't judge — don't drop
const double boxArea = static_cast<double>(std::max(0, box.width)) * std::max(0, box.height);
return (boxArea / frameArea) >= static_cast<double>(_minObjectAreaRatio);
}
bool ANSCustomFS::IsFireOrSmoke(int classId, float confidence) const {
return (classId == 0) || // Fire
(classId == 2 && confidence >= SMOKE_CONFIDENCE_THRESHOLD); // Smoke
@@ -329,6 +337,16 @@ void ANSCustomFS::GetModelParameters() {
// Note: Motion detector threshold is set during LoadModelFromFolder.
// Runtime threshold update is not supported through ANSLIB API.
}
else if (param.Name.find("MinObjectSize") != std::string::npos) {
// UI value is a percentage of the frame area (e.g. 0.03 = 0.03%).
try {
const float pct = std::stof(param.Value);
_minObjectAreaRatio = std::clamp(pct / 100.0f, 0.0f, 1.0f);
}
catch (const std::exception&) {
_minObjectAreaRatio = DEFAULT_MIN_OBJECT_RATIO;
}
}
}
_readROIs = true;
}
@@ -384,6 +402,9 @@ std::vector<ANSCENTER::Object> ANSCustomFS::FindNewDetectedArea(
if (!IsFireOrSmoke(detectedObj.classId, detectedObj.confidence)) continue;
// Size gate — ignore boxes too small relative to the frame.
if (!IsObjectLargeEnough(detectedObj.box, frame.size())) continue;
const bool isHighConf = (detectedObj.confidence > DETECTION_CONFIDENCE_THRESHOLD);
const bool isLowConfFire =
(detectedObj.classId == 0) && (detectedObj.confidence >= LOW_CONF_FIRE_THRESHOLD);
@@ -559,6 +580,20 @@ bool ANSCustomFS::ConfigureParameters(CustomParams& param) {
param2.ListItems.clear();
param2.DefaultValue = std::to_string(MOTION_SENSITIVITY);
param.Parameters.push_back(param2);
// Minimum detected fire/smoke size, as a percentage of the full frame area.
// Boxes below this are rejected — suppresses tiny false positives.
CustomParameter param3;
param3.Name = "MinObjectSize";
param3.DataType = "float";
param3.NoOfDecimals = 2;
param3.MaxValue = 10; // up to 10% of the frame
param3.MinValue = 0;
param3.StartValue = std::to_string(DEFAULT_MIN_OBJECT_RATIO * 100.0f);
param3.ListItems.clear();
param3.DefaultValue = std::to_string(DEFAULT_MIN_OBJECT_RATIO * 100.0f);
param.Parameters.push_back(param3);
param.ROI_Values.clear();
for (auto& roi : this->_params.ROI_Values) {
CustomROIValue roiValue;
@@ -1151,6 +1186,12 @@ std::vector<ANSCENTER::Object> ANSCustomFS::ProcessExistingDetectedArea(
continue;
}
// 2b. Minimum-size gate — reject boxes too small relative to the frame.
// Applied before voting so tiny noise never accumulates confirmation votes.
if (!IsObjectLargeEnough(detectedObj.box, frame.size())) {
continue;
}
// 3. Sample mean HSV V inside the bbox for the flicker deque
cv::Rect safeBox = detectedObj.box & cv::Rect(0, 0, frame.cols, frame.rows);
double vMean = 0.0;