How do I compare video frames?

I have a project in mind where I want to detect motion in an image by comparing two frames from a video camera. I know there are several applications available that will do this but I wanted to roll my own. What techniques do people use to do this? Does anyone know? I want to code this in C or C++ if they are appropriate.

Thanks

Testy

Divide each frame into a grid, calculate the average luminance and chrominance for all the pixels in each sub-field, and then compare the values for each frame. Then you can set thresholds to determine if the two frames are different enough to be called “different.”

Beowulff

Thank you. This is exactly the kind of thing I was looking for. Do you have any idea of the size of the grid I should use for a 640 X 480 image? I’m thinking that the finer grid I use, the better control I would have but also, the more calculation I would need. How would I find the optimum size?

Thanks again

Testy

Just write your code flexibly, and play with the grid size until you get the results you need.
You can make a good guess - if a single pixel change at QVGA scale is important, than you need to be around 320 x 240. I would guess that your machine is plenty fast to actually compare every pixel at full resolution, but then you are going to have to take random noise into account. At lower resolution, this noise will tend to average out.

Beowulff

Thanks again for this. No, I’m not really interested in single pixel changes as that would probably change WAY too frequently. :stuck_out_tongue:
I will be looking for a human at a distance of around 30 feet or 10 meters so I would think it would be maybe 100-200 pixels that would change. (Just guessing on that number) As you say, I will have to experiment around with the grid size to nail this down.

All the best

Testy

I’m not sure if you’ve seen it and classified it as too applicationy, but if I were going to program any image manipulation, I’d probably start by looking at an ImageMagick library.

J Cubed

I’ve never even heard of it. I’ll take a look and see what it does. Thanks for taking the time to mention it, it’s appreciated.

Thanks again.

Testy

And here’s some infoon doing it with AForge.NET

Incidental to stuff I did in grad school (mobile robotics) was stuff I did in computer vision. One package we used was OpenCV (Open Computer Vision library, originally from Intel). Source code available at Sourceforge. As far as I know, that’s the go-to vision library and you can dive in and see how the pros did it.

Folks: I am sure this not where I am suppose to post this request, please excuse me if this is not correct.

I am looking for someone to help me finish a video comparison project I am working on…and it is way over my head. The basic request:

  1. Comparison video will be in a FTP file.
  2. Automatically take the file and compare one frame with no motion to one with motion.
  3. Output a file with the time of the first motion, the time of the last motion, and the X/Y where motion ended…image a door and I need to know where the motion ended in the door frame.

Send me a message if you are interested or know someone that has these skills…I do not…lol. Thanks. Newbee2015