problem acquiring the video from webcam

조회 수: 7 (최근 30일)
Max
Max 2012년 2월 19일
댓글: Jibin Lukose 2017년 10월 2일
hi every one .i am trying to acquire the video frames using the following codes .
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
a = imaqhwinfo;
[camera_name, camera_id, format] = getCameraInfo(a);
vid = videoinput(camera_name, camera_id, format);
% Set the properties of the video object
set(vid, 'FramesPerTrigger', Inf);
set(vid, 'ReturnedColorspace', 'rgb')
vid.FrameGrabInterval = 5;
%start the video aquisition here
start(vid)
while(vid.FramesAcquired<=200)
data = getsnapshot(vid);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%the camera info routine is as follows
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));
%%%%%end of routine %%%
following are the errors i am getting
??? 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);
Error in ==> redObjectTrack at 2 [camera_name, camera_id, format] = getCameraInfo(a);
please help me out of this ..Same codes are working for a desktop PC and a webcam..But when i try this on my laptop its not working ..

채택된 답변

Image Analyst
Image Analyst 2012년 2월 19일
You can't have a function defined down below your script. I didn't see a function line for the first chunk of your code, which you need. You need something like this as the first line:
function redObjectTrack()
When I do that it runs the getCameraInfo() function fine. All I did was to remove the semicolons so that I could see the outputs, and I renamed format to format1 so as to not overwrite a built-in MATLAB function and it printed out this:
camera_name =
winvideo
camera_info =
AdaptorDllName: 'C:\Program Files\MATLAB\R2011b\toolbox\imaq\imaqadaptors\win64\mwwinvideoimaq.dll'
AdaptorDllVersion: '4.2 (R2011b)'
AdaptorName: 'winvideo'
DeviceIDs: {[1]}
DeviceInfo: [1x1 struct]
camera_id =
1
resolution =
RGB24_960x720
  댓글 수: 3
Walter Roberson
Walter Roberson 2017년 7월 3일
(As of R2016b it become possible to put a function below a script, but that was not possible in the 2012 time frame.)
Jibin Lukose
Jibin Lukose 2017년 10월 2일
Me don't have any idea with this MATLAB Track coding, so could you share the edited code, that would run successfully please? @Max & @Image Analyst

댓글을 달려면 로그인하십시오.

추가 답변 (3개)

Jiro Doke
Jiro Doke 2012년 2월 19일
Put a breakpoint on line 4 of your function getCameraInfo, and explore your variable camera_info. Maybe your laptop isn't recognizing your webcam.

Walter Roberson
Walter Roberson 2012년 2월 19일
camera_info is a structure array directly or at the DeviceInfo level.
  댓글 수: 1
Max
Max 2012년 2월 24일
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));
it was at DeviceInfo level

댓글을 달려면 로그인하십시오.


WORAWUT KUNGHUN
WORAWUT KUNGHUN 2017년 7월 3일
a = imaqhwinfo;
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));
vid = videoinput(camera_name, camera_id, resolution);
set(vid, 'FramesPerTrigger', Inf);
set(vid, 'ReturnedColorspace', 'rgb')
vid.FrameGrabInterval = 5;
start(vid)
change the resolution in image acquired by webcam command.

Community Treasure Hunt

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

Start Hunting!

Translated by