Opencv Motion detection with tracking

2019-03-16 09:30发布

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.

3条回答
Viruses.
2楼-- · 2019-03-16 09:53

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.

查看更多
我想做一个坏孩纸
3楼-- · 2019-03-16 10:02

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

查看更多
看我几分像从前
4楼-- · 2019-03-16 10:05

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,

查看更多
登录 后发表回答