Skip to content

GAPI: New BackgroundSubtractor stateful kernel#18674

Merged
alalek merged 2 commits intoopencv:masterfrom
anna-khakimova:ak/backgroundSubtractor
Nov 30, 2020
Merged

GAPI: New BackgroundSubtractor stateful kernel#18674
alalek merged 2 commits intoopencv:masterfrom
anna-khakimova:ak/backgroundSubtractor

Conversation

@anna-khakimova
Copy link
Copy Markdown
Member

@anna-khakimova anna-khakimova commented Oct 27, 2020

New BackgroundSubtractor kernel represents 2 types of operation such as:

  • Background Subtractor MOG2 (default);

  • Background Subtractor KNN

Published for review on 27th of October.

@dmatveev , @OrestChura , please take a look.


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
Xbuild_image:Custom Mac=openvino-2020.3.0

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

@anna-khakimova anna-khakimova force-pushed the ak/backgroundSubtractor branch 4 times, most recently from 706297c to 63181be Compare October 28, 2020 01:30
@anna-khakimova anna-khakimova changed the title New BackgroundSubtractorMOG2 kernel GAPI: Add new BackgroundSubtractorMOG2 stateful kernel Oct 28, 2020
Copy link
Copy Markdown
Member

@alalek alalek left a comment

Choose a reason for hiding this comment

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

/cc @dmatveev

@param src input image: 8-bit unsigned 3-channel image @ref CV_8UC3.
@sa RGB2BGR
*/
GAPI_EXPORTS GMat BGR2RGB(const GMat& src);
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.

Consider adding RGB2BGR too (as inlines alias for example).

/cc @dmatveev

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.

I don't understand your proposal. Please explain.


//! @} gapi_filters

//! @addtogroup gapi_colorconvert
Copy link
Copy Markdown
Member

@alalek alalek Oct 30, 2020

Choose a reason for hiding this comment

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

Perhaps it is better to move these doxygen headers instead of the function.
Keep patches small.


How is this change related to this PR? Each PR should have single clear purpose.

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.

I noticed that this description accidentally was put into the wrong documentation group and I corrected that. Nothing criminal. This is my code from the previous PR. It seems to me that we shouldn't approach this issue so formally.

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.

outdated


@sa BackSubMOG2
*/
GAPI_EXPORTS GMat BackSubMOG2(const GMat& src);
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.

OpenCV implementation of this algorithm has several parameters. Why do we lose them?

    createBackgroundSubtractorMOG2(int history=500, double varThreshold=16,
                                   bool detectShadows=true);

BackSubMOG2

Do we really want to obfuscate function name?


@sa BackSubMOG2

Points on that? on this function again?

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.

Addressed


static void run(const cv::Mat& in, cv::Mat &out, cv::BackgroundSubtractorMOG2& state)
{
state.apply(in, out, -1);
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.

double learningRate

Lost this parameter too.

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.

Changed

@asmorkalov
Copy link
Copy Markdown
Contributor

@anna-khakimova Friendly reminder.

@anna-khakimova anna-khakimova force-pushed the ak/backgroundSubtractor branch 12 times, most recently from e551028 to f83166d Compare November 17, 2020 23:26
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!

@anna-khakimova anna-khakimova force-pushed the ak/backgroundSubtractor branch 6 times, most recently from 07966fe to cd914d1 Compare November 18, 2020 08:53
@anna-khakimova anna-khakimova force-pushed the ak/backgroundSubtractor branch 2 times, most recently from 0e65bae to 4b6636e Compare November 25, 2020 23:09
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 nothing left, some minor suggestions

@anna-khakimova
Copy link
Copy Markdown
Member Author

@alalek please take a look one more.

Values(500, 400, 300, 550),
Values(true, false),
Values(-1, 0, 0.5, 1),
Values("cv/video/768x576.avi")));
Copy link
Copy Markdown
Member

@alalek alalek Nov 26, 2020

Choose a reason for hiding this comment

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

[----------] 256 tests from BackgroundSubtractorTestCPU/BackgroundSubtractorTest (413881 ms total)

This one test case consumes the 2x times more than other 30+k G-API tests.

Keep tests fast.
Do not enable tests if they don't increase code coverage.

TODO:

  • please reduce amount of enabled test cases (you may want to create "full" case for development disabled by default).
  • reduce amount of processed frames (no need to process all 100 frames of video, 3-5 frames should be enough)

/cc @dmatveev

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. Done


namespace cv { namespace detail {
template<> struct CompileArgTag<cv::gapi::video::BackgroundSubtractorParams>
{
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.

avoid indentation in namespaces

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.

Changed.

double threshold = 16; //!< For MOG2: Threshold on the squared Mahalanobis distance between
//!< the pixel and the model to decide whether a pixel is well described by the background model.
//!< For KNN: Threshold on the squared distance between the pixel and the sample to decide
//!< whether a pixel is close to that sample.
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 better to keep multi-line comments before declaration to avoid excessive indentations.

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.

I did as you said on the previous step, but doxygen misinterpreted the comments in this arrangement. @OrestChura can confirm my words. He also observed this behavior. I can prove it by rolling back, but I don't want to waste time on it. So I would rather leave it as it is now.

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.

misinterpreted the comments
//!<

Please learn how to use doxygen comments: https://www.doxygen.nl/manual/docblocks.html

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. Thanks for prompt. Changed

} // namespace gapi
} // namespace cv


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.

unnecessary change

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.

Removed.

@anna-khakimova anna-khakimova force-pushed the ak/backgroundSubtractor branch 3 times, most recently from c1fb3a5 to e5ed281 Compare November 26, 2020 17:35
@anna-khakimova anna-khakimova force-pushed the ak/backgroundSubtractor branch 3 times, most recently from c0b2f0c to 0bcc830 Compare November 26, 2020 18:21
@anna-khakimova
Copy link
Copy Markdown
Member Author

anna-khakimova commented Nov 26, 2020

@OrestChura please take a look one more time. And if it's ok please remove change request and approve.

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.

I don't see any other obstacles to merge it! Thank you!

@anna-khakimova
Copy link
Copy Markdown
Member Author

@alalek please check.

Comment on lines +114 to +120
try
{
gapiBackSub.setSource(gapi::wip::make_src<cv::gapi::wip::GCaptureSource>
(findDataFile(filePath)));
}
catch (...)
{ throw SkipTestException("Video file can't be opened."); }
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 out findDataFile call from try-catch block. We don't want to suppress its exceptions.

catch (...)

it make sense to capture const cv::Exception& only.
/cc @mpashchenkov

@anna-khakimova anna-khakimova force-pushed the ak/backgroundSubtractor branch 2 times, most recently from 88eca7f to 5d66c72 Compare November 30, 2020 10:52
@anna-khakimova anna-khakimova force-pushed the ak/backgroundSubtractor branch from 5d66c72 to 8ca1f57 Compare November 30, 2020 15:36
Copy link
Copy Markdown
Member

@alalek alalek left a comment

Choose a reason for hiding this comment

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

LGTM

@alalek alalek merged commit 56568da into opencv:master Nov 30, 2020
@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
…ractor

GAPI: New BackgroundSubtractor stateful kernel

* New BackgroundSubtractorMOG2 kernel

* Add BS parameters
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.

4 participants