前言
项目中需要读出网口通信的工业相机的图像数据,此文主要是记个笔记。
参考链接
1、在Windows上使用MATLAB Image Acquisition Toolbox
2、调用相机程序
3、matlab使用usb和gige 网口相机
4、Matlab摄像头基本操作
采用的MATLAB的Image Acquisition Tool
1、采用MATLAB APP中的Image Acquisition工具
2、开启后的界面如下
在左侧检测到的相机下选择像素格式mono,中间就会显示图像框,单击Start Preview以在当前图像设置中的屏幕上预览图像。
注意!!!从MATLAB2014a开始,需要安装gige vision toolbox,才能检测到相机,之前的版本不用
下载安装gige vision toolbox:
- 在matlab窗口输入supportPackageInstaller安装gige vision toolbox
- 点击APP,获取更多APP,打开资源管理器下载安装gige vision toolbox
GigE Vision Quick Start Configuration Guide:
C:/ProgramData/MATLAB/SupportPackages/R2018a/toolbox/imaq/supportpackages/gige/GigEVisionQuickStartConfigurationGuide.pdf
3、通过MATLAB代码实时读取显示相机图像
1、
clear
clc
vid = videoinput('gige', 1, 'Mono8');
src = getselectedsource(vid);
vid.FramesPerTrigger = 1;
set(vid,'TriggerRepeat',Inf);
vid.FramesPerTrigger = Inf;
set(vid,'FramesPerTrigger',1);
vid.FrameGrabInterval=1;
% preview(vid); %预览
while (1)
frame=getsnapshot(vid);
figure(1)
imshow(frame);
% title('原始图像');
drawnow;%实时更新图像
end
2、官方的文档里的
v = videoinput('gige', 1, 'Mono8');
s = v.Source;
% Determine optimum streaming parameters as described in the
% "GigE Vision Quick Start Configuration Guide"
s.PacketSize = 9000;
% s.PacketDelay =
% Set exposure time and mode
s.ExposureMode = 'Timed';
s.ExposureTimeAbs = 4000;
% The default videoinput trigger type is 'immediate', which is explicitly
% configured here for clarity.
triggerconfig(v, 'immediate');
% Specify number of frames to acquire
v.FramesPerTrigger = 30;
v.TriggerRepeat = 0;
% Start continuous buffered acquisition and wait for acquisition to complete
start(v);
wait(v, 10);
% Transfer acquired frames from acquisition input buffer into workspace.
data = getdata(v, v.FramesAvailable);
figure;
imaqmontage(data)