Image Acquisition using a GUI
Mostrar comentarios más antiguos
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
Respuesta aceptada
Más respuestas (1)
Image Analyst
el 28 de Abr. de 2014
0 votos
If you're only capturing 1 frame per trigger, then just try using getsnapshot() instead of getdata(). And don't put the file type into imwrite(). Let it figure it out itself from the filename you supply it. Let me know how that works.
1 comentario
Categorías
Más información sobre Image Acquisition Support Packages for Hardware Adaptors (Generic Video Interface) en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!