1

I'm running a process on a WebCam Image. I'd like to Wake Up that process only if there is major changes.

  • Something moving in the image
  • Lights turn on
  • ...

So i'm looking for a fast efficient algorithm in C# to compare 2 byte[] (kinect image) of the same size.

  • I just need kind of "diff size" with a threashold
  • I found some motion detection algorithm but it's "too much"
  • I found some XOR algorithm but it might be too simple ? Would be great If I could ignore small change like sunlight, vibration, etc, ...
Jean-Philippe Encausse
  • 1,491
  • 2
  • 22
  • 40
  • If you want to avoid glitches, which effects a couple of frames only (like a camera flash from outside), but then everything gets back to normal, then you need an algorithm which doesn't only compare two consecutive images, but it remembers more frames in the past. You can look various filtering algorithms, which memory is longer. – Csaba Toth Aug 12 '13 at 23:17
  • The motion detection algorithm identifies actual moving objects? Why is it too much? – Csaba Toth Aug 12 '13 at 23:17
  • 1
    http://stackoverflow.com/questions/843972/image-comparison-fast-algorithm – SSpoke Aug 12 '13 at 23:26
  • Use the infrared sensor of Kinect! – Csaba Toth Aug 13 '13 at 18:25

2 Answers2

1

A concept: MPEG standards involve motion detections. Maybe you can monitor the MPEG stream's bandwidth. If there's no motion, than the bandwidth is very low (except during key frames (I frames)). If something changes and any move is going on, the bandwidth increases.

So what you can do is grab the JPEGs and feed it into an MPEG encoder codec. Then you can just look at the encoded stream. You can tune the frame-rate and the bandwidth too in a range, plus you decide what is the threshold for the output stream of the codec which means "motion".

Advantage: very generic and there are libraries available, often they offer hardware acceleration (VGAs/GPUs help with JPEG en/decoding and some or more MPEG). It's also pretty standard. Disadvantage: more computation demanding than a XOR.

Csaba Toth
  • 10,021
  • 5
  • 75
  • 121
  • That's smart ! Unfortunatly I only have a Kinect byte[] and would like to low computation. – Jean-Philippe Encausse Aug 13 '13 at 07:35
  • Wow, a Kinect! Sounds interesting! I wonder if any Kinect related library/software may offer what you look for. I have a feeling you are not the only one who is looking for motion detection. I think Kinect can easily identify if a scene is static or not! It's a piece of cake for Kinect compared to even identify body parts and gestures! – Csaba Toth Aug 13 '13 at 15:38
1
  1. Mark all pixels which are different from previous image (based on threshold i.e. if Pixel has been changed only slightly - ignore it as noise) as 'changed'

  2. Filter out noise pixels - i.e. if pixel was marked as changed but all its neighbors are not - consider it as noise and unmark as changed

  3. Calculate how many pixels are changed on the image and compare with Threshold (you need to calibrate it manually)

  4. Make sure you are operating on Greyscale images (not RGB). I.e. convert to YUV image space and do comparison only on Y.

This would be simplest and fastest algorithm - you just need to tune these two thresholds.

  • Thanks it look like that what OpenCV did. I'll look into it – Jean-Philippe Encausse Aug 13 '13 at 07:38
  • Do you have any links to articles or publications about that? – Csaba Toth Aug 13 '13 at 15:25
  • One addition knowing that it's Kinect: use Kinect's infrared sensor. @AlexTheDeveloper mentions greyscale, Y component of YUV from the visible spectrum. Infrared is much better especially if you want to detect movement of humans or other mammals, warm blooded species. – Csaba Toth Aug 13 '13 at 15:40
  • Csaba, I don't have any links to publication but this is the simpliest approach that works and indeed was implemented in some read video surveillance system (we had same requirements - records video only if something is happening.) . The good search starting point would be to search for **Motion Detection algorithm** in google. – AlexTheDeveloper Aug 14 '13 at 00:47