C#利用NI VAS采集图片

软件环境

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

  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;
	}
}
posted @ 2020-01-18 09:03  那人_那事  阅读(558)  评论(0编辑  收藏  举报