2

I got a camera triggered by external source at a constant rate of 1/0.14s, and Matlab for-loop is used to take timed pictures for real-time measurements. However, the elapsed time for 1 execution of "getsnapshot" is so different each time. Sometimes I get 1 picture with less than 0.14s and sometimes it takes 0.5s to take a picture. Is there anyway to synchronize the "getsnapshot" with the external trigger? or at least make the "getsnapshot" exactly timed?

The following is my code:

vid = videoinput('camera');  
preview(vid);  

for i=1:100  
data=getsnapshot(vid);  
%...data processing...  
%....  
clear data  
end
bla
  • 25,846
  • 10
  • 70
  • 101
user1650256
  • 33
  • 1
  • 4

1 Answers1

2

First, delete the preview(vid) line, this is probably why the rep. rate you are getting is weird. When you take data you don't need this preview option on, as it takes resources from your cpu.

Then, you may need to set the camera properties on the imaq toolbox to be in triggered mode. For example, for a gentl camera type this might look something like:

    triggerconfig(vid, 'hardware', 'DeviceSpecific', 'DeviceSpecific');

    src = getselectedsource(vid);
    src.FrameStartTriggerMode = 'On';
    src.FrameStartTriggerActivation = 'RisingEdge';
    src.FrameStartTriggerDelayAbs = 0;
    src.FrameStartTriggerSource = 'Line1';
    src.FrameStartTriggerOverlap = 'Off';

Then, with some camera's you can read their trigger out, that is whenever the camera is exposing, it sends a ttl to some output. Matlab way to define it is something like:

    src.SyncOut1SyncOutPolarity = 'Normal';
    src.SyncOut1SyncOutSource = 'Exposing';  

Again, you'll need to play with your camera's options in the imaq tool. Also, the data processing step that you take afterwards may take some time, so benchmark it to see you can take data and analyze it on the fly without bottlenecks happening.

Last, you can use getdata instead of getsnapshot (read the documentation to see their difference) , and in the form: [img, time, metadata] = getdata(vid); This will give you timestamps for each image taken, so you can see what's happening. Also, instead of clear data use flushdata(vid) to keep the vid object from completely filling the memory buffer (though if you only run 100 iterations in a loop, you should be fine).

bla
  • 25,846
  • 10
  • 70
  • 101
  • What is src? Is it under triggerinfo(vid)? I tried to follow your command, but it pops up "??? Undefined function or variable 'src'." – user1650256 Apr 01 '13 at 19:17
  • `src` is obtained with `src = getselectedsource(vid);` I've updated the answer. – bla Apr 01 '13 at 21:33
  • I am using a Hamamatsu c4742 camera and don't have "src.SyncOut1SyncOutPolarity" under get(src). The adjustable features are only FrameStartTrigger. Does this mean that I can not use your method? – user1650256 Apr 02 '13 at 18:01
  • As I said in the answer, you need to explore **your** camera properties, I just gave you a `gentl` type example that I use. Try using imaqtool and see the different options your camera supports. The `SyncOut` property is the way that a cameta (mine) is set to send a TTL when it is exposing, your camera may use a different command, or not have this option. You'll have to explore for yourself. – bla Apr 02 '13 at 18:05
  • I can not find any syncout properties under get(src). Thanks for your kindly answer anyway. – user1650256 Apr 03 '13 at 16:13
  • maybe this thread will be useful to you: http://www.mathworks.com/matlabcentral/newsreader/view_thread/274624 – bla Apr 04 '13 at 00:09