Learn to use google: it is your friend.
A quick search using your question subject gave a huge number of hits, including one article on this very site:
Motion detection using web cam[
^] - it may be in C#, but it will give you the principles.
Don't be so lazy in future: try to do at least the basic research yourself!