Opencv 运动检测与跟踪

发布于 2024-11-28 21:30:55 字数 162 浏览 0 评论 0原文

我需要在网络摄像头的视频帧中进行强大的运动检测和跟踪。背景总是一样的。目的是识别物体的位置,如果可能的话没有阴影,但并不急于去除阴影。我已经尝试过用于背景减法和阈值处理的opencv算法,但这仅取决于一个图像作为背景,如果背景的亮度(或相机自动对焦)发生一点变化怎么办,我需要算法强大亮度或一些阴影等变化很小。

I need a robust motion detection and tracking in web cam's video frames. The background is always the same. The aim is to identify the position of the object, if possible without the shadows, but not so urgent to remove shadows. I've tried the opencv algorithm for background subtraction and thresholding, but this depends on only one image as a background, what if the background changes a little bit in brightness (or camera auto-focus), I need the algorithm to be strong for little changes as brightness or some shadows.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

蹲在坟头点根烟 2024-12-05 21:30:55

强大的跟踪方法是世界各地正在开发的广泛研究兴趣的一部分......
以下可能是解决您的问题的关键,该问题非常有趣但广泛且开放。

首先,他们中的很多人都假设亮度恒定(因此你所要求的很难实现)。例如:

  • Lucas-Kanade
  • Horn-Schunk
  • 块匹配

广泛用于跟踪,但假设亮度恒定。

然后其他有趣的可能是均值平移或凸轮平移跟踪,但您需要遵循一个投影...但是您可以使用根据特定阈值计算的反投影来满足您对鲁棒性的需求...

我稍后会发布相关内容,
朱利安,

Robust method for tracking are part of broad research interests that are being developed all around the world...
Here are maybe keys to solve your problem that is very interesting but wide and open.

First a lot of them assumes brightness constancy (therefore what you ask is difficult to achieve). For instance:

  • Lucas-Kanade
  • Horn-Schunk
  • Block-matching

is widely used for tracking but assumes brightness constancy.

Then other interesting ones could be meanshift or camshift tracking, but you need a projection to follow... However you can use a back-projection computed accordingly to certain threshold to fit your needs for robustness...

I'll post later about that,
Julien,

浅忆流年 2024-12-05 21:30:55

当您在 OpenCV 中尝试阈值处理时,您是使用 RGB(红、绿、蓝)还是 HSV(色调、饱和度、值)颜色格式来执行此操作?根据个人经验,我发现 HSV 编码在与 OpenCV 结合使用进行阈值处理和与 cvBlobsLib 结合使用来识别斑点位置时,在跟踪视频片段中的彩色对象方面要优越得多。

HSV 更容易,因为 HSV 的优点是只需使用单个数字来检测颜色(“色调”),尽管该颜色很可能存在多种色调(从浅色到深色)。 (颜色的量和颜色的亮度分别由“饱和度”和“值”参数处理)。

我使用 cvInRange() OpenCV API 对 HSV 参考图像 ('imgHSV') 进行阈值处理,以获得二值(黑白)图像:

cvInRangeS( imgHSV,  
            cvScalar( 104, 178, 70  ),  
            cvScalar( 130, 240, 124 ),  
            imgThresh ); 

在上面的示例中,两个 cvScalar 参数是 HSV 值的下限和上限,即代表蓝色的色调。在我自己的实验中,我能够通过抓取我有兴趣跟踪和观察发生的色调/饱和度/亮度值类型的对象的屏幕截图来获得一些合适的最大/最小值。

可以在此博客文章中找到带有代码示例的更详细说明。

When you try the thresholding in OpenCV are you doing this with RGB (red,green,blue) or HSV (hue,saturation,value) colour formats? From personal experience, I find the HSV encoding to be far superior for tracking coloured objects in video footage when used in conjunction with OpenCV for thresholding and cvBlobsLib for identifying the blob location.

HSV is easier since HSV has the advantage of only having to use a single number to detect the colour (“hue”), in spite of the very real probability of there being several shades of that colour, ranging from light to darker shades. (The amount of colour and the brightness of the colour are handled by the “saturation” and “value” parameters respectively).

I threshold the HSV reference image ('imgHSV') to obtain a binary (black and white) image using a call to the cvInRange() OpenCV API:

cvInRangeS( imgHSV,  
            cvScalar( 104, 178, 70  ),  
            cvScalar( 130, 240, 124 ),  
            imgThresh ); 

In the above example, the two cvScalar parameters are lower and upper bounds of HSV values that represents hues that are blueish in colour. In my own experiments I was able to obtain some suitable max/min values by grabbing screenshots of the object(s) I was interested in tracking and observing the kinds of hue/saturation/lum values that occur.

More detailed descriptions with a code sample can be found on this blog posting.

辞慾 2024-12-05 21:30:55

Andrian 有一个很酷的教程 http://www.pyimagesearch.com/2015/05/25/basic-motion-detection-and-tracking-with-python-and-opencv/

我关注了并且有一个好的实验测试
https://youtu.be/HJBOOZVefXA

我也使用静态图像,

frameDelta = cv2.absdiff(firstFrame, gray)
thresh = cv2.threshold(frameDelta, 25, 255, cv2.THRESH_BINARY)[1]
thresh = cv2.dilate(thresh, None, iterations=2)
(cnts, _) = cv2.findContours(thresh.copy(), cv2.RETR_EXTERNAL,
cv2.CHAIN_APPROX_SIMPLE)

4行代码可以很好地找到运动
祝你好运

Andrian has a cool tutorial http://www.pyimagesearch.com/2015/05/25/basic-motion-detection-and-tracking-with-python-and-opencv/

I followed and have an good experiment test
https://youtu.be/HJBOOZVefXA

I use static image as well

frameDelta = cv2.absdiff(firstFrame, gray)
thresh = cv2.threshold(frameDelta, 25, 255, cv2.THRESH_BINARY)[1]
thresh = cv2.dilate(thresh, None, iterations=2)
(cnts, _) = cv2.findContours(thresh.copy(), cv2.RETR_EXTERNAL,
cv2.CHAIN_APPROX_SIMPLE)

4 lines code find motion well
good luck

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文