MATLAB: Image Acquisition using a GUI

guiimageImage Acquisition Toolboxjpegkinectpnguiputfilevideovideo processing

Hi guys im having a problem acquiring an image using the GUI , so once i click the button i should be able to get a photo from a the live video in the GUI here is my code
if true
% --- Executes on button press in pbCapture.
function pbCapture_Callback(hObject, eventdata, handles)
vid = videoinput('kinect', 2);
vid.ROIPosition = [89 81 137 140];
vid.FramesPerTrigger = 1;
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);
capt1 = getdata(vid);
[FileName, PathName] = uiputfile('*.jpg', 'Save As');
Name = fullfile(PathName,FileName);
imwrite(capt1, Name, 'jpg');
end
i can save the image in PNG but i cant save it in JPEG i get this error
Error using writejpg>set_jpeg_props (line 184) UINT16 image data requires bitdepth specifically set to either 12 or 16.
Error in writejpg (line 50) props = set_jpeg_props(data,varargin{:});
Error in imwrite (line 473) feval(fmt_s.write, data, map, filename, paramPairs{:});
Error in samples_aquasition>pbCapture_Callback (line 100) imwrite(capt1, Name, 'jpg');
Error in gui_mainfcn (line 96) feval(varargin{:});
Error in samples_aquasition (line 42) gui_mainfcn(gui_State, varargin{:});
Error in@(hObject,eventdata)samples_aquasition('pbCapture_Callback',hObject,eventdata,guidata(hObject)) Error while evaluating uicontrol Callback
i really need to save the file in JPEG , and i dont want to read the image again and convert it to JPEG after saving it as PNG. thanks

Best Answer

Thank you image Analyst for the fast replay but i think that i found the solution to my problem :)!
instead of using
capt1 = getdata(vid);
i used
capt1 = getdata(vid,1,'uint8');
because getdata(vid) will get the data as uint 16 by default and jpg works with uint8 so we have to specify that