From: Mo on
hi everone,

i was woundering if anyone can help me with my prblem, i have created a preview vedio of my own, and in it i display a live video of my camera, what i have done is that i take that video "real time" and i do some filtering on it "also real time" now my problem is that i wanna show the filtered "real time" video in the same figure window i made.

i've tried the following code but an error occurs saying: "??? Error using ==> setappdata
Invalid object handle"

%%start of code
%initialize the webcam
vid = videoinput('winvideo');

% Create a figure window. This example turns off the default
% toolbar and menubar in the figure.
hFig = figure('Toolbar','none',...
'Menubar', 'none',...
'NumberTitle','Off',...
'Name','My Custom Preview GUI');

% Set up the push buttons
uicontrol('String', 'Start Preview',...
'Callback', 'preview(vid)',...
'Units','normalized',...
'Position',[0 0 0.15 .07]);
uicontrol('String', 'Stop Preview',...
'Callback', 'stoppreview(vid)',...
'Units','normalized',...
'Position',[.17 0 .15 .07]);
uicontrol('String', 'Close',...
'Callback', 'close(gcf)',...
'Units','normalized',...
'Position',[0.34 0 .15 .07]);

% Create the image object in which you want to
% display the video preview data.
vidRes = get(vid, 'VideoResolution');
imWidth = vidRes(1);%1
imHeight = vidRes(2);%2
nBands = get(vid, 'NumberOfBands');
hImage = image( zeros(imHeight, imWidth, nBands) );

% Specify the size of the axes that contains the image object
% so that it displays the image at the right resolution and
% centers it in the figure window.
figSize = get(hFig,'Position');
tic
while toc ~= 0
x = getsnapshot(vid);

% sharpening "filtering" the image with a scale from 0-1
h = fspecial('unsharp',0.5);

sharpened_Image = imfilter(x,h,'conv');
imW = sharpened_Image(1);%1
imH = sharpened_Image(2);%2
figWidth = figSize(3);%3
figHeight = figSize(4);%4
subplot(1,2,1)
set(gca,'unit','pixels',...
'position',[ ((figWidth - imWidth)/6)...
((figHeight - imHeight)/2)...
imWidth imHeight ]);
subplot(1,2,2)
set(gca,'position', [ ((figWidth - imW)/2)...
((figHeight - imH)/2)...
imW imH ]);
% Set up the update preview window function.
setappdata(hImage,'UpdatePreviewWindowFcn',@mypreview_fcn);

preview(vid, hImage);

end
%%end of code


any advice and thanks in advance...