|
| 1 | +From e50015edd252f5aef9fb3b09d7d1c0a58d7c9774 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Garrett Brown <garrett.brown@aclima.earth> |
| 3 | +Date: Sat, 7 Feb 2026 12:07:04 -0800 |
| 4 | +Subject: [PATCH 3/3] Implement OpenCV4 required apply() overload |
| 5 | + |
| 6 | +--- |
| 7 | + bgslibrary/algorithms/LBSP/BackgroundSubtractorLBSP.h | 11 +++++++++++ |
| 8 | + .../algorithms/LBSP/BackgroundSubtractorLBSP_.h | 11 +++++++++++ |
| 9 | + .../algorithms/LBSP/BackgroundSubtractorLOBSTER.h | 11 +++++++++++ |
| 10 | + .../algorithms/LBSP/BackgroundSubtractorPAWCS.h | 11 +++++++++++ |
| 11 | + .../algorithms/LBSP/BackgroundSubtractorSuBSENSE.h | 11 +++++++++++ |
| 12 | + 5 files changed, 55 insertions(+) |
| 13 | + |
| 14 | +diff --git a/bgslibrary/algorithms/LBSP/BackgroundSubtractorLBSP.h b/bgslibrary/algorithms/LBSP/BackgroundSubtractorLBSP.h |
| 15 | +index 3744b8c..be5bfee 100644 |
| 16 | +--- a/bgslibrary/algorithms/LBSP/BackgroundSubtractorLBSP.h |
| 17 | ++++ b/bgslibrary/algorithms/LBSP/BackgroundSubtractorLBSP.h |
| 18 | +@@ -22,6 +22,8 @@ namespace bgslibrary |
| 19 | + */ |
| 20 | + class BackgroundSubtractorLBSP : public cv::BackgroundSubtractor { |
| 21 | + public: |
| 22 | ++ using cv::BackgroundSubtractor::apply; |
| 23 | ++ |
| 24 | + //! full constructor |
| 25 | + BackgroundSubtractorLBSP(float fRelLBSPThreshold, size_t nLBSPThresholdOffset = 0); |
| 26 | + //! default destructor |
| 27 | +@@ -32,6 +34,15 @@ namespace bgslibrary |
| 28 | + virtual void initialize(const cv::Mat& oInitImg, const cv::Mat& oROI) = 0; |
| 29 | + //! primary model update function; the learning param is used to override the internal learning speed (ignored when <= 0) |
| 30 | + virtual void apply(cv::InputArray image, cv::OutputArray fgmask, double learningRate = 0) = 0; |
| 31 | ++ // add OpenCV4 overloaded apply that takes a knownForegroundMask |
| 32 | ++ void apply(cv::InputArray image, |
| 33 | ++ cv::InputArray knownForegroundMask, |
| 34 | ++ cv::OutputArray fgmask, |
| 35 | ++ double learningRate = -1) CV_OVERRIDE |
| 36 | ++ { |
| 37 | ++ (void)knownForegroundMask; // ignore this mask by default |
| 38 | ++ apply(image, fgmask, learningRate); // forward to existing implementation |
| 39 | ++ } |
| 40 | + //! unused, always returns nullptr |
| 41 | + //virtual cv::AlgorithmInfo* info() const; |
| 42 | + //! returns a copy of the ROI used for descriptor extraction |
| 43 | +diff --git a/bgslibrary/algorithms/LBSP/BackgroundSubtractorLBSP_.h b/bgslibrary/algorithms/LBSP/BackgroundSubtractorLBSP_.h |
| 44 | +index 79d6df9..04eb4ac 100644 |
| 45 | +--- a/bgslibrary/algorithms/LBSP/BackgroundSubtractorLBSP_.h |
| 46 | ++++ b/bgslibrary/algorithms/LBSP/BackgroundSubtractorLBSP_.h |
| 47 | +@@ -22,6 +22,8 @@ namespace bgslibrary |
| 48 | + */ |
| 49 | + class BackgroundSubtractorLBSP_ : public cv::BackgroundSubtractor { |
| 50 | + public: |
| 51 | ++ using cv::BackgroundSubtractor::apply; |
| 52 | ++ |
| 53 | + //! full constructor |
| 54 | + BackgroundSubtractorLBSP_(float fRelLBSPThreshold, size_t nLBSPThresholdOffset = 0); |
| 55 | + //! default destructor |
| 56 | +@@ -32,6 +34,15 @@ namespace bgslibrary |
| 57 | + virtual void initialize(const cv::Mat& oInitImg, const cv::Mat& oROI) = 0; |
| 58 | + //! primary model update function; the learning param is used to override the internal learning speed (ignored when <= 0) |
| 59 | + virtual void apply(cv::InputArray image, cv::OutputArray fgmask, double learningRate = 0) = 0; |
| 60 | ++ // add OpenCV4 overloaded apply that takes a knownForegroundMask |
| 61 | ++ void apply(cv::InputArray image, |
| 62 | ++ cv::InputArray knownForegroundMask, |
| 63 | ++ cv::OutputArray fgmask, |
| 64 | ++ double learningRate = -1) CV_OVERRIDE |
| 65 | ++ { |
| 66 | ++ (void)knownForegroundMask; // ignore this mask by default |
| 67 | ++ apply(image, fgmask, learningRate); // forward to existing implementation |
| 68 | ++ } |
| 69 | + //! unused, always returns nullptr |
| 70 | + //virtual cv::AlgorithmInfo* info() const; |
| 71 | + //! returns a copy of the ROI used for descriptor extraction |
| 72 | +diff --git a/bgslibrary/algorithms/LBSP/BackgroundSubtractorLOBSTER.h b/bgslibrary/algorithms/LBSP/BackgroundSubtractorLOBSTER.h |
| 73 | +index b7860a1..3dd38fd 100644 |
| 74 | +--- a/bgslibrary/algorithms/LBSP/BackgroundSubtractorLOBSTER.h |
| 75 | ++++ b/bgslibrary/algorithms/LBSP/BackgroundSubtractorLOBSTER.h |
| 76 | +@@ -36,6 +36,8 @@ namespace bgslibrary |
| 77 | + */ |
| 78 | + class BackgroundSubtractorLOBSTER : public BackgroundSubtractorLBSP { |
| 79 | + public: |
| 80 | ++ using cv::BackgroundSubtractor::apply; |
| 81 | ++ |
| 82 | + //! full constructor |
| 83 | + BackgroundSubtractorLOBSTER(float fRelLBSPThreshold = BGSLOBSTER_DEFAULT_LBSP_REL_SIMILARITY_THRESHOLD, |
| 84 | + size_t nLBSPThresholdOffset = BGSLOBSTER_DEFAULT_LBSP_OFFSET_SIMILARITY_THRESHOLD, |
| 85 | +@@ -51,6 +53,15 @@ namespace bgslibrary |
| 86 | + virtual void refreshModel(float fSamplesRefreshFrac, bool bForceFGUpdate = false); |
| 87 | + //! primary model update function; the learning param is reinterpreted as an integer and should be > 0 (smaller values == faster adaptation) |
| 88 | + virtual void apply(cv::InputArray image, cv::OutputArray fgmask, double learningRateOverride = BGSLOBSTER_DEFAULT_LEARNING_RATE); |
| 89 | ++ // add OpenCV4 overloaded apply that takes a knownForegroundMask |
| 90 | ++ void apply(cv::InputArray image, |
| 91 | ++ cv::InputArray knownForegroundMask, |
| 92 | ++ cv::OutputArray fgmask, |
| 93 | ++ double learningRate = -1) CV_OVERRIDE |
| 94 | ++ { |
| 95 | ++ (void)knownForegroundMask; // ignore this mask by default |
| 96 | ++ apply(image, fgmask, learningRate); // forward to existing implementation |
| 97 | ++ } |
| 98 | + //! returns a copy of the latest reconstructed background image |
| 99 | + void getBackgroundImage(cv::OutputArray backgroundImage) const; |
| 100 | + //! returns a copy of the latest reconstructed background descriptors image |
| 101 | +diff --git a/bgslibrary/algorithms/LBSP/BackgroundSubtractorPAWCS.h b/bgslibrary/algorithms/LBSP/BackgroundSubtractorPAWCS.h |
| 102 | +index e81736d..925e601 100644 |
| 103 | +--- a/bgslibrary/algorithms/LBSP/BackgroundSubtractorPAWCS.h |
| 104 | ++++ b/bgslibrary/algorithms/LBSP/BackgroundSubtractorPAWCS.h |
| 105 | +@@ -32,6 +32,8 @@ namespace bgslibrary |
| 106 | + */ |
| 107 | + class BackgroundSubtractorPAWCS : public BackgroundSubtractorLBSP_ { |
| 108 | + public: |
| 109 | ++ using cv::BackgroundSubtractor::apply; |
| 110 | ++ |
| 111 | + //! full constructor |
| 112 | + BackgroundSubtractorPAWCS(float fRelLBSPThreshold = BGSPAWCS_DEFAULT_LBSP_REL_SIMILARITY_THRESHOLD, |
| 113 | + size_t nDescDistThresholdOffset = BGSPAWCS_DEFAULT_DESC_DIST_THRESHOLD_OFFSET, |
| 114 | +@@ -46,6 +48,15 @@ namespace bgslibrary |
| 115 | + virtual void refreshModel(size_t nBaseOccCount, float fOccDecrFrac, bool bForceFGUpdate = false); |
| 116 | + //! primary model update function; the learning param is used to override the internal learning speed (ignored when <= 0) |
| 117 | + virtual void apply(cv::InputArray image, cv::OutputArray fgmask, double learningRateOverride = 0); |
| 118 | ++ // add OpenCV4 overloaded apply that takes a knownForegroundMask |
| 119 | ++ void apply(cv::InputArray image, |
| 120 | ++ cv::InputArray knownForegroundMask, |
| 121 | ++ cv::OutputArray fgmask, |
| 122 | ++ double learningRate = -1) CV_OVERRIDE |
| 123 | ++ { |
| 124 | ++ (void)knownForegroundMask; // ignore this mask by default |
| 125 | ++ apply(image, fgmask, learningRate); // forward to existing implementation |
| 126 | ++ } |
| 127 | + //! returns a copy of the latest reconstructed background image |
| 128 | + virtual void getBackgroundImage(cv::OutputArray backgroundImage) const; |
| 129 | + //! returns a copy of the latest reconstructed background descriptors image |
| 130 | +diff --git a/bgslibrary/algorithms/LBSP/BackgroundSubtractorSuBSENSE.h b/bgslibrary/algorithms/LBSP/BackgroundSubtractorSuBSENSE.h |
| 131 | +index 9ec95e1..aabe129 100644 |
| 132 | +--- a/bgslibrary/algorithms/LBSP/BackgroundSubtractorSuBSENSE.h |
| 133 | ++++ b/bgslibrary/algorithms/LBSP/BackgroundSubtractorSuBSENSE.h |
| 134 | +@@ -34,6 +34,8 @@ namespace bgslibrary |
| 135 | + */ |
| 136 | + class BackgroundSubtractorSuBSENSE : public BackgroundSubtractorLBSP { |
| 137 | + public: |
| 138 | ++ using cv::BackgroundSubtractor::apply; |
| 139 | ++ |
| 140 | + //! full constructor |
| 141 | + BackgroundSubtractorSuBSENSE(float fRelLBSPThreshold = BGSSUBSENSE_DEFAULT_LBSP_REL_SIMILARITY_THRESHOLD, |
| 142 | + size_t nDescDistThresholdOffset = BGSSUBSENSE_DEFAULT_DESC_DIST_THRESHOLD_OFFSET, |
| 143 | +@@ -49,6 +51,15 @@ namespace bgslibrary |
| 144 | + virtual void refreshModel(float fSamplesRefreshFrac, bool bForceFGUpdate = false); |
| 145 | + //! primary model update function; the learning param is used to override the internal learning thresholds (ignored when <= 0) |
| 146 | + virtual void apply(cv::InputArray image, cv::OutputArray fgmask, double learningRateOverride = 0); |
| 147 | ++ // add OpenCV4 overloaded apply that takes a knownForegroundMask |
| 148 | ++ void apply(cv::InputArray image, |
| 149 | ++ cv::InputArray knownForegroundMask, |
| 150 | ++ cv::OutputArray fgmask, |
| 151 | ++ double learningRate = -1) CV_OVERRIDE |
| 152 | ++ { |
| 153 | ++ (void)knownForegroundMask; // ignore this mask by default |
| 154 | ++ apply(image, fgmask, learningRate); // forward to existing implementation |
| 155 | ++ } |
| 156 | + //! returns a copy of the latest reconstructed background image |
| 157 | + void getBackgroundImage(cv::OutputArray backgroundImage) const; |
| 158 | + //! returns a copy of the latest reconstructed background descriptors image |
| 159 | +-- |
| 160 | +2.43.0 |
| 161 | + |
0 commit comments