Updated grabcut example to show the background in a transparant way#20200
Updated grabcut example to show the background in a transparant way#20200opencv-pushbot merged 1 commit intoopencv:3.4from
Conversation
|
Update: fixed whitespace. Hopefully my build passes this time :) |
|
Thanks for useful improvement. This patch should go into 3.4 branch first. We will merge changes from 3.4 into master regularly (weekly/bi-weekly). So, please:
Note: no need to re-open PR, apply changes "inplace". |
|
Done. Thanks for the great explanation, that was really helpful! |
samples/cpp/grabcut.cpp
Outdated
|
|
||
| Mat black (binMask.rows, binMask.cols, CV_8UC3, cv::Scalar(0,0,0)) ; | ||
| Mat white (binMask.rows, binMask.cols, CV_8UC3, cv::Scalar(255,255,255)) ; | ||
| add(black, white, black, binMask); |
There was a problem hiding this comment.
black.setTo(Scalar::all(255), binMask)
There was a problem hiding this comment.
Great proposal, changed!
samples/cpp/grabcut.cpp
Outdated
| image->copyTo( res ); | ||
| if( isInitialized ){ | ||
| getBinMask( mask, binMask); | ||
| image->copyTo( res ); |
There was a problem hiding this comment.
Why do we call image->copyTo( res ); twice?
There was a problem hiding this comment.
Good question... Removed :)
b4163fe to
5b2e7ca
Compare
|
I think that |
|
I can go over the logic this weekend to make it a bit better :) |
|
@rmeertens Friendly reminder. |
1 similar comment
|
@rmeertens Friendly reminder. |
|
Thanks for the reminder! Just back from a two-week trip, will update it this week! |
5e96aaf to
2113af9
Compare
|
Finally had time to go over this pull request again! I now actually verify that we are in the correct state when calling nextIter. The other problem I found, which was the actual reason for the crash, is that clicking produces an empty rectangle. Whenever someone tries to draw an empty rectangle we just go back to the state 'rectangle not set'. Hope this helps :) Let me know if you find any other bugs/problems! |
asmorkalov
left a comment
There was a problem hiding this comment.
Works for me without crashes. 👍
Hey all, I was playing around with the Grabcut example (https://docs.opencv.org/3.4/d8/d83/tutorial_py_grabcut.html) and was annoyed that the background is completely black, instead of showing the original image in a transparant way.
I updated the code to make it transparant. I also made the application a bit more interactive, so you don't have to press 'n' any time you add some foreground or background, but it automatically runs at least one cycle.
Image of the result:

Let me know if you have any feedback :)