setappdata Within Class for Preview Update Function

For camera stream previewing, the example Specifying the Update Preview Function demonstrates how to define your own video preview function: https://www.mathworks.com/help/imaq/previewing-data.html
For the function:
preview(video, hImage);
A callback handle is defined for hImage, using:
setappdata(hImage,'UpdatePreviewWindowFcn',@mypreview_fcn);
The callback is defined as:
function mypreview_fcn(obj,event,himage)
% Example update preview window function.
% Get timestamp for frame.
tstampstr = event.Timestamp;
% Get handle to text label uicontrol.
ht = getappdata(himage,'HandleToTimestampLabel');
% Set the value of the text label.
ht.String = tstampstr;
% Display image data.
himage.CData = event.Data
The problem I'm having, is when use this same concept within a class, the callback never gets called for a preview update:
classdef UI < matlab.apps.AppBase
properties (Access = public)
pFigure matlab.ui.Figure
end
properties (Access = private)
pVid
pSrc
pImage
pStream
end
methods (Access = private)
%********THIS NEVER GETS CALLED ***********
function preview(app,event, pImage)
app.pImage.CData = event.Data;
end
function startStream(app, obj, event)
%**********PREVIEW IS CALLED HERE*************
preview(app.pVid, app.pImage);
end
end
% Callbacks that handle component events
methods (Access = private)
% Code that executes after component creation
function startupFcn(app)
%***************THIS DOESNT SEEM TO WORK*****************
setappdata(app.pImage,'HandleToPreviewUpdate',@app.preview);
end
end
% Component initialization
methods (Access = private)
% Create UIFigure and components
function createComponents(app)
app.pVid = videoinput('pointgrey', 1, 'F7_Mono12_1920x1200_Mode0');
app.pSrc = getselectedsource(app.pVid);
app.pVid.FramesPerTrigger = 1;
% Create a figure window. This example turns off the default
% toolbar and menubar in the figure.
app.pFigure = figure('Toolbar','none',...
'Menubar', 'none',...
'NumberTitle','Off',...
'Position', [1 1 960 735],...
'Name','Rx');
app.Stream = axes('Position',[0.04 0.5 0.45 0.45]);
% Set up the push buttons
uicontrol('String', 'Start Preview',...
'Callback', @app.startStream,...
'Units','normalized',...
'FontSize', FontSize,...
'Position',[0.04 0.38 0.22 .07]);
VidRes = app.pVid.VideoResolution;
imWidth = VidRes(1);
imHeight = VidRes(2);
nBands = app.pVid.NumberOfBands;
app.pImage = image(app.Stream, ones(imHeight, imWidth, nBands));
app.Stream.XTick = [];
app.Stream.YTick = [];
end
end
% App creation and deletion
methods (Access = public)
% Construct app
function app = UI
% Create UIFigure and components
createComponents(app)
% Register the app with App Designer
registerApp(app, app.pFigure)
% Execute the startup function
runStartupFcn(app, @startupFcn)
if nargout == 0
clear app
end
end
% Code that executes before app deletion
function delete(app)
% Delete UIFigure when app is deleted
delete(app.pFigure)
end
end
end

Risposte (0)

Categorie

Scopri di più su Develop Apps Programmatically in Centro assistenza e File Exchange

Prodotti

Release

R2019b

Richiesto:

il 3 Apr 2020

Modificato:

il 3 Apr 2020

Community Treasure Hunt

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

Start Hunting!

Translated by