如何使用OpenCV作为运动检测器(而不是寻找视频输出)

how to use openCV as a motion detector (not looking for video output)

本文关键字:寻找 视频 输出 检测器 OpenCV 何使用 运动检测 运动      更新时间:2023-10-16

我对c++很陌生,并且一直在对openCV进行大量研究。 我目前正在使用网络摄像头制作一个运动检测器,并尝试使用它来触发功能(有点像听众(。我的应用程序中不需要任何类型的视觉视频。例如,我只需要感知运动并给出像布尔值一样的输出。

我对java更熟悉,但它必须用c ++编写,没有包装器,没有转换器。

有人可以帮我指出写作方向吗? 也许有一个教程或建议我应该查找的东西。甚至我应该使用不同的库而不是 openCV。

作为起点,我建议使用基本的图像减法,然后从那里开始。

基本算法是:

firstFrame = readFrame()
firstFrameGrey = convertToGreyScale(firstFrame) // makes the image B&W
while True
secondFrame = readFrame()
secondFrameGrey = convertToGreyScale(secondFrame)
difference = sub(firstFrameGrey, secondFrameGrey)
threshold()
// perform some morphological operations
erosion()
dilation()
findContours()
// loop over contours and try filtering based off of area, perimeter etc.
// This filtration will allow you to detect significant changes.
// update frame
firstFrameGrey = secondFrameGrey

对于形态操作,尝试不同的值,看看你得到的结果。

有关阈值的详细信息

本教程介绍如何执行形态操作。

可在此处找到等值线信息以及区域 API

算法应该是不言自明的,openCV具有我命名的所有方法。