필터 지우기
필터 지우기

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