how to read an imagecaptured by webcam

3 次查看(过去 30 天)
%webcamlist
cam = webcam('Integrated Webcam');
preview(cam);
closePreview(cam)
img = snapshot(cam);
imshow(img)
%image(img)
clear('cam');
I = imread(img);
srcFiles1 = dir('C:\b\*.bmp');
for j = 1 : length(srcFiles1)
filename1 = strcat('C:\b\',srcFiles1(j).name);
I2 = imread(filename1);
points = detectSURFFeatures(I);
length(points)
points2 = detectSURFFeatures(I2);
length(points2)
[features1, validPoints1] = extractFeatures(I, points);
[features2, validPoints2] = extractFeatures(I2, points2);
indexPairs = matchFeatures(features1, features2);
matchedPoints1 = validPoints1(indexPairs(:, 1), :);
matchedPoints2 = validPoints2(indexPairs(:, 2), :);
showMatchedFeatures(I, I2, matchedPoints1, matchedPoints2, 'montage');
figure;
end
%end
output:
Error using imread>parse_inputs (line 450)
The file name or URL argument must be a character vector.
Error in imread (line 322)
[filename, fmt_s, extraArgs, was_cached_fmt_used] = parse_inputs(cached_fmt, varargin{:});
Error in acquire (line 13)
[X, map] = imread(img);
Error using imread>parse_inputs (line 450)
The file name or URL argument must be a character vector.
Error in imread (line 322)
[filename, fmt_s, extraArgs, was_cached_fmt_used] = parse_inputs(cached_fmt, varargin{:});
Error in acquire (line 13)
[X, map] = imread(img);
i have captured an image using webcam and then am trying to compare this image with the images in the database.why is matlab unable to read image file?

回答(1 个)

Cris LaPierre
Cris LaPierre 2019-4-1
编辑:Cris LaPierre 2019-4-1
I think the issue here is that img is not a file, but a matrix of pixel values already. You therefore don't need to use imread to read it. It's already been 'read' in.
Try just using I=img;
  2 个评论
venus tyagi
venus tyagi 2019-4-1
It is working now.But the images have to be converted to gray format.the following error is coming when the acquired and the compared image are converted to gray.
Error in acquire (line 20)
I2 = rgb2gray(imread(filename1));
Cris LaPierre
Cris LaPierre 2019-4-1
Please share the entire error message. Would be nice to also include a sample image that produces this error.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Microscopy 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by