이 페이지는 기계 번역을 사용하여 번역되었습니다. 최신 내용을 영문으로 보려면 여기를 클릭하십시오.
라이브 히스토그램이 있는 비디오 디스플레이
이 예제에서는 라이브 히스토그램을 설정하고 표시하는 방법을 보여줍니다.
Image Acquisition Toolbox™과 Image Processing Toolbox™를 함께 사용하면 라이브 히스토그램이 포함된 비디오 피드를 표시할 수 있습니다. 이 기능은 수동 제어를 사용하여 조리개 등의 카메라 설정을 보정할 때 유용할 수 있습니다. 이 예제에서는 PREVIEW 함수, 연관된 사용자 정의 업데이트 함수 및 IMHIST 함수를 사용하여 라이브 히스토그램 옆에 비디오 미리보기 창을 배치하는 방법을 보여줍니다. 여기의 기술은 다른 실시간 정보를 표시하는 데에도 사용할 수 있습니다. 예를 들어, 라이브 비디오 피드를 필터링된 버전의 비디오 옆에 배치할 수 있습니다.
비디오 피드와 히스토그램 클립을 시청하세요. (8초)
비디오 객체 및 그림 설정
% Access an image acquisition device. vidobj = videoinput('winvideo'); % Convert the input images to grayscale. vidobj.ReturnedColorSpace = 'grayscale';
비디오와 동일한 크기의 이미지 객체는 수신 프레임을 저장하고 표시하는 데 사용됩니다.
% Retrieve the video resolution. vidRes = vidobj.VideoResolution; % Create a figure and an image object. f = figure('Visible', 'off'); % The Video Resolution property returns values as width by height, but % MATLAB images are height by width, so flip the values. imageRes = fliplr(vidRes); subplot(1,2,1); hImage = imshow(zeros(imageRes)); % Set the axis of the displayed image to maintain the aspect ratio of the % incoming frame. axis image;
새 프레임이 나올 때마다 호출되는 UpdatePreviewWindowFcn 콜백 함수를 지정합니다. 콜백 함수는 새로운 프레임을 표시하고 히스토그램을 업데이트하는 역할을 합니다. 또한 프레임에 사용자 정의 처리를 적용하는 데 사용할 수도 있습니다. 이 콜백을 사용하는 방법에 대한 자세한 내용은 PREVIEW 함수에 대한 설명서에서 확인할 수 있습니다. 이 콜백 함수 자체는 update_livehistogram_display.m 파일에 정의되어 있습니다.
setappdata(hImage,'UpdatePreviewWindowFcn',@update_livehistogram_display);
콜백 함수 정의
% Here are the contents of update_livehistogram_display.m which contains % the callback function. dbtype('update_livehistogram_display.m')
1 function update_livehistogram_display(obj,event,hImage) 2 % This callback function updates the displayed frame and the histogram. 3 4 % Copyright 2007-2017 The MathWorks, Inc. 5 % 6 7 % Display the current image frame. 8 set(hImage, 'CData', event.Data); 9 10 % Select the second subplot on the figure for the histogram. 11 subplot(1,2,2); 12 13 % Plot the histogram. Choose 128 bins for faster update of the display. 14 imhist(event.Data, 128); 15 16 % Refresh the display. 17 drawnow
미리보기 시작
% The PREVIEW function starts the camera and display. The image on which to % display the video feed is also specified. preview(vidobj, hImage); % View the histogram for 30 seconds. pause(30);
위는 히스토그램과 비디오 피드의 샘플 이미지입니다.
% Stop the preview image and delete the figure.
stoppreview(vidobj);
delete(f);
비디오 입력 객체가 더 이상 필요하지 않으면 관련 변수를 삭제하고 지웁니다.
delete(vidobj)
clear vidobj