Can any one help me to fix error with imread()?
1 次查看(过去 30 天)
显示 更早的评论
The code is...
imgListFile = fopen('image_class.txt', 'r');
F = zeros(6, 24); L = cell(6, 1);
tline = fgetl(imgListFile); currentLine = 1;
while ischar(tline)
disp(tline)
splittedLine = regexp(tline, ',[ ]*', 'split');
imagePath = fullfile('imgs', splittedLine{1});
I = imread(imagePath);
f = sfta(I, 4);
F(currentLine, :) = f;
% Store the image label.
L{currentLine} = splittedLine{2};
tline = fgetl(imgListFile);
currentLine = currentLine + 1;
end;
fclose(imgListFile);
I am getting following error...
Error using imread (line 347)
Can't open file "imgs" for reading;
you may not have read permission.
Error in classifymy (line 12)
I = imread(imagePath);
I have checked read permission, but it is there? Not able to trace where is problem? Thanks in advance
0 个评论
回答(2 个)
Geoff Hayes
2015-10-18
Nilima - it sounds like you don't have read permissions for this file (though is imgs the correct name for it?). To find out, look at the permissions for this file. If using a Linux or Unix OS, open a terminal window and go to the directory where this file is located. Type
ls -ag
to list all of the files in this directory along with their permissions. In order for you to have read permissions to this file you will need to see something like
-r--r--r--@ 1 staff 43279 15 Mar 2015 myImage.gif
The r is for read. If you don't see it for the appropriate group that you are in, then you will have to add it using chmod to change the file's permissions.
If using a Windows operating system, then you can use Explorer to open the properties of the file which you can then add the read permission to.
Walter Roberson
2015-10-18
At some point in the file you are encountering a line which is empty before its first comma. That is leaving you with an empty splittedLine{1} and the fullfile() is then leaving "imgs" as the directory name rather than converting it to "imgs\" or "imgs/" with no following file name.
5 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Audio and Video Data 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!