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;
	}
}
相關文章
相關標籤/搜索