Hi all,
I've got a gige camera and using Matlab to create a gui with some controlling functions/processing buttons for the camera images.
Using the following
Image = preview(VidObj);ExtractedFrame = Image.CData;
I've been able to get the video feed to plot as 3D data which is what I'm looking for.
However, the preview window (small window, also showing the video stream) is always present and tends to be dominant in activity.
This is OK for the most but I think that because it's always visible (it's the active window on top of my gui figure), it's taking away control from my GUI.
I've added sliders in to control the viewing angle (which would be nicer to use the "surf" rotate by clicking and spinning the image, but again it works for what I need.
Where I'm struggling is adjusting camera exposure – it's presently set up as a
uicontrol('Style','edit', ...)
which is ideally how I'd like it, but the VideoPreview window always keeps the focus, so I can't actually highlight the exposure time to 'edit' the value (can't get the GUI active for long enough)
But to have the gui with additional buttons and controls is where I'm headed, and using preview(VidObj) only lets this be a 2D image (where I'd like to see peaks as the attached screenshot shows)
One can also see the controls I have – change colormap ('rainbow' = jet), control min & max Z, exposure, then the sliders to control the 'view' of the surf plot of the image.
As I'm also doing more image processing, I can export the image displayed (at the bottom), find camera values above certain Z (peak detection) and apply Z thresholding
Z(Z<Thresh)=0
by pressing the buttons at the bottom left of the GUI
I'm planning to add more, but tidying the surf(Image) from preview(VidObj) will probably be the quickest way to handle this (and further issues?!)
I include my main code also which is handling the camera acquisition
function DisplayCameraFeed(~, ~) VidObj = videoinput('gige'); VidObj.SelectedSourceName = 'input1'; [~] = preview(VidObj); % Important to initialise camera!
while GUI_Handles.Toggle_MAIN.Value NthFrame = NthFrame + 1; %% This section gets the camera settings VideoProperties = get(VidObj); CameraProperties = getselectedsource(VidObj); % Added 20191204; to access features like camera exposure, etc
% VideoProperties.Previewing = 'off'; % TRIED TO REMOVE THE DOMINANT PREVIEW WINDOW, didn't work!
CameraProperties.ExposureTime = str2double(GUI_Handles.Text_SetExposure.String); % Extract the handle (it's a string) from the exposure
%% Now we're ready to get the image from the camera, and do any potential processing
Image = preview(VidObj); ExtractedFrame = Image.CData; % Check that surf/mesh will be able to display the image OK (greyscale)
switch size(ExtractedFrame, 3) case 1 % No change needed
case 3 % Make RGB2Gray
ExtractedFrame = rgb2gray(ExtractedFrame); otherwise % Oh dear!
keyboard; end GUI_Handles.GlobalCell{2, 4} = ExtractedFrame; % Store image
if GUI_Handles.Toggle_Slicing.Value % Only want the sliced image above the threshold
Toggle_Slicing; ExtractedFrame = GUI_Handles.GlobalCell{2, 4}; end %% Displaying of the image. surf(flipud(ExtractedFrame)); % Matlab flips for surf plot
shading flat; axis tight; SetColorMap; SliderCheck; AXES = gca; AXES.Position = [0.25, 0.25, 0.7, 0.7]; AXES.XAxis.Visible = 'off'; AXES.YAxis.Visible = 'off'; AXES.CLim = [GUI_Handles.Slider_Z_Min.Value, GUI_Handles.Slider_Z_Max.Value]; AXES.ZLim = [GUI_Handles.Slider_Z_Min.Value, GUI_Handles.Slider_Z_Max.Value]; AXES.View = [GUI_Handles.Slider_Angle_Azimuth.Value, GUI_Handles.Slider_Angle_Elevation.Value]; AXES.XLabel.String = sprintf('X'); AXES.YLabel.String = sprintf('Y'); AXES.XGrid = 'off'; AXES.YGrid = 'off'; AXES.ZGrid = 'off'; %% Add peak detection: drawnow; hold on; Toggle_PeakDetector; % drawnow;
hold off; endstoppreview(VidObj)end
Thanks for your help 🙂
Best Answer