Gre*_*ack 1 matlab loops image matlab-figure
我循环触发视频,利用其数据,并使用imshow. 外置摄像头有 30 fps,但是imshow在循环中使用时,它将帧速率大幅降低到 5-7 fps 左右。有解决方法吗?下面是片段:
Vid = videoinput('some_cam',1);
triggerconfig(Vid, 'manual');
Vid.FramesPerTrigger = 1;
Vid.TriggerRepeat = inf;
viewer = vision.DeployableVideoPlayer();
start(Vid);
himg = figure;
while ishandle(himg)
trigger(Vid);
[image, timeStamp] = getdata(Vid);
imshow(image); %This line significantly reduce the performance
%Do something with the images...This part is important and would need as many frame rate as possible
end
Run Code Online (Sandbox Code Playgroud)
所以我在想,如果我发送imshow到另一个线程上运行怎么办?但在这种情况下,我不知道该怎么做,因为我需要访问image. 预览或任何其他命令在我的情况下不起作用,因为我必须image事先进行一些更改。
在 MATLAB 中加速动画图形的方法是不使用诸如imshow或 之类的函数plot,它们清除轴、创建新图形对象、调整轴属性等。这些函数在幕后做了很多不必要的工作在屏幕上制作动画时。
相反,修改现有的图形对象:
start(Vid);
hfig = figure;
trigger(Vid);
[image, timeStamp] = getdata(Vid);
himg = imshow(image);
while ishandle(hfig)
trigger(Vid);
[image, timeStamp] = getdata(Vid);
himg.CData = image; % update the existing graphics object
%...
end
Run Code Online (Sandbox Code Playgroud)
对于非常旧版本的 MATLAB,请使用set(himg,'CData',image).
您可能需要drawnow在循环内添加一个以查看图像更改。
| 归档时间: |
|
| 查看次数: |
68 次 |
| 最近记录: |