Hi Speed Image Capture (matlab seems slow)

{EDIT 1}
I am using Windows.
This set up is to be used in real world (for about 2 hours in a stretch) This means collection of a lot of data. A simple notepad file containing the data points is of about 5-6 MB.
Ultimately, I need two things:

  1. A notepad file containing the data points whenever vehicles have been detected.
  2. A folder containing images taken by webcams whenever vehicles were detected.

Please refer to this image for convenience:(attached as well)

There is a timer running on arduino from the start.
As the vehicle passes down the road, the Left ping marks the time stamp and offset from the road edge of the vehicle as soon as it detects the vehicle. By the time vehicle has crossed it, I will be getting 5-10 readings or even more depending upon the speed of the vehicle. Right ping does the same. Here’s an example of the collected data:

115807 0 196
115849 0 201
115893 0 197
115932 0 198
115972 0 200
(Useless data points deleted to maintain readability of this post)
117613 224 0
117653 223 0
117692 224 0
117732 226 0
117772 226 0

Now, I have added two webcams to this whole setup. Arduino sends signal to my laptop whenever a vehicle crosses any ping sensor. My job is to take pictures through the webcam and store it on my HDD so that later on, I can know whether the recorded data point corresponds to a car, a bus or just some person moving by.

I tried to do this using Matlab. Whenever I received a valid data, I commanded MATLAB to take a snapshot. To some extent it was working but it was rather slow and the incoming values from Arduino were getting piled up (in some sort of temporary memory maybe). Ultimately, it was useless for me due to the slow snap shooting rate. Any idea how to achieve faster image shooting in order to match the speed of data being collected (approx 1 picture every 40 ms).
I heard about OpenCV. Do you think it would be fast enough to accomplish the job?
Is there any other light weight application, which can intercept signals from my arduino and take pictures using webcam?

Is there any other light weight application, which can intercept signals from my arduino and take pictures using webcam?

On my machine I can use this command:

mplayer -vo png -frames 1 tv://

or even better if installed:

fswebcam -r 640x480 --jpeg 85 -D 0 -d /dev/video0 web-cam-shot.jpg

I don't know if that would match your 40ms but it's worth a try.

PS: If you don't run Linux you should have mentioned that, if not mentioned I assume you run the same OS as I do :)

Depending on your budget, you could possibly use Canon's hacked Firmware, or something similar and just take images using a digital camera. I imagine your issue is dealing with the latency between sending commands around due to running an OS. You may actually need to directly control the "capture an image" aspect directly from the arduino. Is it possible for you to skip the whole PC part and directly control a camera directly? I imagine you could get under ms response time trigger, plus however long it takes to take a picture, and have it automatically numbered so you'll know which image corresponds with each ping. Depending on how long/often you take data, your 8/16Gig memory card may be enough.

I don't have good knowledge of cameras beyond things overheard at work and supposition for details about how to do it. Canon's stuff is called CHDK.