Test fire and smoke
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -38,6 +38,9 @@ class CUSTOM_API ANSCustomFS : public IANSCustomClass
|
||||
// V-channel flicker gate: real fire oscillates in luma; sunlight does not
|
||||
static constexpr double FLICKER_V_STD_THRESHOLD = 3.0;
|
||||
static constexpr int FLICKER_MIN_SAMPLES = 6;
|
||||
// Minimum fire/smoke box area as a fraction of the full frame (configurable via "MinObjectSize").
|
||||
// Resolution-independent: rejects tiny boxes (the dominant small false-positive source).
|
||||
static constexpr float DEFAULT_MIN_OBJECT_RATIO = 0.0003f; // 0.03% of frame area
|
||||
|
||||
private:
|
||||
using ANSLIBPtr = std::unique_ptr<ANSCENTER::ANSLIB, decltype(&ANSCENTER::ANSLIB::Destroy)>;
|
||||
@@ -99,6 +102,8 @@ private:
|
||||
std::vector<cv::Rect> _exclusiveROIs;
|
||||
float _smokeDetetectionThreshold{ 0 };
|
||||
float _motionSpecificity{ 0 };
|
||||
// Min fire/smoke box area as a fraction of the full frame; see DEFAULT_MIN_OBJECT_RATIO.
|
||||
float _minObjectAreaRatio{ DEFAULT_MIN_OBJECT_RATIO };
|
||||
|
||||
// Tracker-based voting state
|
||||
std::unordered_map<int, TrackRecord> _trackHistory;
|
||||
@@ -118,6 +123,7 @@ private:
|
||||
|
||||
bool IsROIOverlapping(const cv::Rect& obj, const std::vector<cv::Rect>& objectList, float iouThreshold = 0.5);
|
||||
bool IsDetectedAreaValid(const cv::Rect& area) const;
|
||||
bool IsObjectLargeEnough(const cv::Rect& box, const cv::Size& frameSize) const;
|
||||
bool IsFireOrSmoke(int classId, float confidence) const;
|
||||
bool ValidateMotionCorrelation(const std::vector<cv::Rect>& fireNSmokeRects) const;
|
||||
void UpdatePositiveDetection();
|
||||
|
||||
Reference in New Issue
Block a user