how to use imwrite command to save image in folder

8 views (last 30 days)
i am using webcam in matlab.to save webcam images and video i used this code clc ; % clearing the command window n = input(' Enter the number of photos to be taken: '); intervel = input(' Enter the time(seconds) gap between succeessive photos: '); photosave = input(' Do you want to save the files(y/n): ','s'); disp('Please wait...'); outputFolder = fullfile(cd, 'frames'); if ~exist(outputFolder, 'dir') mkdir(outputFolder); end obj = videoinput('winvideo',1); preview(obj); disp('Press Enter to start after webcam initialization.'); pause; disp('First shot will taken after 1 second'); pause(1); for i=1:n img=getsnapshot(obj); image(img); if(photosave == 'y') outputBaseFileName = sprintf('fr%d.png',i); outputFullFileName = fullfile(outputFolder, outputBaseFileName); imwrite(img,outputFullFileName,'jpg'); end pause(intervel); end closepreview;
disp('The program successfully taken the photos'); disp('Done.');
i got error to run mkdir , imwrite commands
Error using imwrite Unable to open file "C:\Program Files\MATLAB\MATLAB Production Server\R2014a\bin\frames\fr1.png" for writing. You may not have write permission. please tel me how to get write permission
  2 Comments
David Young
David Young on 13 Feb 2015
The question of how to get write permission on a folder depends on your operating system. It's not really a MATLAB question, and is probably better asked on a forum that deals with Windows or Linux issues, as appropriate, though it's possible someone here will offer a suggestions.
Although it probably doesn't matter for this question, your code is unreadable. You can make it readable using the "{} Code" button.
David Young
David Young on 13 Feb 2015
Also, it strikes me as odd that you want to write your image into a folder in the MATLAB tree. Why not write it into one of your own working folders? Then the permissions problem wouldn't arise.

Sign in to comment.

Answers (0)

Categories

Find more on Environment and Settings in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!