Why do I keep getting a timeout error when I try to manually configure a webcam?

15 次查看(过去 30 天)
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)

回答(1 个)

Vandana Rajan
Vandana Rajan 2017-2-28
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 个评论
Vandana Rajan
Vandana Rajan 2017-3-9
Hi Tasnima,
I have taken up this query with MathWorks Technical Support Team. Some one from the team will be reaching out to you via e-mail. Please check all your e-mail folders in case it ends up in the spam folder. Meanwhile, there is an EBR (external bug report) which is similar to your issue. Please find link for the same below
https://www.mathworks.com/support/bugreports/1422542 You may try the work around suggested in it.
Walter Roberson
Walter Roberson 2017-3-9
Tasnima Rahman:
memory() is only available on MS Windows. Unfortunately on Linux and OS-X you have to look outside of MATLAB.

请先登录,再进行评论。

Community Treasure Hunt

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

Start Hunting!

Translated by