c++visual-c++opencvkinect

Animate my Detected objects in OpenCV


I was wondering how it is possible to create effects like a glowing ball or a glowing line in my video frames in OpenCV. Any tips on where I can start or what can I use so I can create simple animations in my output?

Thanks in advance!


Solution

  • These effects are simple to accomplish with primitive OpenCV pixel operations. Let's say you have your ball identified as a white region in a separate mask image mask. Blur this mask with GaussianBlur and then combine the result with your source image img. For a glow effect, you probably want something like Photoshop's Screen blending mode, which will only brighten the image:

    Result Color = 255 - [((255 - Top Color)*(255 - Bottom Color))/255]

    The real key to the "glow" effect is using the pixels in the underlying layer as the screen layer. This translates to OpenCV:

    cv::Mat mask, img;
    ...
    mask = mask * img; //fill the mask region with pixels from the original image
    cv::GaussianBlur(mask, mask, cv::Size(0,0), 4); //blur the mask, 4 pixels radius
    mask = mask * 0.50; //a 50% opacity glow
    img = 255 - ((255 - mask).mul(255 - img) / 255); //mul for per-element multiply
    

    I did not test this code, so I might have something wrong here. Color Dodge is also a useful blending mode for glows. More here: How does photoshop blend two images together?