-
Notifications
You must be signed in to change notification settings - Fork 84
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
Alpha-blending using smoothed mask #72
Conversation
@@ -76,6 +76,29 @@ cv::Mat convert_rgb_to_yuyv( cv::Mat input ) { | |||
return yuyv; | |||
} | |||
|
|||
cv::Mat alpha_blend(cv::Mat srca, cv::Mat srcb, cv::Mat mask) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't there something for this already in OpenCV?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nothing obvious: it has a constant alpha blend function addWeighted
, and masked binary blending via copyTo
or add
each with a mask parameter.
There is the usual half answered SO question: https://stackoverflow.com/questions/41263010/how-to-blend-images-using-a-mask-in-opencv and an unanswered OpenCV forum one: https://answers.opencv.org/question/28439/blending-two-images-with-masked-roi/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Searching their "new" forums I stumbled upon:
https://forum.opencv.org/t/opencv-java-how-to-superimpose-three-images-that-have-the-same-size/857/2
This links to this blog post:
https://learnopencv.com/alpha-blending-using-opencv-cpp-python/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Heh - literally where I got my code from..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
One possible option might be to avoid the division by 255 and try to get this somehow to use a division by 256. But that for another time …
Initial timing measurements indicate this adds 0.5-1.0 msec to the post-processing compared to |
Ah, that's a good idea, thanks. What happens if I cherry-pick this into main, would that mess anything up down the line? |
No, this should be fine. Git detects when you merge things where you've had the same patch applied already. |
* Alpha-blending using smoothed mask * Tidy up alpha blending, avoid float math
Using a smoothed segmentation mask to alpha blend between background and foreground (captured video), this is a simple not-quite-light-wrapping (there is no blurred background component) fix to the hard edges we have presently. Might address #67.
For reference: https://www.premiumbeat.com/blog/what-is-light-wrapping-tips-tutorials/ provides a reasonable description of light wrapping.