如何在matlab中读取指定文件夹中的图像?

时间:2021-07-22 19:37:18
myPath= 'C:\Users\Prienka\Documents\MATLAB\frames'; 
a =dir(fullfile(myPath,'*.png'));
a(1).name
a(end).name
Im1 = imread(a(1).name);
Im2 = imread(a(end).name);
Im1 = rgb2gray(Im1);
Im2 = rgb2gray(Im2);
hn1 = imhist(Im1)./numel(Im1); %initial pixel postion
hn2 = imhist(Im2)./numel(Im2); %final pixel position
d = sum(sqrt(hn2-hn1).^2); 
d=sprintf('%.0f',d);
obj = VideoReader('traffic.mp4')
x=obj.FrameRate
velocity=d/x;
velocity=sprintf('%.0f',velocity)
if velocity >= 63
    msgbox('SPEED EXCEEDED' ) 
end

this is my code for calculating the velocity of a vehicle in a vedio... the problem is i have extracted all the movie frames in a different folder named "frames"... here whenever m trying to run the code its showing a error like this "Error using imread (line 350) File "001.png" does not exist.

这是我在视频中计算车辆速度的代码…问题是,我已经在一个名为“frame”的不同文件夹中提取了所有的电影帧。在这里,每当m试图运行代码时,它的显示错误就像这样“使用imread(行350)文件”001。png”并不存在。

Error in pikz (line 5) Im1 = imread(a(1).name);" my file name is pikz.m

错误在pikz(第5行)Im1 = imread(a(1).name);“我的文件名是pikz.m。

1 个解决方案

#1


0  

In your current working directory (pwd) the file does not exist. Dir only returns relative path like '001.png'. You have to use fullfile to get the absolute path like 'C:\Users\Prienka\Documents\MATLAB\frames\001.png' to pass it to imread

在当前工作目录(pwd)中,文件不存在。Dir只返回相对路径,如“001.png”。你必须使用fullfile来获得绝对路径,如“C:\ \ \ \Prienka\Documents\MATLAB\frame \001”。png将它传递给imread。

#1


0  

In your current working directory (pwd) the file does not exist. Dir only returns relative path like '001.png'. You have to use fullfile to get the absolute path like 'C:\Users\Prienka\Documents\MATLAB\frames\001.png' to pass it to imread

在当前工作目录(pwd)中,文件不存在。Dir只返回相对路径,如“001.png”。你必须使用fullfile来获得绝对路径,如“C:\ \ \ \Prienka\Documents\MATLAB\frame \001”。png将它传递给imread。