How to save webcam image in gui to a certain folder without push button
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Snowleopard
am 24 Jul. 2016
Kommentiert: Geoff Hayes
am 10 Aug. 2016
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 Kommentare
Geoff Hayes
am 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.
Akzeptierte Antwort
Geoff Hayes
am 27 Jul. 2016
snowleopoard - Did you get an error message when you tried to save the file, and if so, what was it?
I suspect that the above error is when you pressed the Take Image button a second time. Is that the case? If so, the problem is probably due to
vid = videoinput('winvideo', 1, 'YUY2_1024x768');
You are creating a new video input object without deleting the previous one (created the first time you pressed the button). Either add a line to delete your object before the callback exits (so after you've saved to file), or use a single object that you create once and save to your handles object. Something like
function pbTP_Callback(hObject, eventdata, handles)
if ~isfield(handles,'vidObject')
handles.vidObject = videoinput('winvideo', 1, 'YUY2_1024x768');
guidata(hObject,handles);
end
% now do same as what you have written, replacing vid with handles.vidObject
The above code checks to see if the vidObject has already been created and is part of the handles structure. If not, it creates it and saves it to handles using guidata.
5 Kommentare
Geoff Hayes
am 10 Aug. 2016
That's my mistake. Change
pause(str2double(handles.edit2,'String'))
to
pause(str2double(get(handles.edit2,'String')))
Note the missing get.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Image Preview and Device Configuration finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!