Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Opencv Motion detection with tracking

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.

like image 628
maximus Avatar asked Aug 11 '11 02:08

maximus


2 Answers

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,

like image 142
jmartel Avatar answered Oct 08 '22 10:10

jmartel


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.

like image 39
AndyUK Avatar answered Oct 08 '22 10:10

AndyUK