C#利用NI VAS采集图片

软件环境

Vision Acquisition Software:该软件为NI视觉采集集成环境web

  1. 新建C#工程
  2. 添加引用(位于’C:\Program Files (x86)\National Instruments\MeasurementStudioVS2008\DotNET\Assemblies\Current’文件夹下)
  • NationalInstruments.Common
  • NationalInstruments.Vision.Common
  • NationalInstruments.Vision.Aquisition.Imaqdx
  1. 得到在线的全部相机
ImaqdxCameraInformation[] cameraList = ImaqdxSystem.GetCamerInformation(true);
  1. 打开全部相机
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;
	}
}
  1. 关闭全部相机
public void CloseCameraDevice()
{
	foreach(ImaqdxSession session in cameraSessionList)
	{
		if(session != null)
			session.Close();
	}
}
  1. 拍照及显示
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;
	}
}
相关文章
相关标签/搜索