I am using opencv and visual studio ultimate 2010. My goal is to detect cars in a road and count them. I am using edge detection solution for this.
We want to perform this tasks for any object that cross of virtual line.
Your question is still to broad.
However, I'll try to give you some pointers.
You can use a background subtraction method. You can find some info and code here and here. The work on your moving objects (cars). You can find some hints here
Setup you car classifier , and try to detect the cars in your scene. You can find a nice tutorial on Support Vector Machine (SVM) here, or you can start from the OpenCV people detector example, training it to detect cars instead of people.
For counting cars I recommend the first approach.
Good luck!