Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementation of Global sampling based matting #2278

Open
wants to merge 3 commits into
base: 4.x
Choose a base branch
from

Conversation

Nerdyvedi
Copy link

@Nerdyvedi Nerdyvedi commented Sep 30, 2019

Merge with extra: opencv/opencv_extra#682

This is the C++ implementation of Global sampling based method for alpha matting

Copy link
Contributor

@asmorkalov asmorkalov left a comment

Choose a reason for hiding this comment

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

The patch breaks build, please fix it:

/build/precommit-contrib_linux64/opencv_contrib/modules/ximgproc/test/test_globalmatting.cpp:16:7: error: 'class opencv_test::{anonymous}::CV_GlobalMattingTest' has virtual functions and accessible non-virtual destructor [-Werror=non-virtual-dtor]
 class CV_GlobalMattingTest
       ^
/build/precommit-contrib_linux64/opencv_contrib/modules/ximgproc/test/test_globalmatting.cpp: In member function 'void opencv_test::{anonymous}::CV_GlobalMattingTest::runModel()':
/build/precommit-contrib_linux64/opencv_contrib/modules/ximgproc/test/test_globalmatting.cpp:38:5: error: 'ts' was not declared in this scope
     ts->printf(cvtest::TS::LOG,"Test images not found!\n");
     ^
/build/precommit-contrib_linux64/opencv_contrib/modules/ximgproc/test/test_globalmatting.cpp:44:5: error: 'ts' was not declared in this scope
     ts->printf(cvtest::TS::LOG,"Dimensions of trimap and the image are not the same");
     ^
/build/precommit-contrib_linux64/opencv_contrib/modules/ximgproc/test/test_globalmatting.cpp:53:5: error: 'ts' was not declared in this scope
     ts->printf(cvtest::TS::LOG,"Could not find the alpha matte for the image\n");
     ^
/build/precommit-contrib_linux64/opencv_contrib/modules/ximgproc/test/test_globalmatting.cpp:60:5: error: 'ts' was not declared in this scope
     ts->printf(cvtest::TS::LOG,"The dimensions of the output are not correct");
     ^
/build/precommit-contrib_linux64/opencv_contrib/modules/ximgproc/test/test_globalmatting.cpp: In member function 'virtual void opencv_test::{anonymous}::CV_GlobalMattingTest_accuracy_Test::Body()':
/build/precommit-contrib_linux64/opencv_contrib/modules/ximgproc/test/test_globalmatting.cpp:80:8: error: 'class opencv_test::{anonymous}::CV_GlobalMattingTest' has no member named 'safe_run'
   test.safe_run();
        ^
cc1plus: some warnings being treated as errors

modules/ximgproc/CMakeLists.txt Outdated Show resolved Hide resolved
@asmorkalov
Copy link
Contributor

@Nerdyvedi Do you have any progress on the patch?

@Nerdyvedi
Copy link
Author

@asmorkalov Just give me this weekend, I will fix this

@Nerdyvedi
Copy link
Author

@asmorkalov Could you please take a look at what's wrong, I don't think the issue is with my code

modules/ximgproc/src/globalmatting.cpp Outdated Show resolved Hide resolved
modules/ximgproc/src/globalmatting.cpp Outdated Show resolved Hide resolved
modules/ximgproc/src/globalmatting.cpp Outdated Show resolved Hide resolved
modules/ximgproc/src/globalmatting.cpp Outdated Show resolved Hide resolved
modules/ximgproc/src/globalmatting.cpp Outdated Show resolved Hide resolved
modules/ximgproc/src/globalmatting.cpp Outdated Show resolved Hide resolved
const std::string TRIMAP_FILENAME = "trimap/doll.png";


void runModel()
Copy link
Member

Choose a reason for hiding this comment

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

static to make function local.

modules/ximgproc/tutorials/globalmatting.md Outdated Show resolved Hide resolved
@Nerdyvedi
Copy link
Author

@alalek , Buildbot is giving a patch size error, Even though I have squashed my commits. Is it because I have commited 9 images for the tutorial

@alalek
Copy link
Member

alalek commented Dec 1, 2019

modules/ximgproc/tutorials/images/doll-input.png

PNG format is not very good for real-life content.
Consider converting these "input" tutorials images into JPEG format.
Using PNG makes sense in tests only (lossless input).


Ignore size warning for now ("delete PNG" can't remove data from git history)

@Nerdyvedi
Copy link
Author

@alalek I have made the changes you asked for, There is a patch size error, Could you let me know how to solve it?

Nerdyvedi and others added 2 commits December 28, 2019 21:40
Add files via upload
Add files via upload
Add files via upload
Update README.md
Update and rename mattingClass.cpp to globalmatting.cpp
Rename mattingClass.h to globalmatting.h
Update and rename globalmatting.h to globalmatting.hpp
Update globalmatting.cpp
Add files via upload
Update global_matting_sample.cpp
Update test_global_matting.cpp
Update globalmatting.cpp
Update globalmatting.hpp
Update globalmatting.hpp
Update globalmatting.cpp
Update globalmatting.cpp
Update globalmatting.hpp
Update globalmatting.hpp
Update ximgproc.hpp
Update ximgproc.hpp
Update ximgproc.hpp
Update CMakeLists.txt
Update globalmatting.hpp
Update globalmatting.hpp
Update globalmatting.hpp
Update globalmatting.hpp
Update globalmatting.hpp
Update globalmatting.cpp
Update globalmatting.cpp
Update test_global_matting.cpp
Update test_global_matting.cpp
Update test_global_matting.cpp
Update global_matting_sample.cpp
Update globalmatting.cpp
Update globalmatting.hpp
Removing trailing whitespaces
Removing whitespaces
Rename global_matting_sample.cpp to globalmatting.cpp
Rename test_global_matting.cpp to test_globalmatting.cpp
Update globalmatting.cpp
Update globalmatting.cpp
Update globalmatting.cpp
Update globalmatting.cpp
Update globalmatting.cpp
Update test_globalmatting.cpp
Update test_globalmatting.cpp
Update test_globalmatting.cpp
Update globalmatting.hpp
Update globalmatting.cpp
Update test_globalmatting.cpp
Removing whitespaces
Removed whitespaces
Update test_globalmatting.cpp
Update test_globalmatting.cpp
Update test_globalmatting.cpp
Update globalmatting.cpp
Removing global structure from header file
Added the global structure into cpp file
Added license and removed extra header files
Added License information
Removed whitespaces
Update globalmatting.cpp
Create globalmatting.md
Update globalmatting.md
Update globalmatting.md
Removed square function from the public header
Added the square function to the source file
Added license information and removed BaseTest
Using cvtest::findDatafile
Bringing y to outer loop and x in inner loop
Added license information to sample
Update test_globalmatting.cpp
Removed trailing whitespaces
Update README.md
Update README.md
Update globalmatting.md
Not using BaseTest legacy code anymore

Put all the testing code in the Test()
Fixed buildbot errors
Fixed syntactical errors
Fixed whitespace errors
Removing highgui dependency

It is redundant for the module
Removed highgui header file

highgui module is not used in header files
Using CV_CheckTypeEQ function
Fixed buildbot errors
Fixed whitespace errors
Added __OPENCV_XIMGPROC prefix and _HPP___ suffix
Removed unnecessary header files
Using Scalar::all(0) instead of (uchar)0
Replacing Scalar::all(0) with cv::Scalar::all(0)
Replacing Scalar::all(0) with (uchar)0
Using opencv's random function
Removed whitespace errors
Added images used in tutorials
No external links on embedded images are now used
Fixed image path error

Removing png input

Removing png input

Removing input png

Removing trimap png

Removing trimap png

Removing trimap png

Uploading jpg files

Update globalmatting.md

Bringing y to outer loop

Using normL2Sqr function
- moved out implementation details from public API
- don't use cv::
- more checks
- updated test
@alalek
Copy link
Member

alalek commented Dec 28, 2019

I rebased patch and cleanup code according OpenCV coding style guide.

Added reference test data check into test shows that result is unstable. Please take a look.

P.S. Fetch code from your fork directly, don't try to "rebase" or "merge".

Point p(x, y);

samples[y][x].fi = rand() % foregroundBoundary.size();
samples[y][x].bj = rand() % backgroundBoundary.size();
Copy link
Member

Choose a reason for hiding this comment

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

Avoid using rand() anywhere.
It is not stable and sometimes it is not thread safe. We need reproducible results for automated tests.

Consider using of OpenCV's thread local theRNG() implementation.

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.

3 participants