error using webcam

1 次查看(过去 30 天)
FIR
FIR 2011-10-18
i want to track redobjects,i have code for it and it detects redobjects,but wen i use cam to take picture i get an error
error is
Error using ==> end
Incorrect cell or structure reference involving "end".
Most likely cause is a reference to multiple elements of a cell or
structure followed by additional subscript or structure references.
Error in ==> getCameraInfo at 4
camera_id = camera_info.DeviceInfo.DeviceID(end);
the code for getCameraInfo is
function [camera_name, camera_id, resolution] = getCameraInfo(a)
camera_name = char(a.InstalledAdaptors(end));
camera_info = imaqhwinfo(camera_name);
camera_id = camera_info.DeviceInfo.DeviceID(end);
resolution = char(camera_info.DeviceInfo.SupportedFormats(end));
can anyone suggest please

采纳的回答

Walter Roberson
Walter Roberson 2011-10-18
camera_info or camera_info.DeviceInfo is a structure array with multiple elements, so either camera_info or camera_info.DeviceInfo represents multiple array values simultaneously. You then try to index in to a field in one of those arrays, but MATLAB does not allow that operation.
For example, if you had
A(1).id = 1:5;
A(2).id = 6:10;
then A.id(end) would try to refer to both A(1).id(end) and A(2).id(end) simultaneously... which isn't allowed.
You should use
size(camera_info)
arrayfun(@size,[camera_info.DeviceInfo],'Uniform',0)
to explore to see which is the structure array with multiple elements.
  1 个评论
FIR
FIR 2011-10-18
i did as u sai dbut i get error
the error is
Error in ==> getCameraInfo1 at 2
camera_name = char(a.InstalledAdaptors(end));
??? Output argument "camera_id" (and maybe others) not assigned during call to
"C:\Documents and Settings\User\Desktop\camera\getCameraInfo1.m>getCameraInfo1".

请先登录,再进行评论。

更多回答(1 个)

Daniel Shub
Daniel Shub 2011-10-18
I am not sure, but following on from Walter ...
Are you sure you want
camera_info.DeviceInfo.DeviceID(end)
and not
camera_info(end).DeviceInfo.DeviceID
or
camera_info.DeviceInfo(end).DeviceID
or similarly for your comment to Walter. Instead of
a.InstalledAdaptors(end)
try
a(end).InstalledAdaptors
I am just guessing here. The output of whos or even better a description of the class and size of each object (and the nested objects) would make it easier to diagnose.

类别

Help CenterFile Exchange 中查找有关 Data Import and Analysis 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by