如何在MATLAB中加快帧速率?

时间:2013-04-04 21:42:24

标签: matlab image-processing computer-vision real-time image-recognition

问题本身。

我目前正在使用MATLAB开发实时图像识别软件,我在尝试使用网络摄像头加快帧速率方面遇到了一些麻烦。即使我只处理图像的一小部分(使用ROI裁剪),它也不会加快帧速率。

这让我相信我的每一帧(或者它们的大小,更具体)的计算都不是问题所在。所以,寻找答案,我做了简单的代码:

imaqreset;

% Turn the webcam on with a MJPG_6480x480 acquisition format.
webcam1 = videoinput('winvideo',1,'MJPG_640x480');
set(webcam1,'FramesPerTrigger',1);
set(webcam1,'TriggerRepeat',Inf);
triggerconfig(webcam1,'Manual');
start(webcam1);

% Pre-allocate for the variable wich will hold the frame rates over time.
a = zeros(1,100)';

% Acquire frames in a loop and saves the frame rate in each iteration.
for i=1:100

    % Starts the timer.
    tic;

    % Triggers the webcam1 to capture a frame.
    trigger(webcam1);

    % Saves the frame in a dummy variable (just to simulate the acquisition time)
    i1 = getdata(webcam1,1);

    % The frame rate for this iteration will 1/(time for iteration).
    a(i) = 1/toc;    
end

% Plots the frame rates over time.
plot(a);

% Cleans up.
delete(webcam1);

在我的电脑中,这段代码在12.4 fps左右运行稳定。现在,棘手的部分是:如果我将采集格式更改为“MJPG_160x120”,则代码以相同的帧速率运行。或者到MJPG_1280_1024' !!

这是否意味着无论MATLAB需要从网络摄像头获取图像的大小,我将能够在这台计算机上实现最快的帧速率,这个网络摄像头是~12.4fps?或者我错过了什么?

最后一件事......

在我的软件中(也就是说,不是上面发布的简化代码,而是我的实际代码,处理每一帧),处理整个帧时帧速率下降到大约7 fps,但是当计算机找到目标时(因此,使用ROI缩小搜索范围)帧速率回升到大约12 fps(不高,正如我所料)。对我来说,这是一个很好的证据,表明最大帧速率不是由我的代码决定的,而是由图像采集速度决定的。


任何帮助将不胜感激,谢谢!

0 个答案:

没有答案