Always have errors for image acquisition after 4 images acquired.

2 visualizzazioni (ultimi 30 giorni)
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.
However, for unknown reasons, after grabbing images 4 times, errors came up.
I could find out that there was no trigger event log.
Please provide me a piece of advice to solve this problem. Thank you inadvance.
Here is the matlab code:
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']);
subplot(2,2,1);
imshow(vid_bw1Image);
subplot(2,2,2);
imshow(vid_bw2Image);
subplot(2,2,3);
imshow(vid_colorImage);
subplot(2,2,4);
imshow(vid_uvImage);
delete(v_color);
delete(v_uv);
delete(v_bw1);
delete(v_bw2);
clear v_color;
clear v_uv;
clear v_bw1;
clear v_bw2;

Risposte (2)

Image Analyst
Image Analyst il 24 Ago 2019
Your best bet might be to open a support ticket with the MATLAB tech support. Very few of us have 4 cameras to reproduce your problem. That, plus the fact that you're not giving us the complete error message, or even a part of it, make it hard for us to help you.
  3 Commenti
Image Analyst
Image Analyst il 24 Ago 2019
Well, yeah, I have dozens, but normally only 1 or 2 hooked up to my computer at any one time.
Jungkeuk Park
Jungkeuk Park il 25 Ago 2019
I can't give exact error message since there is simply no data grabbed by the program and I found that there are event logs for start and stop event but nothing for the trigger event.
You can refer the following screenshot which contains the error message and value's of variables. You can easily notice that data arrays are empty( "[ ]" ) and event logs(elog~) are only 1x2 struct arrays.
I coudln't find the reason why cameras are not trrigered after exact 4 shoots. Are these related to packet size or other data networking or memory settings?

Accedi per commentare.


Image Analyst
Image Analyst il 25 Ago 2019
You're doing
vid_colorimage = imadjust(vid_colorimage, [0, 0, ...................................
however imadjust only accepts a gray scale image, not a color image.
Cast to gray scale if you want to use imadjust(). There is an output property of your video object, ReturnedColorSpace, that you can set to 'grayscale'. Refer to documentation for ReturnedColorSpace if you want to do that.
Or else just don't use imadjust() at all.

Community Treasure Hunt

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

Start Hunting!

Translated by