이 페이지는 기계 번역을 사용하여 번역되었습니다. 영어 원문을 보려면 여기를 클릭하십시오.
수집율 결정
이 예제에서는 GETDATA 함수가 제공하는 타임스탬프를 사용하는 방법과 MATLAB® 함수를 사용하여 장치 프레임 속도를 추정하는 방법을 보여줍니다.
1단계: 장치에 접근하고 구성합니다.
비디오 입력 객체를 생성하고 비디오 소스 객체에 액세스하여 원하는 수집 속도를 구성합니다. 수집 속도는 비디오 소스 객체의 장치별 FrameRate 속성 값에 따라 결정됩니다.
FrameRate는 장치별 속성이므로 일부 장치에서는 지원되지 않을 수 있습니다.
% Access an image acquisition device. vidobj = videoinput('winvideo', 1); % Configure the number of frames to log. vidobj.FramesPerTrigger = 50; % Skip the first few frames the device provides % before logging data. vidobj.TriggerFrameDelay = 5; % Access the device's video source. src = getselectedsource(vidobj); % Determine the device specific frame rates (frames per second) available. frameRates = set(src, 'FrameRate')
frameRates =
'30.0000'
'24.0000'
'8.0000'
% Configure the device's frame rate to the highest available setting.
src.FrameRate = frameRates{1};
actualRate = str2num( frameRates{1} )
actualRate =
30
2단계: 데이터 기록 및 검색.
수집을 시작하고 기록된 프레임과 타임스탬프를 검색합니다.
% Start the acquisition. start(vidobj) % Wait for data logging to end before retrieving data. Set the wait time % to be equal to the expected time to acquire the number of frames % specified plus a little buffer time to accommodate overhead. waittime = actualRate * (vidobj.FramesPerTrigger + vidobj.TriggerFrameDelay) + 5; wait(vidobj, waittime); % Retrieve the data and timestamps. [frames, timeStamp] = getdata(vidobj);
3단계: 인수율을 계산합니다.
각 프레임의 타임스탬프를 표시하면 수집 속도가 일정하다는 것을 확인할 수 있습니다.
% Graph frames vs time. plot(timeStamp,'x') xlabel('Frame Index') ylabel('Time(s)')

평균 시간 차이는 예상 수집률과 비교하기 위해 결정될 수도 있습니다.
% Find the time difference between frames. diffFrameTime = diff(timeStamp); % Graph the time differences. plot(diffFrameTime, 'x'); xlabel('Frame Index') ylabel('Time Difference(s)') ylim([0 .12])

% Find the average time difference between frames.
avgTime = mean(diffFrameTime)
avgTime =
0.0333
% Determine the experimental frame rate.
expRate = 1/avgTime
expRate = 30.0245
실험적 프레임 속도와 알려진 프레임 속도 사이의 시간 차이를 비교하면 오차율을 계산할 수 있습니다. 일반적인 USB 웹 카메라를 수집 장치로 사용하므로 실제 장치 프레임 속도가 변동될 것으로 예상됩니다.
% Determine the percent error between the determined and actual frame rate.
diffRates = abs(actualRate - expRate)
diffRates =
0.0245
percentError = (diffRates/actualRate) * 100
percentError =
0.0817
% Once the video input object is no longer needed, delete % it and clear it from the workspace. delete(vidobj) clear vidobj