开发者

EmguCV/OpenCV Image addition/subtraction

开发者 https://www.devze.com 2022-12-11 01:25 出处:网络
I am using EmguCV and am trying to subtract 2 images to create a filter similar to AForge .NET\'s MoveTowards filter.

I am using EmguCV and am trying to subtract 2 images to create a filter similar to AForge .NET's MoveTowards filter.

This is what my slightly modified version from the above URL tries to do. Given 2 images, the source and the overlay - it slowly moves the source image towards the overlay. It does this based on the following:

re开发者_JAVA技巧sult = source + movementFactor * (overlay - source);

where result, source and overlay are images and movementFactor is the rate of change in the range 0 to 1.

When I tried this in code with movementFactor equal to 1, the results looked messed up (there was something like a motion trail). To test it further, I removed movementFactor from the above equation, and made result = source + overlay - source. I expected to see the overlay image as the result, which I did, but along with one region of the image that was flashing.

I am guessing that pixel intensities get clipped in the upper or lower bounds when addition/subtraction takes place.

I can accomplish what I want with this:

for (int i = 0; i < src.Height; i++)
{
    for (int j = 0; j < src.Width; j++)
    {
        res[i, j] = new Gray(src[i, j].Intensity + movementFactor * (ovr[i, j].Intensity - src[i, j].Intensity));
    }
}

But this significantly slows down the processing. How can I overcome the addition/subtraction problem or the speed problem with the above? Thanks for your answers!


I will post the answer I found over here, in case someone runs across the same issue in the future.

This is how you would do it:

Image<Gray,Byte> result = new Image<Gray,Byte>(source.Size);
CvInvoke.cvAddWeighted(source, 1.0-movementFactor, overlay, movementFactor, 0.0, result);

Source: EmguCV's forums, here is the post that gave me the reply


I will post the answer I found over here, in case someone runs across the same issue in the future.

This is how you would do it:

Image<Gray,Byte> result = new Image<Gray,Byte>(source.Size);
CvInvoke.cvAddWeighted(source, 1.0-movementFactor, overlay, movementFactor, 0.0, result); 

Source: EmguCV's forums, here is the post that gave me the reply

Note that there is a cleaner syntax for that:

var result = frame.AddWeighted(1.0 - movementFactor, overlay, movementFactor, 0.0);
0

精彩评论

暂无评论...
验证码 换一张
取 消