Can someone please explain to me what the code below isnt working?
myFolderdepth = 'C:\Users\owner\Desktop'; %Specify Directory to get image from
Depth = dir (fullfile(myFolderdepth,'shower_depth','*.png'))%%Get images from file named shower_depth
Depth_name = {Depth.name}'; %gets the name
figure;
imshow(Depth_name{3})
The error message I get is as follows:
Error using getImageFromFile (line 11)
Cannot find the specified file:
"Depth_003.png".
The directory I am working in is: C:\Users\owner\Desktop
The name of the pictures are Depth_001,Depth_002,Depth_003,......
Oddly enough, I have another folder that has images and if I change the 'shower_depth' to the other folder name, it works fine.
Thank you!
P.S I did some further experimentation, it turns out its because of the way the image is named; if its Depth_01.png thats fine it works but Depth_001.png is not okay
Anyone knows why?
The following command:
Depth = dir (fullfile(myFolderdepth,'shower_depth','*.png'))
only gets the relative names of the files. This means that the file names are only retrieved, not the full path to the file. Take a look at the error that you're getting:
Error using getImageFromFile (line 11)
Cannot find the specified file: "Depth_003.png".
Do you see the path of where your images in the above file name? Nope! You only see the file stored in the directory. You need to specify the full path of where the image is located.
What you need to do is append the directory as well as the image itself as the string you supply to imshow:
myFolderdepth = 'C:\Users\owner\Desktop'; %Specify Directory to get image from
Depth = dir (fullfile(myFolderdepth,'shower_depth','*.png'))%%Get images from file named shower_depth
Depth_name = {Depth.name}'; %gets the name
figure;
imshow(fullfile(myFolderDepth, Depth_name{3})); %// CHANGE HERE
Depth_name is only the image name. You have to read the image before show it. The modified code is below:
im = imread(Depth_name{3});
imshow(Depth_name{3});
Related
I have a folder containing .ply files. I want to read them and plot them like an animation. Initially i am trying to read the files and plot individually using the following code:
testfiledir = 'Files\';
plyfiles = dir(fullfile(testfiledir, '*.ply'));
for k=1:length(plyfiles)
FileNames = plyfiles(k).name;
plys=pcread(FileNames);
pcshow(plys)
end
But while running the script i get the error:
Error using pcread (line 51)
File "val0.ply" does not exist.
Error in read_pcd (line 6)
plys=pcread(FileNames);
val0.ply is one my first frame which is read in the variable 'plyfiles'
Where am I making mistake?
Use a datastore it is much easier and will keep track of everything for you. E.g.
ds = fileDatastore("Files/","ReadFcn",#pcread,"FileExtensions",".ply");
then you can read the files from it using read or readall, e.g.
while hasdata(ds)
plys = read(ds);
pcshow(plys)
end
It is slightly slower than if you can make the optimal implementation, but I prefer it big-time for its ease.
hello evryone
wanna load file from a specific path writen in an edit box named by 'Load_text', i got the path from the edit box using :
pth=get(handles.Load_text,'string');
then i used 'dir' as follow:
S=dir(fullfile([pth '*.bmp']));
that what cause me an errur . so any ideas ?
If you want to load a file then why you are using dir?
Since you have the file's name, then you can create the fullpath as you do with the fullpath method and check its existence with exists.
If the file exists, then you can load it with all available methods from MATLAB.
Keep in mind that this means that the file is in the same directory as your GUI files. If it is in another then you will have to add it in the fullpath call.
fullpath online doc: http://www.mathworks.com/help/matlab/ref/fullfile.html
exists online doc: http://www.mathworks.com/help/matlab/ref/exist.html
Does the save function in Matlab save the thing saved in the same project file?
I'm trying to save a vector as 'mat' file.
This is my code :
function facePts = getFacePts(faceFileName)
if(exist('faceFileName','file')==2)
facePts=load('faceFilename.mat');
return;
end
img=imread(faceFileName,'tif');
showImage(img);
[x,y]=ginput(3);
facePts=[x,y]';
facePts=facePts(:);
save faceFileName.m, facePts; %%%%% HERE
end
The function compiles but I can't find the file I saved
I guess you want to do this:
save('faceFileName.mat', 'facePts');
Ok, so I figuered out that the path of the current folder wasn't the path of my Project.
I changed that by going to 'Desktop' in the Bar, checked 'Current Folder' and chaged the path there.
Now it works !
I have a project with a image stored as a logo that I wish to use.
URL logoPath = new MainApplication().getClass().getClassLoader().getResource("img/logo.jpg");
Using that method I get the URL for the file and convert it to string. I then have to substring that by 5 to get rid of this output "file:/C:/Users/Stephen/git/ILLA/PoC/bin/img/logo.jpg"
However when I export this as a jar and run it I run into trouble. The URL now reads /ILLA.jar!/ and my image is just blank. I have a gut feeling that it's tripping me up so how do I fix this?
Cheers
You are almost there.
Images in a jar are treated as resources. You need to refer to them using the classpath
Just use getClass().getResource: something like:
getClass().getResource("/images/logo.jpg"));
where "images" is a package inside the jar file, with the path as above
see the leading / in the call - this will help accessing the path correctly (using absolute instead of relative). Just make sure the path is correct
Also see:
How to includes all images in jar file using eclipse
See here: Create a file object from a resource path to an image in a jar file
String imgName = "/resources/images/image.jpg";
InputStream in = getClass().getResourceAsStream(imgName);
ImageIcon img = new ImageIcon(ImageIO.read(in));
Note it looks like you need to use a stream for a resource inside an archive.
i m creating a project in gwt (point) is project name ...
i want to store a image in point/war/images folder, whaich i gave the full path like C:\Documents and Settings\computer\workspace\m\war\images\ tthe the iamge will stored in images folder but i want to give the default path
i give "../war/images/" as default path, but this give me error (he system cannot find the path specified )
can any body help to give the default path
Usually you put images in the war/images directory, and you access them like
Image img = new Image("images/my_image.jpg")
You may also read this thread, and this question.