How to save webcam image in gui to a certain folder without push button
Show older comments
I have interfaced webcam with matlab gui and able to take images. I have two push buttons Preview & Take Image. I want to take image with "Take Image" push button & my taken images to be stored with my desired names and folder as we do in imsave normally but here I am unable.Can anyone help me, the closest was below but it is introducing new push button.
function pbTP_Callback(hObject, eventdata, handles)
vid = videoinput('winvideo', 1, 'YUY2_1024x768');
vid.FramesPerTrigger = 1;
vid.ReturnedColorspace = 'rgb';
triggerconfig(vid, 'manual');
vidRes = get(vid, 'VideoResolution');
imWidth = vidRes(1);
imHeight = vidRes(2);
nBands = get(vid, 'NumberOfBands');
hImage = image(zeros(imHeight, imWidth, nBands), 'parent', handles.axPreview)
preview(vid, hImage);
start(vid);
pause(5);
trigger(vid);
stoppreview(vid);
im1 = getdata(vid);
imwrite(im1, 'myimage.jpg');
8 Comments
Geoff Hayes
on 24 Jul 2016
Snowleopard - what is the purpose of the Take Image push button? Does it save the current image to file? As for the code that you have provided, pbTP_Callback, what does this correspond to? It seems that it previews and then saves the image to file. Are you trying to split this function into two, for each of your buttons?
Snowleopard
on 24 Jul 2016
Geoff Hayes
on 24 Jul 2016
Snowleopard - what does the Preview button do? Does it do the same as the above but just doesn't write the images to file? Is the problem with your above code that
imwrite(im1, 'myimage.jpg');
always overwrites the last saved image? If so, why not just call imsave from within the pbTP_Callback function?
Snowleopard
on 25 Jul 2016
Geoff Hayes
on 25 Jul 2016
Please clarify what you mean by I was unable to use imsave. Did you observe any errors and, if so, what were they?
Snowleopard
on 25 Jul 2016
Edited: Snowleopard
on 25 Jul 2016
Geoff Hayes
on 26 Jul 2016
According to imsave, it creates a Save Image tool in a separate figure that is associated with the image in the current figure, called the target image. Presumably your current figure is the GUI and so this is probably not the correct approach. Try using either imputfile or uiputfile which will allow you (or the user) to select the filename and folder where he or she wishes to save the file.
Snowleopard
on 27 Jul 2016
Accepted Answer
More Answers (0)
Categories
Find more on Image Preview and Device Configuration in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!