Log in

View Full Version : How to apply motion detection to webcams


JeanMarc
22nd July 2009, 04:18
Hi,

I am experimenting with webcams and free software Dorgem for home monitoring applications. The motion detection capability of Dorgem is (not surprisingly) not nearly as good as what could be achieved with Avisynth (I think!). The webcam captures way too many frames, as the smallest change from frame to frame is considered "motion". I want to be able to go back to the avi file created from the webcam output, and eliminate all the frames that don't have significant motion in them, in effect deciding what motion criteria should be applied.

I have seen a lot of clever scripts out there to detect/estimate motion, but I am looking for something basic, that could do something like:
If YDifferenceToNext() < 3,
then DeleteFrame
else do nothing
Obviously, Avisynth doesn't support this kind of syntax :(

I have been looking at ScriptClip and ConditionalFilter without finding anything obvious, but I don't have a huge experience with Avisynth syntax and filters, and I am probably missing something.

Unfortunately, the following doesn't work:
clip = AviSource("c:\file.avi")
ScriptClip(clip, "DeleteFrame(YDifferenceFromPrevious/3.0)")
I guess because the argument of DeleteFrame is not a clip.


This is a problem that many people may have encountered. So if anyone has any idea on the subject, please help!

Thanks.

thewebchat
22nd July 2009, 04:59
1) I believe GScript by [someone] implements if/then/else conditional statements.

2) You could try using Dup/DeDup to drop duplicate frames instead of coding your own solution.

JeanMarc
22nd July 2009, 14:25
First,thanks for the suggestions.
1) I believe GScript by [someone] implements if/then/else conditional statements.
This is great! This will simplify a lot of things. Now that I have the logic, I don't have the function. What I would like to do is delete the current frame after comparing it with the previous one. But "current_frame" doesn't exist in avisynth (see this post (http://forum.doom9.org/showthread.php?p=1196026#post1196026)).
Now, it may be possible to do it inside the Gscript??? I am looking at it.

2) You could try using Dup/DeDup to drop duplicate frames instead of coding your own solution.
Actually, after just looking at the readme, that looks like the easiest solution. I will test it first.
:thanks:

Gavino
22nd July 2009, 22:37
I have been looking at ScriptClip and ConditionalFilter without finding anything obvious, but I don't have a huge experience with Avisynth syntax and filters, and I am probably missing something.
This is similar to the problem discussed in this thread, where you want to delete frames based on some local criterion - in your case, the criterion will be different (YDifferenceFromNext() < 3, or some other way of detecting a duplicate), but the principle is the same.

If you find DeDup doesn't do what you want, the solution I posted there should be adaptable to your needs.
The use of a recursive procedure could now be replaced by a GScript 'while' loop (not available at the time).

JeanMarc
23rd July 2009, 13:36
This is similar to the problem discussed in this thread, where you want to delete frames based on some local criterion - in your case, the criterion will be different (YDifferenceFromNext() < 3, or some other way of detecting a duplicate), but the principle is the same...The use of a recursive procedure could now be replaced by a GScript 'while' loop (not available at the time).
Good examples in that thread. This might provide more flexibility. I will explore the method.

If you find DeDup doesn't do what you want, the solution I posted there should be adaptable to your needs.
Dedup looks like a simple solution that works for me now! (I have resolved the problem I had here (http://forum.doom9.org/showthread.php?p=1307709#post1307709))

:thanks: for all the feedback.