capture a image using matlab
8 次查看(过去 30 天)
显示 更早的评论
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
2017-9-7
Try removing this part from your code "2,'USB2.0 PC CAM'" for videoinput command.
回答(1 个)
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 National Instruments Frame Grabbers 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!