问题本身。
我目前正在使用 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 左右(如我所料,没有更高)。对我来说,这是一个很好的证据,证明最大帧速率不是由我的代码决定的,而是由图像采集速度决定的。
任何帮助将不胜感激,在此先感谢!