2011-03-30 8 views
2

Matlab을 처음 사용하고 Matlab에서 GUI를 프로그래밍하려고하는데 작은 창에서 랩톱에있는 웹캠을 표시합니다. 시작 단추가있을 때 함수를 만들려고합니다. 그것은 내가했던 스냅 샷을 5 초간 찍고 메인 윈도우에 이미지를 표시하기를 원한다. 나는 이것에 대한 도움이 필요하다. 또한 그림 크기를 더 큰 것으로 설정하는 방법. 다음은 내 MATLAB 코드는 내가 가이드를 사용하는 방법에 대한 이전 의견에 동의Matlab GUI 및 함수 프로그래밍

% Create a video input object. 
vid = videoinput('winvideo'); 

% Create a figure window. This example turns off the default 
% toolbar and menubar in the figure. 
hFig = figure('Toolbar','none',... 
     'Menubar', 'none',... 
     'NumberTitle','Off',... 
     'Name','LegoBot'); 




% Set up the push buttons 
uicontrol('String', 'Start Preview',... 
    'Callback', 'preview(vid)',... 
    'Units','normalized',... 
    'Position',[0 0 0.15 .07]); 
uicontrol('String', 'Stop Preview',... 
    'Callback', 'stoppreview(vid)',... 
    'Units','normalized',... 
    'Position',[.17 0 .15 .07]); 
uicontrol('String', 'Close',... 
    'Callback', 'close(gcf)',... 
    'Units','normalized',... 
    'Position',[0.34 0 .15 .07]); 



% Create the text label for the timestamp 
hTextLabel = uicontrol('style','text','String','Timestamp', ... 
    'Units','normalized',... 
    'Position',[0.85 -.04 .15 .08]); 

% Create the image object in which you want to 
% display the video preview data. 
vidRes = get(vid, 'VideoResolution'); 
imWidth = vidRes(1); 
imHeight = vidRes(2); 
nBands = get(vid, 'NumberOfBands'); 
hImage = image(zeros(imHeight, imWidth, nBands)); 

% Specify the size of the axes that contains the image object 
% so that it displays the image at the right resolution and 
% centers it in the figure window. 
figSize = get(hFig,'Position'); 
figWidth = figSize(7); 
figHeight = figSize(8); 
set(gca,'unit','pixels',... 
     'position',[ ((figWidth - imWidth)/2)... 
        ((figHeight - imHeight)/2)... 
         imWidth imHeight ]); 

% Set up the update preview window function. 
setappdata(hImage,'UpdatePreviewWindowFcn',@mypreview_fcn); 

% Make handle to text label available to update function. 
setappdata(hImage,'HandleToTimestampLabel',hTextLabel); 

preview(vid, hImage); 
+0

나는 가이드, http://www.mathworks.com/help/techdoc/ref/guide.html의 외부 MATLAB의 GUI를 개발하는 것은 매우 어려운 작업이며, 대한 아니라는 것을 충분히 강조 할 수 초보자. – linuxuser27

+0

... 실제 질문은 무엇입니까? 내가 가이드를 사용하는 두 번째 linuxuser의 제안, 귀하의 경우에 도움이됩니까? 그렇지 않다면 실제 문제는 무엇입니까? –

답변

0

가, 나 또한 누군가가 여기 DAQ Matlab Webcam하신대로, 데이터 accquition 도구 상자를 사용하는 것이 좋습니다 그 주위에 당신의 코드를 작성하려고 할 것입니다 경우 당신의 원하는 시간 간격으로 데이터를 수집하는 루프를 만들 수 있습니다. 도움이

희망,

0

재미는, 난 그냥이 문제를 처리하기 위해 오늘 아침에 코드를 썼다. 루프를 종료하기 위해 자신 만의 논리를 추가해야하지만 이것은 효과가 있습니다.

% Initialize variables 
objects = imaqfind; delete(objects); clear objects 
cameraOn = true; %Loop initialization 
counter = 0; 
fileName = 'OutputFile'; 

%Initialize Webcam Object 
vid = videoinput('winvideo'); 
src = getselectedsource(vid); 
get(src); 

% Configure Camera 
vid = videoinput('winvideo', 1, 'MJPG_640x480'); %Gotten from imaqtool 
src = getselectedsource(vid); 
triggerconfig(vid, 'manual'); 
src.ExposureMode = 'manual'; %Speeds up webcam to max 
src.BacklightCompensation = 'off'; %Speeds up webcam to max 

% Call Preview Window 
vid = videoinput('winvideo',1); 
preview(vid) 

% Begin snapshot collection 
while cameraOn == true; 
for ii = 5:-1:1 
    display([num2str(ii)]); %Display a countdown 
    pause(1); 
end 
snapshot = getsnapshot(vid); %Collect video frame 
counter=counter+1; 
imwrite(snapshot,[fileName,num2str(counter,3),'.png'],'png'); 
end 

% Stop previewing video data. 
stoppreview(vid); 

delete(vid); clear vid