フィルターのクリア

capture a image using matlab

6 ビュー (過去 30 日間)
vikash
vikash 2013 年 10 月 7 日
コメント済み: Kamal Abuqaaud 2017 年 9 月 7 日
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 件のコメント
Kamal Abuqaaud
Kamal Abuqaaud 2017 年 9 月 7 日
Try removing this part from your code "2,'USB2.0 PC CAM'" for videoinput command.

サインインしてコメントする。

回答 (1 件)

Image Analyst
Image Analyst 2013 年 10 月 7 日
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!

Translated by