Skip to content

GAPI: Kalman filter stateful kernel.#18869

Merged
alalek merged 8 commits intoopencv:masterfrom
anna-khakimova:ak/kalman
Dec 14, 2020
Merged

GAPI: Kalman filter stateful kernel.#18869
alalek merged 8 commits intoopencv:masterfrom
anna-khakimova:ak/kalman

Conversation

@anna-khakimova
Copy link
Copy Markdown
Member

@anna-khakimova anna-khakimova commented Nov 19, 2020

New stateful Kalman filter kernel for GAPI.

@OrestChura, @rgarnov, @AsyaPronina please review.

Published for review on 19th of November.

force_builders_only=linux,docs,Custom
Xforce_builders=Custom,Custom Win,Custom Mac,Linux32,Win32
build_gapi_standalone:Linux x64=ade-0.1.1f
build_gapi_standalone:Win64=ade-0.1.1f
build_gapi_standalone:Mac=ade-0.1.1f
build_gapi_standalone:Linux x64 Debug=ade-0.1.1f

build_image:Custom=centos:7
buildworker:Custom=linux-1
build_gapi_standalone:Custom=ade-0.1.1f

Xbuild_image:Custom=ubuntu-openvino-2020.3.0:16.04
Xbuild_image:Custom Win=openvino-2020.3.0
build_image:Custom Mac=openvino-2020.3.0

test_modules:Custom=gapi
test_modules:Custom Win=gapi
test_modules:Custom Mac=gapi

buildworker:Custom=linux-1
# disabled due high memory usage: test_opencl:Custom=ON
test_opencl:Custom=OFF
test_bigdata:Custom=1
test_filter:Custom=*

@anna-khakimova anna-khakimova force-pushed the ak/kalman branch 5 times, most recently from 10772df to 0b05f55 Compare November 20, 2020 13:35
@alalek
Copy link
Copy Markdown
Member

alalek commented Nov 20, 2020

New BackgroundSubtractorMOG2 kernel

In makes sense to separate unrelated commits.

#include "opencv2/core/mat.hpp"
#include "opencv2/core.hpp"

#undef countNonZero
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this in public GAPI headers?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@anna-khakimova countNonZero() is banned for a reason: this function can take ONLY single-channel Mat.
(See #16657)
You can use cv::norm() here instead

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is banned in tests only.
No idea how this appears in common public header.

Copy link
Copy Markdown
Member Author

@anna-khakimova anna-khakimova Nov 20, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This appear because both headers modules/gapi/include/opencv2/gapi/cpu/video.hpp and modules/gapi/test/test_precomp.hpp are included to one modules/gapi/test/cpu/gapi_video_tests_cpu.cpp. So,
#define countNonZero() countNonZero_is_forbidden_in_tests_use_norm_instead() in test_precomp.hpp affects content of cpu/video.hpp file.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you really need such details in the future?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move this hack to the tests if it is really necessary (or move code implementation into src/, or replace this call)

cv::countNonZero(...) > 0) is slow (and may cause unexpected result overflow which is worse). Replace to

norm(..., NORM_INF) != 0

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. Changed.

Comment on lines +25 to +31
struct KalmanParams
{
KalmanParams()
{
statePre = Mat::zeros(dpDims, 1, type);
statePost = Mat::zeros(dpDims, 1, type);
transitionMatrix = Mat::eye(dpDims, dpDims, type);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A lot of code in public headers.

Public headers should define API for Users only.
Implementation must go into "src".

/cc @dmatveev

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, implementation can be placed in modules/gapi/src/backends/cpu/gcpuvideo.cpp next to the kernel which uses this

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment on lines +24 to +25

struct KalmanParams
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Classes in public headers should be properly documented.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. Applied.

#include "opencv2/core/mat.hpp"
#include "opencv2/core.hpp"

#undef countNonZero
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@anna-khakimova countNonZero() is banned for a reason: this function can take ONLY single-channel Mat.
(See #16657)
You can use cv::norm() here instead

Comment on lines +25 to +31
struct KalmanParams
{
KalmanParams()
{
statePre = Mat::zeros(dpDims, 1, type);
statePost = Mat::zeros(dpDims, 1, type);
transitionMatrix = Mat::eye(dpDims, dpDims, type);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, implementation can be placed in modules/gapi/src/backends/cpu/gcpuvideo.cpp next to the kernel which uses this

@anna-khakimova anna-khakimova force-pushed the ak/kalman branch 2 times, most recently from 5b02e05 to 256c4a6 Compare November 29, 2020 00:51
Copy link
Copy Markdown
Contributor

@OrestChura OrestChura left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Such a complicated operation! Great!

@anna-khakimova anna-khakimova changed the title GAPI: New Kalman filter kernel. GAPI: Kalman filter stateful kernel. Dec 1, 2020
Copy link
Copy Markdown
Contributor

@dmatveev dmatveev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @OrestChura for the initial review.

@anna-khakimova
Copy link
Copy Markdown
Member Author

@OrestChura please resolve applied conversations.

Copy link
Copy Markdown
Contributor

@OrestChura OrestChura left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost!!

@anna-khakimova
Copy link
Copy Markdown
Member Author

@alalek please take a look.

@anna-khakimova
Copy link
Copy Markdown
Member Author

@rgarnov , @OrestChura please check

Copy link
Copy Markdown
Contributor

@rgarnov rgarnov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, good job!

Copy link
Copy Markdown
Contributor

@OrestChura OrestChura left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job! Thank you!
The remaining comments are minor, you may apply if there are further iterations

@anna-khakimova
Copy link
Copy Markdown
Member Author

@alalek please review.

@alalek
Copy link
Copy Markdown
Member

alalek commented Dec 11, 2020

Overall look good to me.
Please left feedback near comments if they are out of scope of this PR and will not be addressed here.

@anna-khakimova
Copy link
Copy Markdown
Member Author

@alalek comments were addressed. Please check.

@alalek alalek merged commit 46e275d into opencv:master Dec 14, 2020
@anna-khakimova
Copy link
Copy Markdown
Member Author

@alalek thank you.

@alalek alalek mentioned this pull request Apr 9, 2021
a-sajjad72 pushed a commit to a-sajjad72/opencv that referenced this pull request Mar 30, 2023
* GAPI: Kalman filter stateful kernel

* Applied comments

* Applied comments. Second iteration

* Add overload without control vector

* Remove structure constructor and dimension fields.

* Add sample as test

* Remove visualization from test-sample + correct doxygen comments

* Applied comments.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants