Clear Filters
Clear Filters

capture a image using matlab

6 views (last 30 days)
vikash
vikash on 7 Oct 2013
Commented: Kamal Abuqaaud on 7 Sep 2017
i am trying to capture image in matlab using following commands:
cam=videoinput('winvideo',2,'USB2.0 PC CAM')
preview(cam)
start(cam)
frame=getsnapshot(cam);
imshow(frame);
But it shows error: ??? Error using ==> videoinput.videoinput at 329 Device files are not supported by this device. See IMAQHWINFO.
Error in ==> webcam at 2
cam=videoinput('winvideo',2,'USB2.0 PC CAM')
---- using command imaqhinfo('winvideo',2) returns:
ans =
DefaultFormat: 'YUY2_1280x1024'
DeviceFileSupported: 0
DeviceName: 'USB2.0 PC CAMERA'
DeviceID: 2
ObjectConstructor: 'videoinput('winvideo', 2)'
SupportedFormats: {1x7 cell}
which confirms the device name and deviceID ---
then i tried a different set of codes:
if(~isdeployed)
cd(fileparts(which(mfilename)));
end
clc;
clear;
close all;
imtool close all;
workspace;
fontSize = 36;
vid = videoinput('winvideo',2,'USB2.0 PC CAMERA');
vid.FramesPerTrigger = 1;
preview(vid);
start(vid);
rgbImage = getdata(vid);
subplot(1,2, 1);
imshow(rgbImage);
title('Initial Image', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'Position', get(0,'Screensize'));
% Save this image to disk.
fullImageFileName = fullfile(pwd, 'myfirstimage.jpg');
imwrite(rgbImage,fullImageFileName);
% Read it back in to check it.
recalledImage = imread(fullImageFileName);
subplot(1,2, 2);
imshow(recalledImage);
title('Recalled Image', 'FontSize', fontSize);
But again, there is same error message ----
please help me to solve the issue
thanks in advance
  1 Comment
Kamal Abuqaaud
Kamal Abuqaaud on 7 Sep 2017
Try removing this part from your code "2,'USB2.0 PC CAM'" for videoinput command.

Sign in to comment.

Answers (1)

Image Analyst
Image Analyst on 7 Oct 2013
I think the "device format" should be 'YUY2_1280x1024'. The problem is probably that you put in the "Device Name" instead of the "Device Format" for the third argument to videoinput().
vid = videoinput('winvideo', 2, 'YUY2_1280x1024');
If that doesn't work, then can you operate the camera from within imaqtool? If so, what does the session log say? You should be able to copy and paste the session log into your m-file to do the same thing.

Community Treasure Hunt

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

Start Hunting!