C#利用NI VAS采集图片
软件环境
Vision Acquisition Software
:该软件为NI视觉采集集成环境
- 新建C#工程
- 添加引用(位于’C:\Program Files (x86)\National Instruments\MeasurementStudioVS2008\DotNET\Assemblies\Current’文件夹下)
NationalInstruments.Common
NationalInstruments.Vision.Common
NationalInstruments.Vision.Aquisition.Imaqdx
- 获得在线的所有相机
ImaqdxCameraInformation[] cameraList = ImaqdxSystem.GetCamerInformation(true);
- 打开所有相机
public bool OpenCameraDevice()
{
try
{
List<ImaqdxSession> cameraSessionList = new List<ImaqdxSession>();
foreach(var camera in cameraList)
{
cameraSessionList.Add(new ImaqdxSession(camera.Name));
return true;
}
}
catch()
{
return false;
}
}
- 关闭所有相机
public void CloseCameraDevice()
{
foreach(ImaqdxSession session in cameraSessionList)
{
if(session != null)
session.Close();
}
}
- 拍照及显示
public bool SnapPictureAndShow(int cameraIndex)
{
VisionImage image = new VisionImage();
try
{
cameraSessionList[cameraIndex].Snap(image);
Algorithms.Copy(image, NI_ImageViewer.Image);
return true;
}
catch()
{
return false;
}
}