Image Acquisition using a GUI
1 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
更多回答(1 个)
Image Analyst
2014-4-28
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Acquisition Support Packages for Hardware Adaptors (Generic Video Interface) 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!