how to give a triggers to 4 different cameras

13 Ansichten (letzte 30 Tage)
Jungkeuk Park
Jungkeuk Park am 24 Aug. 2019
Beantwortet: Shadaab Siddiqie am 27 Jul. 2021
I am using matlab to obtain images from 4 JAI CCD cameras(1 color, 2 mono, 1 uv).
Matlab code sets exposure time to cameras with pulse generation and grab images by external trigger.
The problem is when I take a picture, the trigger time is quiet different.
For example, the trigger times are 1)17:51:24.41 2)17:51:26:43 3)17:51:26.47 4) 17:51:28.40
Time gaps are 1-2) 2.03 sec, 2-3)0.04sec, 3-4) 1.53sec, 1-4) 3.59sec.
And camera triggering order is different. It is once 1)camera #1, 2)camera #3, 3)camera #4 and 4) camera #2
and then 1)camera #4, 2)camera #1, 3) camera #2 and 4) camera #4.
Please tell me how to syncronize the trigger time for 4 cameras and control triggering order. Thank you for an advice in advance.
Here is the matlab code I use:
clc; clear all; close all;
prompt = {'Exposure_color (ms):','Exposure_UV (ms):'...
,'Exposure_BW1 (ms):','Exposure_BW2 (ms):'};
title = 'Exposure time';
dims = [1 35];
definput = {'25','12','5','5'};
answer = inputdlg(prompt,title,dims,definput);
v_bw1 = videoinput('gige',3,'Mono8'); %ch.1~4
v_uv = videoinput('gige',4,'Mono8');
v_color = videoinput('gige',1,'BayerRG8');
v_bw2 = videoinput('gige',2,'Mono8');
s1 = v_bw1.Source;
s2 = v_uv.Source;
s3 = v_color.Source;
v_color.ReturnedColorspace = 'grayscale';
s4 = v_bw2.Source;
% Specify total number of frames to be acquired
% One frame is acquired for each external signal pulse.
numFrames = 1; % Enter the number of frame
% BW1
s1.PulseGeneratorSelector = 'PulseGenerator1';
s1.PulseGeneratorClearActivation = 'RisingEdge';
s1.PulseGeneratorClearInverter = 'False';
s1.PulseGeneratorClearSource = 'Line5';
s1.PulseGeneratorClock = 0.446428571428571;
%s1.PulseGeneratorFrequency = 0.500000080000013;
% s1.PulseGeneratorLengthMs = 1.1*str2num(answer{3});
s1.PulseGeneratorLengthMs = 2000;
s1.PulseGeneratorStartPoint = 1;
s1.PulseGeneratorEndPointMs = str2num(answer{3}); % exposure time (ms)
% UV
s2.PulseGeneratorSelector = 'PulseGenerator1';
s2.PulseGeneratorClearActivation = 'RisingEdge';
s2.PulseGeneratorClearInverter = 'False';
s2.PulseGeneratorClearSource = 'Line5';
s2.PulseGeneratorClock = 0.446428571428571;
%s2.PulseGeneratorFrequency = 0.500000080000013;
% s2.PulseGeneratorLengthMs = 1.1*str2num(answer{2});
s2.PulseGeneratorLengthMs = 2000;
s2.PulseGeneratorStartPoint = 1;
s2.PulseGeneratorEndPointMs = str2num(answer{2}); % exposure time (ms)
% Color
s3.PulseGeneratorSelector = 'PulseGenerator1';
s3.PulseGeneratorClearActivation = 'RisingEdge';
s3.PulseGeneratorClearInverter = 'False';
s3.PulseGeneratorClearSource = 'Line5';
s3.PulseGeneratorClock = 0.446428571428571;
%s3.PulseGeneratorFrequency = 0.500000080000013;
%s3.PulseGeneratorLengthMs = 1.1*str2num(answer{1});
s3.PulseGeneratorLengthMs = 2000;
s3.PulseGeneratorStartPoint = 1;
s3.PulseGeneratorEndPointMs = str2num(answer{1}); % exposure time (ms)
% BW2
s4.PulseGeneratorSelector = 'PulseGenerator1';
s4.PulseGeneratorClearActivation = 'RisingEdge';
s4.PulseGeneratorClearInverter = 'False';
s4.PulseGeneratorClearSource = 'Line5';
s4.PulseGeneratorClock = 0.446428571428571;
%s4.PulseGeneratorFrequency = 0.500000080000013;
% s4.PulseGeneratorLengthMs = 1.1*str2num(answer{4});
s4.PulseGeneratorLengthMs = 2000;
s4.PulseGeneratorStartPoint = 1;
s4.PulseGeneratorEndPointMs = str2num(answer{4}); % exposure time (ms)
v_bw1.FramesPerTrigger = 1;
v_uv.FramesPerTrigger = 1;
v_color.FramesPerTrigger = 1;
v_bw2.FramesPerTrigger = 1;
v_bw1.TriggerRepeat = 0;
v_uv.TriggerRepeat = 0;
v_color.TriggerRepeat = 0;
v_bw2.TriggerRepeat = 0;
% Specify 'hardware' videoinput trigger type
triggerconfig(v_bw1, 'hardware', 'DeviceSpecific', 'DeviceSpecific');
triggerconfig(v_uv, 'hardware', 'DeviceSpecific', 'DeviceSpecific');
triggerconfig(v_color, 'hardware', 'DeviceSpecific', 'DeviceSpecific');
triggerconfig(v_bw2, 'hardware', 'DeviceSpecific', 'DeviceSpecific');
s1.TriggerSelector = 'FrameStart';
s2.TriggerSelector = 'FrameStart';
s3.TriggerSelector = 'FrameStart';
s4.TriggerSelector = 'FrameStart';
s1.TriggerSource = 'PulseGenerator1';
s2.TriggerSource = 'PulseGenerator1';
s3.TriggerSource = 'PulseGenerator1';
s4.TriggerSource = 'PulseGenerator1';
s1.TriggerActivation = 'RisingEdge';
s2.TriggerActivation = 'RisingEdge';
s3.TriggerActivation = 'RisingEdge';
s4.TriggerActivation = 'RisingEdge';
s1.TriggerMode = 'on';
s2.TriggerMode = 'on';
s3.TriggerMode = 'on';
s4.TriggerMode = 'on';
s1.GainRaw = 336;
s2.GainRaw = 336;
s3.GainRaw = 100;
s4.GainRaw = 336;
% For exposure time control configure a TriggerWidth exposure mode
s1.ExposureMode = 'TriggerWidth';
s2.ExposureMode = 'TriggerWidth';
s3.ExposureMode = 'TriggerWidth';
s4.ExposureMode = 'TriggerWidth';
answer = questdlg('Take a shot?','Take a shot','Shot','No','Shot');% Start hardware-triggered buffered continuous acquisition, and wait for
% acquisition to complete
start([v_bw1 v_uv v_color v_bw2])
wait([v_bw1 v_uv v_color v_bw2], 100)
% wait(v_uv, 5)
% wait(v_bw1, 5)
% wait(v_bw2, 5)
% Eventlog
elog_color = v_color.EventLog;
elog_uv = v_uv.EventLog;
elog_bw1 = v_bw1.EventLog;
elog_bw2 = v_bw2.EventLog;
elog_bw1(1).Data
elog_uv(1).Data
elog_color(1).Data
elog_bw2(1).Data
elog_bw1(2).Data
elog_uv(2).Data
elog_color(2).Data
elog_bw2(2).Data
fn_color=mat2str(elog_color(2).Data.AbsTime);
fn_uv=mat2str(elog_uv(2).Data.AbsTime);
fn_bw1=mat2str(elog_bw1(2).Data.AbsTime);
fn_bw2=mat2str(elog_bw2(2).Data.AbsTime);
% Transfer acquired frames and timestamps from acquisition input buffer
% into workspace
data_color = getdata(v_color, v_color.FramesAvailable);
data_uv = getdata(v_uv, v_uv.FramesAvailable);
data_bw1 = getdata(v_bw1, v_bw1.FramesAvailable);
data_bw2 = getdata(v_bw2, v_bw2.FramesAvailable);
vid_bw1Image=imrotate(data_bw1,-90); % image processing
vid_bw2Image=imrotate(data_bw2,90);
vid_colorImage=imrotate(data_color,-90);
vid_uvImage=imrotate(data_uv,90);
% vid_colorImage = imadjust(vid_colorImage,[0 0 0;0.706 1 0.706],[]);
vid_colorImage=demosaic(vid_colorImage, 'grbg');
DIRNAME1 = datestr(now,'yyyymmdd'); % create folders
DIRNAME2 = datestr(now,'HHMMSS');
mkdir(DIRNAME1, DIRNAME2);
pathname = ['C:\Users\admin\Documents\gyujin\code','\',DIRNAME1,'\',DIRNAME2,'\'];
mkdir(pathname);
imwrite(vid_bw1Image,[pathname,fn_bw1,'bw1.jpg']); % save images
imwrite(vid_bw2Image,[pathname,fn_bw2, 'bw2.jpg']);
imwrite(vid_uvImage,[pathname,fn_uv,'uv.jpg']);
imwrite(vid_colorImage,[pathname,fn_color,'color.jpg']);
delete(v_color);
delete(v_uv);
delete(v_bw1);
delete(v_bw2);
clear v_color;
clear v_uv;
clear v_bw1;
clear v_bw2;

Antworten (1)

Shadaab Siddiqie
Shadaab Siddiqie am 27 Jul. 2021
Form my understanding you want to trigger multiple cameras based on some conditions. You can do something like this.
%Configure camera for FrameStart trigger mode and specify external triggering signal input line and desired trigger condition.
% TriggerMode to 'on') applies only to the specified trigger mode (FrameStart).
s.TriggerSelector = 'FrameStart';
s.TriggerSource = 'Line1';
s.TriggerActivation = 'RisingEdge';
s.TriggerMode = 'on';
% Specify a constant exposure time for each frame
s.ExposureMode = 'Timed';
s.ExposureTimeAbs = 4000;
% Start hardware-triggered buffered continuous acquisition, and wait for acquisition to complete
start(v)
wait(v, 10)
% Transfer acquired frames and timestamps from acquisition input buffer into workspace
[data2, ts2] = getdata(v, v.FramesAvailable);

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by