16
16
*/
17
17
18
18
namespace cv { namespace gapi {
19
+
20
+ /* * @brief Structure for the Kalman filter's initialization parameters.*/
21
+
22
+ struct GAPI_EXPORTS KalmanParams
23
+ {
24
+ // initial state
25
+
26
+ // ! corrected state (x(k)): x(k)=x'(k)+K(k)*(z(k)-H*x'(k))
27
+ Mat state;
28
+ // ! posteriori error estimate covariance matrix (P(k)): P(k)=(I-K(k)*H)*P'(k)
29
+ Mat errorCov;
30
+
31
+ // dynamic system description
32
+
33
+ // ! state transition matrix (A)
34
+ Mat transitionMatrix;
35
+ // ! measurement matrix (H)
36
+ Mat measurementMatrix;
37
+ // ! process noise covariance matrix (Q)
38
+ Mat processNoiseCov;
39
+ // ! measurement noise covariance matrix (R)
40
+ Mat measurementNoiseCov;
41
+ // ! control matrix (B) (Optional: not used if there's no control)
42
+ Mat controlMatrix;
43
+ };
44
+
19
45
namespace video
20
46
{
21
47
using GBuildPyrOutput = std::tuple<GArray<GMat>, GScalar>;
@@ -129,6 +155,28 @@ G_TYPED_KERNEL(GBackgroundSubtractor, <GMat(GMat, BackgroundSubtractorParams)>,
129
155
}
130
156
};
131
157
158
+ void checkParams (const cv::gapi::KalmanParams& kfParams,
159
+ const cv::GMatDesc& measurement, const cv::GMatDesc& control = {});
160
+
161
+ G_TYPED_KERNEL (GKalmanFilter, <GMat(GMat, GOpaque<bool >, GMat, KalmanParams)>,
162
+ "org.opencv.video.KalmanFilter")
163
+ {
164
+ static GMatDesc outMeta (const GMatDesc& measurement, const GOpaqueDesc&,
165
+ const GMatDesc& control, const KalmanParams& kfParams)
166
+ {
167
+ checkParams (kfParams, measurement, control);
168
+ return measurement.withSize (Size (1 , kfParams.transitionMatrix .rows ));
169
+ }
170
+ };
171
+
172
+ G_TYPED_KERNEL (GKalmanFilterNoControl, <GMat(GMat, GOpaque<bool >, KalmanParams)>, "org.opencv.video.KalmanFilterNoControl")
173
+ {
174
+ static GMatDesc outMeta (const GMatDesc& measurement, const GOpaqueDesc&, const KalmanParams& kfParams)
175
+ {
176
+ checkParams (kfParams, measurement);
177
+ return measurement.withSize (Size (1 , kfParams.transitionMatrix .rows ));
178
+ }
179
+ };
132
180
} // namespace video
133
181
134
182
// ! @addtogroup gapi_video
@@ -250,6 +298,49 @@ The operation generates a foreground mask.
250
298
*/
251
299
GAPI_EXPORTS GMat BackgroundSubtractor (const GMat& src, const cv::gapi::video::BackgroundSubtractorParams& bsParams);
252
300
301
+ /* * @brief Standard Kalman filter algorithm <http://en.wikipedia.org/wiki/Kalman_filter>.
302
+
303
+ @note Functional textual ID is "org.opencv.video.KalmanFilter"
304
+
305
+ @param measurement input matrix: 32-bit or 64-bit float 1-channel matrix containing measurements.
306
+ @param haveMeasurement dynamic input flag that indicates whether we get measurements
307
+ at a particular iteration .
308
+ @param control input matrix: 32-bit or 64-bit float 1-channel matrix contains control data
309
+ for changing dynamic system.
310
+ @param kfParams Set of initialization parameters for Kalman filter kernel.
311
+
312
+ @return Output matrix is predicted or corrected state. They can be 32-bit or 64-bit float
313
+ 1-channel matrix @ref CV_32FC1 or @ref CV_64FC1.
314
+
315
+ @details If measurement matrix is given (haveMeasurements == true), corrected state will
316
+ be returned which corresponds to the pipeline
317
+ cv::KalmanFilter::predict(control) -> cv::KalmanFilter::correct(measurement).
318
+ Otherwise, predicted state will be returned which corresponds to the call of
319
+ cv::KalmanFilter::predict(control).
320
+ @sa cv::KalmanFilter
321
+ */
322
+ GAPI_EXPORTS GMat KalmanFilter (const GMat& measurement, const GOpaque<bool >& haveMeasurement,
323
+ const GMat& control, const cv::gapi::KalmanParams& kfParams);
324
+
325
+ /* * @overload
326
+ The case of Standard Kalman filter algorithm when there is no control in a dynamic system.
327
+ In this case the controlMatrix is empty and control vector is absent.
328
+
329
+ @note Function textual ID is "org.opencv.video.KalmanFilterNoControl"
330
+
331
+ @param measurement input matrix: 32-bit or 64-bit float 1-channel matrix containing measurements.
332
+ @param haveMeasurement dynamic input flag that indicates whether we get measurements
333
+ at a particular iteration.
334
+ @param kfParams Set of initialization parameters for Kalman filter kernel.
335
+
336
+ @return Output matrix is predicted or corrected state. They can be 32-bit or 64-bit float
337
+ 1-channel matrix @ref CV_32FC1 or @ref CV_64FC1.
338
+
339
+ @sa cv::KalmanFilter
340
+ */
341
+ GAPI_EXPORTS GMat KalmanFilter (const GMat& measurement, const GOpaque<bool >& haveMeasurement,
342
+ const cv::gapi::KalmanParams& kfParams);
343
+
253
344
// ! @} gapi_video
254
345
} // namespace gapi
255
346
} // namespace cv
@@ -264,6 +355,6 @@ template<> struct CompileArgTag<cv::gapi::video::BackgroundSubtractorParams>
264
355
}
265
356
};
266
357
} // namespace detail
267
- } // namespace cv
358
+ } // namespace cv
268
359
269
360
#endif // OPENCV_GAPI_VIDEO_HPP
0 commit comments