-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cameras that skip the first frame. What a pain in the ***...
- Loading branch information
1 parent
b4707bc
commit b49e861
Showing
3 changed files
with
56 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,66 @@ | ||
function [OutputError] = PIVlab_capture_OPTRONIS_save(OPTRONIS_vid,nr_of_images,ImagePath,frame_nr_display,bitmode) | ||
warning('off','imaq:gentl:hardwareTriggerTriggerModeOff') | ||
fix_Optronis_skipped_frame=0; | ||
if bitmode==8 | ||
bitmultiplicator=1; | ||
bitmultiplicator=1; | ||
elseif bitmode==10 | ||
bitmultiplicator = 32; %bring 10bit data to 16 bits full histogram, otherwise images outside Matlab are not displayed correctly (too dark). | ||
disp(mfilename) | ||
disp('needs testing') | ||
bitmultiplicator = 32; %bring 10bit data to 16 bits full histogram, otherwise images outside Matlab are not displayed correctly (too dark). | ||
disp(mfilename) | ||
disp('needs testing') | ||
end | ||
OPTRONIS_settings = get(OPTRONIS_vid); | ||
OPTRONIS_settings.Source.EnableFan = 'On'; | ||
hgui=getappdata(0,'hgui'); | ||
OutputError=0; | ||
OPTRONIS_frames_to_capture = nr_of_images*2+fix_Optronis_skipped_frame; | ||
if getappdata(hgui,'cancel_capture') ~=1 %capture was not cancelled --> save images from RAM to disk | ||
OPTRONIS_data = getdata(OPTRONIS_vid,OPTRONIS_frames_to_capture); | ||
cntr=0; | ||
starttime=tic; | ||
for image_save_number=(1+fix_Optronis_skipped_frame) : 2 : size(OPTRONIS_data,4) | ||
if getappdata(hgui,'cancel_capture') ~=1 | ||
imgA_path=fullfile(ImagePath,['PIVlab_' sprintf('%4.4d',cntr) '_A.tif']); | ||
imgB_path=fullfile(ImagePath,['PIVlab_' sprintf('%4.4d',cntr) '_B.tif']); | ||
imwrite(OPTRONIS_data(:,:,:,image_save_number)*bitmultiplicator,imgA_path,'compression','none'); %tif file saving seems to be the fastest method for saving data... | ||
imwrite(OPTRONIS_data(:,:,:,image_save_number+1)*bitmultiplicator,imgB_path,'compression','none'); | ||
cntr=cntr+1; | ||
set(frame_nr_display,'String',['Saving images to disk: Image pair ' num2str(cntr) ' of ' num2str(size(OPTRONIS_data,4)/2)]); | ||
drawnow limitrate; | ||
end | ||
end | ||
disp([num2str(toc(starttime)/cntr *1000) ' ms/image']) | ||
OPTRONIS_data = getdata(OPTRONIS_vid,OPTRONIS_frames_to_capture+2); | ||
%% Detect if first frame is empty | ||
% There are a number of bugs with the OPTRONIS cameras and Matlabs IMAQ | ||
% toolbox. I had discussion with both parties, noone feels responsible. | ||
% E.g. the Optronis returns color formats that Matlab does not understand, | ||
% and Matlab cannot configure the Optronis to run on external trigger. This | ||
% is EXTREMELY annoying to me, as I can't do anything. | ||
%These lines of code check if the first frame is substantially darker than | ||
%the following frames. If it is, then it is likely, that the camera didn't | ||
%start properly, then we have to remove the first frame. | ||
bug_fix_skipped_frame=0; | ||
max_imgs=50; | ||
if size(OPTRONIS_data,4) >= 10 | ||
if size(OPTRONIS_data,4) < max_imgs | ||
max_imgs=size(OPTRONIS_data,4); | ||
end | ||
sum_img=zeros(1,max_imgs); | ||
for i=1:max_imgs | ||
sum_img(i)=sum(OPTRONIS_data(:,:,:,i),'all'); | ||
end | ||
mean_img=mean((sum_img(:,2:end))); | ||
stdev_img=5*std(sum_img(:,2:end)); %5x stdev is allowed | ||
if (sum_img(1) < (mean_img-stdev_img)) | ||
%disp('bild skipped') | ||
%disp(['value: ' num2str(sum_img(1))]) | ||
%disp(['lower bound: ' num2str(mean_img-stdev_img) '| upper bound: ' num2str(mean_img+stdev_img)]) | ||
disp('First frame removed. Bug fix for OPTRONIS and Mathworks (not for PIVlab...!)') | ||
bug_fix_skipped_frame=1; | ||
else | ||
%disp('OK') | ||
end | ||
else | ||
disp('Automatic bug fix for skipped frames could not be run, needs to have at least 5 image pairs') | ||
end | ||
%% | ||
cntr=0; | ||
starttime=tic; | ||
for image_save_number=bug_fix_skipped_frame + (1+fix_Optronis_skipped_frame) : 2 : OPTRONIS_frames_to_capture | ||
if getappdata(hgui,'cancel_capture') ~=1 | ||
imgA_path=fullfile(ImagePath,['PIVlab_' sprintf('%4.4d',cntr) '_A.tif']); | ||
imgB_path=fullfile(ImagePath,['PIVlab_' sprintf('%4.4d',cntr) '_B.tif']); | ||
imwrite(OPTRONIS_data(:,:,:,image_save_number)*bitmultiplicator,imgA_path,'compression','none'); %tif file saving seems to be the fastest method for saving data... | ||
imwrite(OPTRONIS_data(:,:,:,image_save_number+1)*bitmultiplicator,imgB_path,'compression','none'); | ||
cntr=cntr+1; | ||
set(frame_nr_display,'String',['Saving images to disk: Image pair ' num2str(cntr) ' of ' num2str(OPTRONIS_frames_to_capture/2)]); | ||
drawnow limitrate; | ||
end | ||
end | ||
disp([num2str(toc(starttime)/cntr *1000) ' ms/image']) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters