Allied Vision相机 您所在的位置:网站首页 工业相机使用说明书图片 Allied Vision相机

Allied Vision相机

2024-07-14 04:58| 来源: 网络整理| 查看: 265

    简介

          Allied Vision相机图像采集处理。Vimba是Allied Vision推出的极具前瞻性的独立软件开发工具包(SDK),适于所有配备GigE Vision、USB3 Vision、IEEE 1394和Camera Link接口的Allied Vision相机。通过Vimba,您可以轻松控制Allied Vision相机、即刻获取图像,并为复杂的视觉应用独立编程或连接第三方资源库。安装包链接:https://download.csdn.net/download/c_gyl/10854105。安装软件后,在工程中添加引用VimbaNET.dll。代码下载:https://download.csdn.net/download/c_gyl/10854122

 

使用

可根据需要,自行裁剪。

1.变量 public event Action ImageGrabbed; private Bitmap SingleBitmap; private bool IsSingleGrab; public bool IsLive; public bool IsConnect; private VimbaHelper m_VimbaHelper; private VimbaHelper.FrameInfos ShowFrameInfos = VimbaHelper.FrameInfos.Off; //Show frame info's private string CameraID = null; //The camera ID 2.打开

启动后,查找已连接的相机

public bool Open() { bool result = true; try { m_VimbaHelper = new VimbaHelper(); m_VimbaHelper.Startup(); // Startup API if (null == CameraID) { // Open first available camera // Fetch all cameras known to Vimba List cameras = m_VimbaHelper.CameraList; if (cameras.Count < 0) { result = false; } foreach (Camera currentCamera in cameras) { // Check if we can open the camera in full mode VmbAccessModeType accessMode = currentCamera.PermittedAccess; if (VmbAccessModeType.VmbAccessModeFull == (VmbAccessModeType.VmbAccessModeFull & accessMode)) { // Now get the camera ID CameraID = currentCamera.Id; break; } } result = (null == CameraID ? false:true); } } catch (Exception ex) { string err = ex.Message; result = false; } finally { IsConnect = result; } return result; } 2.连续采集

   启动采集后,绑定采集事件

public void ContinousGrab() { try { if (!IsConnect) { return; } m_VimbaHelper.StartContinuousImageAcquisition(CameraID, ShowFrameInfos); m_VimbaHelper.m_Camera.OnFrameReceived += this.GetImage; this.IsLive = true; } catch (Exception ex) { string err = ex.Message; } } 3. 获取图像

   绑定ImageGrabbed,即可取出图像或通过frame.Fill取出图像后自行处理。

private void GetImage(Frame frame) { try { if (!IsConnect || !IsLive) { return; } Bitmap bitMap = null; frame.Fill(ref bitMap); if (ImageGrabbed != null) { ImageGrabbed(bitMap); } if (IsSingleGrab) { this.SingleBitmap = new Bitmap(bitMap); IsSingleGrab = false; } } catch (Exception ex) { string err = ex.Message; } } 4.取出单个图像

在不停止采集的情况下,取出单个图像。超时部分可根据实际更改。

public bool SingleGrab(out Bitmap bitmap) { bitmap = null; try { if (!IsConnect) { return false; } IsSingleGrab = true; int count = 0; while (IsSingleGrab) { count++; Thread.Sleep(10); if (count > 100) { return false; } } bitmap = new Bitmap(SingleBitmap); } catch (Exception ex) { string err = ex.Message; return false; } return bitmap != null ? true : false; } 5 停止采集

当停止采集图像时使用。

public void StopGrab() { try { if (!IsConnect) { return; } m_VimbaHelper.m_Camera.OnFrameReceived -= this.GetImage; m_VimbaHelper.StopContinuousImageAcquisition(); this.IsLive = false; } catch (Exception ex) { string err = ex.Message; } } 4. 关闭

软件或者资源释放时使用。

public void Close() { try { if (!IsConnect) { return; } CameraID = null; IsConnect = false; IsLive = false; } catch (Exception ex) { string err = ex.Message; } finally { try { if (m_VimbaHelper != null) { m_VimbaHelper.Shutdown(); m_VimbaHelper = null; } } catch (Exception ex) { string err = ex.Message; } } }   采集类

AsynchronousGrabConsole类

/*============================================================================= Copyright (C) 2012 - 2016 Allied Vision Technologies. All Rights Reserved. Redistribution of this file, in original or modified form, without prior written consent of Allied Vision Technologies is prohibited. ------------------------------------------------------------------------------- File: VimbaHelper.cs Description: Implementation file for the VimbaHelper class that demonstrates how to implement an asynchronous, continuous image acquisition with VimbaNET. ------------------------------------------------------------------------------- THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. =============================================================================*/ namespace AsynchronousGrabConsole { using System; using System.Collections.Generic; using AVT.VmbAPINET; public delegate void FrameReceivedHandler(Frame frame); /// /// A helper class as a wrapper around Vimba /// public class VimbaHelper { private Vimba m_Vimba = null; // Main Vimba API entry object public Camera m_Camera = null; // Camera object if camera is open private bool m_Acquiring = false; // Flag to remember if acquisition is running private FrameInfos m_ShowFrameInfo = FrameInfos.Off; // Indicates if frame info is shown in the console private int systemTime = System.Environment.TickCount; // Hold the system time to calculate the frame rate private ulong m_FrameID = 0; public event FrameReceivedHandler m_FrameReceivedHandler = null; /// /// Initializes a new instance of the VimbaHelper class /// public VimbaHelper() { } /// /// Finalizes an instance of the VimbaHelper class and shuts down Vimba /// ~VimbaHelper() { // Release Vimba API if user forgot to call Shutdown ReleaseVimba(); } /// /// Frame Infos Enumeration /// public enum FrameInfos { /// /// Do not Show frame information /// Off = 0, /// /// Show Frame information /// Show, /// /// Show frame information, if a frame is lost or a frame is not complete /// Automatic } /// /// Gets the current camera list /// public List CameraList { get { // Check if API has been started up at all if (null == m_Vimba) { throw new Exception("Vimba is not started."); } List cameraList = new List(); CameraCollection cameras = m_Vimba.Cameras; foreach (Camera camera in cameras) { cameraList.Add(camera); } return cameraList; } } /// /// Starts up Vimba API and loads all transport layers /// public void Startup() { // Instantiate main Vimba object Vimba vimba = new Vimba(); // Start up Vimba API vimba.Startup(); m_Vimba = vimba; } /// /// Shuts down Vimba API /// public void Shutdown() { // Check if API has been started up at all if (null == m_Vimba) { throw new Exception("Vimba has not been started."); } ReleaseVimba(); } /// /// Returns the version of Vimba API /// /// public String GetVersion() { if (null == m_Vimba) { throw new Exception("Vimba has not been started."); } VmbVersionInfo_t version_info = m_Vimba.Version; return String.Format("{0:D}.{1:D}.{2:D}", version_info.major, version_info.minor, version_info.patch); } /// /// Starts the continuous image acquisition and opens the camera /// Registers the event handler for the new frame event /// /// The camera ID /// Flag to indicate if the Camera info data shall be shown or not public void StartContinuousImageAcquisition(string id, FrameInfos showCameraInfo) { // Check parameters if (null == id) { throw new ArgumentNullException("id"); } // Check if API has been started up at all if (null == m_Vimba) { throw new Exception("Vimba is not started."); } // Check if a camera is already open if (null != m_Camera) { throw new Exception("A camera is already open."); } // show camera info's in the console Output : m_ShowFrameInfo = showCameraInfo; // Open camera m_Camera = m_Vimba.OpenCameraByID(id, VmbAccessModeType.VmbAccessModeFull); if (null == m_Camera) { throw new NullReferenceException("No camera retrieved."); } // Set the GeV packet size to the highest possible value // (In this example we do not test whether this cam actually is a GigE cam) try { m_Camera.Features["GVSPAdjustPacketSize"].RunCommand(); while (false == m_Camera.Features["GVSPAdjustPacketSize"].IsCommandDone()) { // Do nothing } } catch { // Do nothing } bool error = true; try { // Register frame callback m_Camera.OnFrameReceived += this.OnFrameReceived; // Reset member variables m_Acquiring = true; // Start synchronous image acquisition (grab) m_Camera.StartContinuousImageAcquisition(3); error = false; } finally { // Close camera already if there was an error if (true == error) { ReleaseCamera(); } } } /// /// Stops the image acquisition /// public void StopContinuousImageAcquisition() { // Check if API has been started up at all if (null == m_Vimba) { throw new Exception("Vimba is not started."); } // Check if no camera is open if (null == m_Camera) { throw new Exception("No camera open."); } // Close camera ReleaseCamera(); } /// /// Display the image as dots or show the FrameInfo /// /// The received frame public void OutPutFrameInfo(Frame frame) { bool showFrameInfo = false; double frameRate = 0; string status = string.Empty; if (null == frame) { throw new ArgumentNullException("frame"); } frameRate = CalcFPS(); // Get frame rate status = GetFrameStatus(frame); // Get frame status ulong nFramesMissing = GetFramesMissing(frame); if (0 < nFramesMissing) { if (1 == nFramesMissing) { Console.WriteLine("1 missing frame detected\n"); } else { Console.WriteLine("{0} missing frames detected\n", nFramesMissing); } } showFrameInfo = status != "Complete" || 0 < nFramesMissing; // Show frame infos for incomplete frame or if a frame is lost if (m_ShowFrameInfo == FrameInfos.Show || (showFrameInfo && m_ShowFrameInfo == FrameInfos.Automatic)) { if (m_ShowFrameInfo == FrameInfos.Automatic) Console.WriteLine(string.Empty); Console.Write("FrameID:"); Console.Write(frame.FrameID); Console.Write(" Status:"); Console.Write(status); Console.Write(" Size:"); Console.Write(frame.Width); Console.Write("x"); Console.Write(frame.Height); Console.Write(" Format:"); Console.Write(frame.PixelFormat); Console.Write(" FPS:"); if (!double.IsNaN(frameRate) && !double.IsInfinity(frameRate) && nFramesMissing


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有