image - 在循环内显示图像时减少循环开销
问题描述
我正在循环触发视频,利用它的数据,并使用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
所以我在想,如果我发送imshow
到另一个线程上运行呢?但在这种情况下,我不知道该怎么做,因为我需要访问image
. 预览或任何其他命令在我的情况下都不起作用,因为我必须image
事先进行一些更改。
解决方案
在 MATLAB 中加速动画图形的方法是不使用imshow
or之类的函数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
对于非常旧版本的 MATLAB,请使用set(himg,'CData',image)
.
您可能需要drawnow
在循环内添加一个以查看图像更改。
推荐阅读
- postgresql - 事务查看开始后对数据库行所做的更改
- c# - 如何修复我的鼠标不在 X 轴上旋转相机?
- asp.net-core - ASP.Net Core 排除英语以外的已发布语言目录
- xamarin.forms - 顶部定位的 Xamarin 形成带有标题的列表视图 - 问题:顶部位置在某些 iPhone 型号上有所不同
- docker - 无法在 docker 中启用实验性功能
- java - 在 Java 中读取 MIDI 消息:缺少音符关闭事件?
- python - python中集合的“奇怪”排序
- java - NullPointerException 使用带有 JUnit 5 到 Selenium 的 @Before 注释
- c++ - 为什么在 std::vector::push_back(T object) 方法中构造对象时调用析构函数?
- python - 如何在 Python 中通过 csvReader 使用高阶函数