简体   繁体   English

帧差噪声?

[英]Frame difference noise?

I'm attempting to detect motion using frame difference. 我正在尝试使用帧差来检测运动。 If there is a motion, I will enter another method, if not, I will not enter that method. 如果有动作,我会输入另一种方法,如果没有,我将不会输入该方法。 The problem is when I make frame difference by using either absdiff(), or bitwise_xor(), I get a noisy frame, that is always detected as a motion. 问题是当我通过使用absdiff()或bitwise_xor()来制作帧差异时,我得到一个嘈杂的帧,它总是被检测为一个运动。

I tried to remove that noise by using erode() and dilate() methods, it decreases the effect of the noise, but still there is noise. 我试图通过使用erode()和dilate()方法消除噪音,它降低了噪音的影响,但仍有噪音。 How can I remove this noise ? 我怎样才能消除这种噪音?

Part of my current code: 我当前代码的一部分:

capture >> Frame; // get a new frame from camera

cvtColor(Frame,Frame1,CV_RGB2GRAY);
threshold(Frame1,Frame1,50,255,CV_THRESH_BINARY);

waitKey(500);
capture >> PreFrame;

cvtColor(PreFrame,PreFrame,CV_RGB2GRAY);
threshold(PreFrame,PreFrame,50,255,CV_THRESH_BINARY);

//Result = Frame1 - PreFrame1;
//absdiff(Frame1,PreFrame1,Result);

bitwise_xor(Frame1,PreFrame,Result);
erode(Result,Result,Mat());
dilate(Result,Result,Mat());

imshow("Result",Result);

if (norm(Result,NORM_L1)==0){
    printf(" no change \n")
}
else
{
    // motion detected
}

You can reduce noise a few different ways just applying one of the following techniques right after capturing the frame: 在捕获帧后立即使用以下技术之一,您可以通过几种不同的方式降低噪声:

Blurring (averaging within the frame) 模糊(帧内平均)

Have a look at a few different blur operators like: 看看几个不同的模糊运算符,如:

  1. blur (fast, but less smooth) 模糊 (快速,但不太流畅)
  2. GaussianBlur (slower, but smoother) GaussianBlur (慢,但更平滑)
  3. medianBlur (reduces impulse noise) medianBlur (降低脉冲噪音)

medianBlur is good for controlling impulse noise while preserving edges in the image. medianBlur有助于控制脉冲噪声,同时保留图像中的边缘。

Frame averaging (average different frames) 帧平均(平均不同帧)

  1. accumulate 积累
  2. accumulateWeighted accumulateWeighted

With frame averaging just divide the accumulated result by the number of frames accumulated to get the averaged frame. 对于帧平均,仅将累积结果除以累积的帧数以获得平均帧。 You probably want a rolling average window of say 5-10 frames to reduce the noise significantly. 你可能想要一个5-10帧的滚动平均窗口来显着降低噪音。 However, higher window sizes means more motion blurring when objects move in and out of the field of view. 但是,当对象移入和移出视野时,较高的窗口大小意味着更多的运动模糊。 This will work best if your camera is motionless. 如果您的相机不动,这将最有效。

Hope that helps! 希望有所帮助!

What happens if take the absolute difference of your grayscale images, and then threshold the result to remove small intensity changes? 如果获取灰度图像的绝对差异,然后将结果阈值移除以消除小的强度变化,会发生什么? This would allow small variations in pixel intensity frame-to-frame, while still triggering your motion detector if there were any significant changes. 这将允许帧到帧的像素强度的微小变化,同时如果有任何显着变化仍然触发您的运动检测器。

For example: 例如:

// Obtain image two images in grayscale
cvtColor(Frame,Frame1,CV_RGB2GRAY);
cvtColor(PreFrame,PreFrame,CV_RGB2GRAY);

// Take the absolute difference, this will be zero for identical
// pixels, and larger for greater differences
absdiff(Frame, PreFrame, Result)

// Threshold to remove small differences
threshold(Result,Result,20,255,CV_THRESH_BINARY);

// Prepare output, using Result as a mask
Mat output = Mat::zeros(Frame.size(), Frame.type());
add(
    Frame,   // Add frame
    0,       // and zero
    output,  // to output
    Result   // Only if result is non-zero
);

Do you have any example input/output images you are able to share? 您是否有可以共享的示例输入/输出图像?

By thresholding your images before you take the difference, you're multiplying the effect of the noise greatly. 通过在拍摄差异之前对图像进行阈值处理,可以大大增加噪声的影响。 Do the subtraction on the grayscale images directly with absdiff instead of bitwise_xor . 直接用absdiff而不是bitwise_xor对灰度图像进行bitwise_xor

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM