简体   繁体   English

当从凸轮检测到运动时,OpenCv C ++记录视频

[英]OpenCv C++ record video when motion detected from cam

I am attempting to use a straightforward motion detection code to detect movement from a camera. 我正在尝试使用简单的运动检测代码来检测摄像机的运动。 I'm using the OpenCV library and I have some code that takes the difference between two frames to detect a change. 我正在使用OpenCV库,并且我有一些代码利用两个框架之间的差异来检测更改。

I have the difference frame working just fine and it's black when no motion is present. 我的差速器框架工作得很好,没有运动时它是黑色的。

The problem is how now i can detect that blackness to stop recording or no darkness to begin recording frames. 问题是,现在我如何才能检测到该黑度停止记录或没有黑暗开始记录帧。

Thank u all. 谢谢大家

A very simple thing to do is to sum the entire diff image into an integer. 一个非常简单的事情是将整个diff图像求和成一个整数。 If that sum is above a threshold you have movement. 如果该总和超过阈值,则您可以移动。 Then you can use a second threshold and when the sum is below that limit you stopped having movement. 然后,您可以使用第二个阈值,并且当总和低于该限制时,您将停止移动。

You can also make the threshold only change the program state if some elapsed time has occurred since the last threshold. 您也可以使阈值仅在自上一个阈值以来已经过了一段时间才更改程序状态。 ie after movement is detected you don't check for lack of movement for 10 seconds. 即,在检测到运动之后,您将在10秒钟内不检查运动是否不足。

What about storing a black frame internally and using your same comparison code? 如何在内部存储黑框并使用相同的比较代码呢? If your new frame is different (above a threshold) from the all-black frame, start recording. 如果新帧与全黑帧不同(超过阈值),则开始录制。

This seems the most straightforward since you already have the image-processing algorithms down. 这似乎是最简单的方法,因为您已经降低了图像处理算法的效率。

Take a look at the code of the free software motion for getting inspiring ideas. 查看自由软件运动的代码以获取启发性的想法。

There are quite a few things to keep in mind for reliable motion detection. 要进行可靠的运动检测,需要牢记许多注意事项。 For example tolerate the slow changes from the sun's rotation. 例如,可以忍受太阳旋转带来的缓慢变化。 Or accepting momentary image glitches which can come especially from the cheapest cameras. 或者接受瞬时图像故障,这些故障尤其可能来自最便宜的相机。

From a small experience I have had, I think that better than just adding up all differences, it works better to count the number of pixels whose variation exceeds a certain threshold. 从我的少量经验来看,我认为比将所有差异相加更好,它可以算出变化超过特定阈值的像素数。

Motion also offers masks, which let you for example ignore movements in a nearby road. Motion还提供了遮罩,例如,您可以忽略附近道路的运动。

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

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