Wednesday, 11 September 2013

MatLab (Image Processing, Image Acquisition) How to save captured images by webcam without overwriting the original file name?

MatLab (Image Processing, Image Acquisition) How to save captured images
by webcam without overwriting the original file name?

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.
Just like in digital cameras, whenever I will hit the trigger button, it
will save 1 image and the file name will be image1.jpg. So basically, if I
will push trigger again, it will capture 1 image again and the file name
will be image2.jpg and so on.
here is my code:
counter = 1; %initialize filename increment
vid = videoinput('winvideo',2);
set(vid, 'ReturnedColorSpace', 'RGB');
img = getsnapshot(vid);
imshow(img);
savename = strcat('C:\Users\Sony Vaio\Documents\Task\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
My code saves and keeps on overwriting the filename image1.jpg. To make
things clear
1 push to the pushbutton, 1 image saves.
it's like it will call the whole block code every hit at pushbutton. I
hope you guys can help me. I really troubled right now :( Thank you :)

No comments:

Post a Comment