Why do I keep getting a timeout error when I try to manually configure a webcam?
32 views (last 30 days)
Show older comments
Hello,
I am trying to manually configure a webcam but keep on getting the following error:
Error using imaqdevice/getsnapshot (line 65)
A timeout occurred during GETSNAPSHOT.
Error in WebCam_Config_Test (line 17)
snapshot = getsnapshot(vidobj);
I am running a simple test from the Mathworks site to establish whether it's feasible to use a manually configured cam. I would like to use a cam without the webcam add on, because I want to change the properties. The code I am running is below. Note that I did try to change the timeout to 500.
Does anyone have any suggestions? I would appreciate any help as this is driving me up the wall! Many thanks.
clear all;
vidobj = videoinput('macvideo', 2);
vidObj.Timeout = 500;
% Configure the object for manual trigger mode.
triggerconfig(vidobj, 'manual');
% Now that the device is configured for manual triggering, call START.
% This will cause the device to send data back to MATLAB, but will not log
% frames to memory at this point.
start(vidobj)
% Measure the time to acquire 20 frames.
tic
for i = 1:20
snapshot = getsnapshot(vidobj);
end
elapsedTime = toc
% Compute the time per frame and effective frame rate.
timePerFrame = elapsedTime/20
effectiveFrameRate = 1/timePerFrame
% Call the STOP function to stop the device.
stop(vidobj)
% Once the video input object is no longer needed, delete the associated variable.
delete(vidobj)
0 Comments
Answers (1)
Vandana Rajan
on 28 Feb 2017
Hi,
GETSNAPSHOT is meant as a convenience function to grab one frame from a camera, and in this process, it starts the camera, takes one frame, then stops the camera. Doing this in a loop can lead to unnecessary communication with the hardware.
Instead, you may try setting a specific frame rate and TRIGGER once, then use GETDATA to access frames that are already acquired. An example code is given below.
vid = videoinput('winvideo');
triggerconfig(vid, 'manual');
vid.FramesPerTrigger = inf;
start(vid);
trigger(vid)
for x = 1:100
data = getdata(vid,1);
% do something
end
stop(vid);
Try this out and let us know about the outcome.
5 Comments
Walter Roberson
on 9 Mar 2017
Tasnima Rahman:
memory() is only available on MS Windows. Unfortunately on Linux and OS-X you have to look outside of MATLAB.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!