Here is an easy way to do this using my older Posts :
Just first Run this file :
Just first Run this file :
Capture and save Frames using Webcam matlab Code
Now run this :
Guess what... its done... :D
So,what I want to say is that always look at the smaller modules,combine them,Make your own project...