주요 콘텐츠

이 페이지는 기계 번역을 사용하여 번역되었습니다. 최신 내용을 영문으로 보려면 여기를 클릭하십시오.

알파 블렌딩 스트리밍 이미지 쌍

이 예제에서는 이미지 수집 장치에서 스트리밍 이미지를 캡처하고, 각 프레임에 대한 온라인 이미지 처리를 수행하고, 처리된 프레임을 표시하는 방법을 보여줍니다.

그 결과, 두 이미지 중 하나는 고정된 진자이고 다른 하나는 움직이는 진자이며, 움직이는 형상이 투명하게 보입니다.

1단계: 배경 이미지 캡처

움직이는 특징 없이 배경의 스냅샷을 기록하고 표시합니다.

% Access an image acquisition device.
vidobj = videoinput('winvideo', 1, 'RGB24_320X240');

% Using the preview window, properly position the camera.
preview(vidobj)
pause(1)

% Capture an image with no moving features.
background = getsnapshot(vidobj);

% Convert the background from uint8 to double.
background = double(background)/255;

% Display the background image in a figure window.
imagesc(background);

2단계: 기록된 데이터 처리

수집한 이미지 데이터를 사용하여 온라인 이미지 처리를 수행하고, 처리된 이미지를 그림 창에 표시합니다.

스트리밍된 각 이미지 프레임에 대해 해당 프레임과 배경 이미지 간의 선형 조합을 계산합니다. 선형 결합은 두 이미지를 효과적으로 알파 블렌딩하여 움직이는 특징이 투명하게 나타나도록 합니다.

% Set the object into motion.
pause(2);

% Configure the acquisition.
vidobj.FramesPerTrigger = 20;

% Start the acquisition.
start(vidobj)

% While logging data, perform a linear combination between
% the current and background images.
current = getdata(vidobj, 1, 'double');
transparent = (current * 0.5) + (background * 0.5);

% Display the processed image.
imagesc(transparent);

% Repeat for all remaining images.
while (vidobj.FramesAvailable > 0),
    % Perform a linear combination between the current and background images.
    current = getdata(vidobj, 1, 'double');
    transparent = (current * 0.5) + (background * 0.5);

    % Display the processed image.
    imagesc(transparent);
end

% Once the video input object is no longer needed, delete
% it and clear it from the workspace.
delete(vidobj)
clear vidobj