commenting preview of video raises error

1 view (last 30 days)
Matlab 8.1.0.604 Image Processing Tool Box version 8.2(R2013a)
Hello all, Im trying to apply my algorithm on a live video and a command preview(vid) opens up a window with camera input ,every thing is working fine with code.
when I close the preview window or comment the command in the line "preview(vid)" it arise error.
'Timeout error during getsnapshot()'
is there any way that I dont want to use that preview. In debugging mode when I move step by step it doesnt show up any problem.
Here is my code snippet
% code
vid = videoinput(caminfo.InstalledAdaptors{1,ifcam},camdev.DeviceIDs{1});
start(vid); % to start a video camera
preview(vid); % Preview Video
% i get error when I comment the line above.
%%Acquire Image.
figure('Name','BG Subtraction','Numbertitle','Off','Menubar','None','units','pixels','Position',[200 500 1500 500]);
while true
Im = getsnapshot(vid);
subplot(1,3,1);
imshow(Im);
[r c p] = size(Im);
%Extract individuals plane from RGB image
imR = squeeze(Im(:,:,1));
imG = squeeze(Im(:,:,2));
imB = squeeze(Im(:,:,3));
%Thresholding on individual planes
imBinaryR = im2bw(imR,graythresh(imR));
imBinaryG = im2bw(imR,graythresh(imG));
imBinaryB = im2bw(imR,graythresh(imB));
imBinary = imcomplement(imBinaryR & imBinaryG & imBinaryB);
subplot(1,3,2);
imshow(imBinary);
end

Accepted Answer

Image Analyst
Image Analyst on 6 Nov 2015
I'm not sure if a preview window is needed or not. If it is, maybe you can set the size of the window really small, like a pixel or so, if you don't want it to show.
videoRes = get(vidobj, 'VideoResolution');
numberOfBands = get(vidobj, 'NumberOfBands');
axes(handles.axesImage);
cla('reset');
handleToImageInAxes = image( zeros([videoRes(2), videoRes(1), numberOfBands], 'uint8') );
preview(vidobj, handleToImageInAxes);
start(vidobj);
% Make axes a single pixel.
set(handles.axesImage, 'Units', 'normalized', 'Position', [1, 1, .001, .001]);
  1 Comment
Raady
Raady on 7 Nov 2015
I can take your suggestions, but to my gesture the command getsnapshot take a frame from the input signal (where I mentioned vid). My question is, what is it to do with preview ? why am I getting error when preview is commented.Is there any relation with preview and getsnapshot ?

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!