快速加速 [英] getsnapshot speedup

查看:90
本文介绍了快速加速的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

getsnapshot 函数需要花费大量时间执行,因为(我猜)每次调用时都会初始化网络摄像头。如果你想获得具有高帧率的图像,这是一个问题。

the getsnapshot function takes a lot of time executing since (I guess) initializes the webcam every time is called. This is a problem if you want to acquire images with a high framerate.

我随便发现的一招就是调用 预览 功能,可使网络摄像头处理程序保持打开状态 getsnapshot 几乎是即时的,但它保持一个小的预览窗口打开:

I trick I casually discovered is to call the preview function, which keeps the webcam handler open making getsnapshot almost instantaneous, but it keeps a small preview window open:

% dummy example
cam = videoinput(...);
preview(cam);

while(1)
    img = getsnapshot(cam);
    % do stuff
end

是否有更清洁的加速方式 getsnapshot ? (没有打开预览窗口)

Is there a "cleaner" way to speedup getsnapshot? (without preview window opened)

推荐答案

您可以使用专为视觉应用而设计的新机器视觉工具箱。请参阅以下代码:

You could use the new "machine vision" toolbox which is specially built for vision applications. See code below:

vid = videoinput('winvideo', 1, 'RGB24_320x240'); %select input device

hvpc = vision.VideoPlayer;   %create video player object

src = getselectedsource(vid);
vid.FramesPerTrigger =1;
vid.TriggerRepeat = Inf;
vid.ReturnedColorspace = 'rgb';
src.FrameRate = '30';
start(vid)

%start main loop for image acquisition
for t=1:500
  imgO=getdata(vid,1,'uint8');    %get image from camera
  hvpc.step(imgO);    %see current image in player
end

如您所见,您可以获取图像用getdata。 Matlab中视频应用程序的瓶颈是预览窗口,它大大延迟了代码。新的vision.VideoPlayer 很多更快(我在Matlab的实时视觉应用程序中使用了这个代码。当我编写没有视觉工具箱的第一个版本时,实现大约18 fps的帧速率和使用新工具箱大约70个!)。

As you can see, you can acquire the image with getdata. The bottleneck in video applications in Matlab was the preview window, which delayed to code substantially. The new vision.VideoPlayer is a lot faster (i have used this code in real time vision applications in Matlab. When i had written the first version without the vision toolbox, achieving frame rates at about 18 fps and using the new toolbox got to around 70!).

注意:我需要使用Matlab的图像应用程序速度,你应该考虑通过mex使用OpenCV库来获得一个在图像处理方面表现不错。

Note: I you need speed in image apps using Matlab, you should really consider using OpenCV libs through mex to get a decent performance in image manipulation.

这篇关于快速加速的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆