image1.jpg, image2.jpg.....etc how?
30 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I want to save images without overwriting them whenever I hit the pushbutton. Can you please help me how save images without overwriting the original? What I want to do is whenever I'll hit the pushbutton, It will generated 1 image at a time without deleting the original.
here's my simple code.
vid = videoinput('winvideo',1);
set(vid, 'ReturnedColorSpace', 'RGB');
img = getsnapshot(vid);
imshow(img);
imwrite(img,'C:\Users\Sony Vaio\Documents\Appendix\images\image.jpg');
thank you :)
0 Commenti
Risposta accettata
Jeff E
il 11 Set 2013
counter = 1; %initialize filename increment
vid = videoinput('winvideo',1);
set(vid, 'ReturnedColorSpace', 'RGB');
img = getsnapshot(vid);
imshow(img);
savename = strcat('C:\Users\Sony Vaio\Documents\Appendix\images\image_' , num2str(counter) , '.jpg'); %this is where and what your image will be saved
imwrite(img, savename);
counter = counter +1; %counter should increment each time you push the button
Instead of using a counter, you could also use a timestamp, as from CLOCK or DATESTR.
4 Commenti
Più risposte (1)
Image Analyst
il 11 Set 2013
Lloyd:
Use sprintf() to construct a unique filename based on a loop counter. See the FAQ for details: http://matlab.wikia.com/wiki/FAQ#How_can_I_process_a_sequence_of_files.3F
baseFileName = sprintf('Frame %d.png', frameCounter);
fullFileName = fullfile(folder, baseFileName);
imwrite(img, fullFileName);
frameCounter = frameCounter + 1;
Put the above in a loop that keeps snapping and saving images until you stop it somehow.
3 Commenti
Image Analyst
il 12 Set 2013
So it's not in a loop - it's in a pushbutton callback. So you can either make frameCounter global or persistent, or you can get a directory listing, figure out what the highest number so far is, and then increment it (which is the most complicated and longest method but probably the most robust and reliable.)
Vedere anche
Categorie
Scopri di più su C4ISR in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!