具有跟踪功能的Opencv运动检测 [英] Opencv Motion detection with tracking

查看:85
本文介绍了具有跟踪功能的Opencv运动检测的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要对网络摄像头的视频帧进行强大的运动检测和跟踪.背景总是一样的.目的是确定对象的位置,如果可能的话,没有阴影,但不急于去除阴影.我已经尝试过使用opencv算法进行背景减法和阈值化,但这仅取决于一张图像作为背景,如果背景亮度略有变化(或相机自动对焦),我需要该算法对于亮度或阴影变化不大.

解决方案

在OpenCV中尝试阈值处理时,是使用RGB(红色,绿色,蓝色)或HSV(色相,饱和度,值)颜色格式来进行此设置吗?从个人经验来看,我发现将HSV编码与OpenCV一起用于阈值检测和cvBlobsLib一起用于识别斑点位置时,在跟踪视频中的彩色对象方面要好得多.

HSV更容易,因为HSV的优点是,尽管存在非常实际的可能性,即从浅色到较深的颜色都有多种阴影,但HSV只需使用一个数字即可检测颜色(色相").阴影. (颜色的数量和颜色的亮度分别通过饱和度"和值"参数进行处理.)

使用对cvInRange()OpenCV API的调用,对HSV参考图像('imgHSV')设置阈值以获得二进制(黑白)图像:

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

在上面的示例中,两个cvScalar参数分别是HSV值的上限和下限,该值表示蓝色的色调.在我自己的实验中,我可以通过抓取我感兴趣的对象的屏幕快照来获取一些合适的最大值/最小值,该对象有兴趣跟踪并观察出现的色相/饱和度/亮度值的种类.

可以在此博客发布上找到带有代码示例的更详细说明.. >

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.

解决方案

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.

这篇关于具有跟踪功能的Opencv运动检测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆