absDiff two ofxCvGrayscaleImages to detect movement

Hello!

I have been using openframeworks on Windows for a few days now, I am loving it!

Basically I am trying to take take the difference between a previous frame (from a webcam) and the latest frame to detect movement. Interested in OpenCV, I began with the opencvExample project which is exactly what I am looking for.

However, I notice that there isn’t a function (that I can see) which saves the previous frame for you. It looks as if ofxCv has the relevant functions, but obviously this has not been released yet and therefore it is not recommended that this is used.

Is there a best practice when doing this? Or shall I simply just take a similar approach to the opencvExample project, but instead of pressing the spacebar to save an image to compare to, save an image in a ofxCvGrayscaleImage and update that every frame, then take the absDiff of that frame and the latest frame?

Hope that makes sense!
Cheers

I’ve used ofxCv in some small demo projects and it’s actually pretty robust. I know Kyle is going to change it in the future, but it’s actually quite good already. That said, if you want to diff images, you can simply use absDiff as you mentioned. You’ll want to make sure you only store the frame when the grabber has a new frame, i.e. when videoGrabber.isFrameNew() returns true, like in the example. That will give you pixels, which might be all you need, but if you want some metric of how different one frame is from another that’s a little trickier.

Oh cool ok, I will have another look into it in that case then.

I added just one line to the opencvExample so now it continuously compares the previous frame to the latest frame from the webcam. As you said, this has given me the pixels. I am hoping to use the difference in frames to collide with objects, so I presume I can just do a check to see if a certain amount of pixels are in the same area as say a ball, then that means they have collided.

Not sure if that is the best/most efficient way to calculate the collision, or whether, as you say I will need to implement something a bit trickier in order to see if the motion of the user has collided with a ball.