Allied Vision相机

    简介

          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<Bitmap> 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<Camera> 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);

    /// <summary>
    /// A helper class as a wrapper around Vimba
    /// </summary>
    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;
        /// <summary>
        /// Initializes a new instance of the VimbaHelper class
        /// </summary>
        public VimbaHelper()
        {
        }

        /// <summary>
        /// Finalizes an instance of the VimbaHelper class and shuts down Vimba
        /// </summary>
        ~VimbaHelper()
        {
            // Release Vimba API if user forgot to call Shutdown
            ReleaseVimba();
        }

        /// <summary>
        /// Frame Infos Enumeration
        /// </summary>
        public enum FrameInfos
        {
            /// <summary>
            /// Do not Show frame information
            /// </summary>
            Off = 0,

            /// <summary>
            /// Show Frame information
            /// </summary>
            Show,

            /// <summary>
            /// Show frame information, if a frame is lost or a frame is not complete
            /// </summary>
            Automatic
        }

        /// <summary>
        /// Gets the current camera list
        /// </summary>
        public List<Camera> CameraList
        {
            get
            {
                // Check if API has been started up at all
                if (null == m_Vimba)
                {
                    throw new Exception("Vimba is not started.");
                }

                List<Camera> cameraList = new List<Camera>();
                CameraCollection cameras = m_Vimba.Cameras;
                foreach (Camera camera in cameras)
                {
                    cameraList.Add(camera);
                }

                return cameraList;
            }
        }

        /// <summary>
        /// Starts up Vimba API and loads all transport layers
        /// </summary>
        public void Startup()
        {
            // Instantiate main Vimba object
            Vimba vimba = new Vimba();

            // Start up Vimba API
            vimba.Startup();
            m_Vimba = vimba;
        }

        /// <summary>
        /// Shuts down Vimba API
        /// </summary>
        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();
        }

        /// <summary>
        /// Returns the version of Vimba API
        /// </summary>
        /// <returns></returns>
        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);
        }

        /// <summary>
        /// Starts the continuous image acquisition and opens the camera
        /// Registers the event handler for the new frame event
        /// </summary>
        /// <param name="id">The camera ID</param>
        /// <param name="showCameraInfo">Flag to indicate if the Camera info data shall be shown or not</param>
        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();
                }
            }
        }

        /// <summary>
        /// Stops the image acquisition
        /// </summary>
        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();
        }

        /// <summary>
        /// Display the image as dots or show the FrameInfo
        /// </summary>
        /// <param name="frame">The received frame</param>
        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 <= 0)
                {
                    Console.WriteLine(frameRate.ToString("0.0"));
                }
                else
                {
                    Console.WriteLine("?");
                }
            }
            else
            {
                Console.Write(".");
            }
        }

        /// <summary>
        /// Checks if a frame is missing
        /// </summary>
        /// <param name="frame">The received frame</param>
        /// <returns>True if a frame is missing</returns>
        private ulong GetFramesMissing(Frame frame)
        {
            ulong missingFrames;
            // For USB the very first frame ID is 0
            if (frame.FrameID == 0 && m_FrameID == 0) 
            {
                missingFrames = 0;
            }
            else if (frame.FrameID - m_FrameID == 1)
            {
                missingFrames = 0;
            }
            else
            {
                missingFrames = frame.FrameID - m_FrameID;
            }

            m_FrameID = frame.FrameID;

            return missingFrames;
        }

        /// <summary>
        /// Calculates the Frame rate
        /// </summary>
        /// <returns>The frame rate</returns>
        private double CalcFPS()
        {
            int sytemTimeLocal = System.Environment.TickCount;

            double fps = 1000 / (double)(sytemTimeLocal - systemTime);

            systemTime = sytemTimeLocal;

            return fps;
        }

        /// <summary>
        /// Gets the frame Status as a string
        /// </summary>
        /// <param name="frame">The received frame</param>
        /// <returns>Frame Status string</returns>
        private string GetFrameStatus(Frame frame)
        {
            string status = string.Empty;

            switch (frame.ReceiveStatus)
            {
                case VmbFrameStatusType.VmbFrameStatusComplete:
                    status = "Complete";
                    break;

                case VmbFrameStatusType.VmbFrameStatusIncomplete:
                    status = "Incomplete";
                    break;

                case VmbFrameStatusType.VmbFrameStatusTooSmall:
                    status = "Too small";
                    break;

                case VmbFrameStatusType.VmbFrameStatusInvalid:
                    status = "Invalid";
                    break;

                default:
                    status = "?";
                    break;
            }

            return status;
        }

        /// <summary>
        /// Handles the frame received event
        /// The frame is displayed and eventually queued
        /// </summary>
        /// <param name="frame">The received frame</param>
        private void OnFrameReceived(Frame frame)
        {
            try
            {
                // Convert frame into displayable image
                OutPutFrameInfo(frame);
            }
            finally
            {
                // We make sure to always return the frame to the API
                try
                {
                    m_Camera.QueueFrame(frame);
                }
                catch
                {
                    // Do nothing
                }
            }
        }

        /// <summary>
        ///  Unregisters the new frame event
        ///  Stops the capture engine
        ///  Closes the camera
        /// </summary>
        private void ReleaseCamera()
        {
            if (null != m_Camera)
            {
                // We can use cascaded try-finally blocks to release the
                // camera step by step to make sure that every step is executed.
                try
                {
                    try
                    {
                        try
                        {
                            m_Camera.OnFrameReceived -= this.OnFrameReceived;
                            if (true == m_Acquiring)
                            {
                                m_Camera.StopContinuousImageAcquisition();
                            }
                        }
                        catch(Exception ex)
                        {
                            string err = ex.Message;
                        }
                    }
                    finally
                    {
                        m_Acquiring = false;
                        m_Camera.Close();
                    }
                }
                finally
                {
                    m_Camera = null;
                }
            }
        }

        /// <summary>
        ///  Releases the camera
        ///  Shuts down Vimba
        /// </summary>
        private void ReleaseVimba()
        {
            if (null != m_Vimba)
            {
                // We can use cascaded try-finally blocks to release the
                // Vimba API step by step to make sure that every step is executed.
                try
                {
                    try
                    {
                        // First we release the camera (if there is one)
                        ReleaseCamera();
                        // Now finally shutdown the API
                        m_Vimba.Shutdown();
                    }
                    catch(Exception ex)
                    {
                        string err = ex.Message;
                    }

                }
                finally
                {
                    m_Vimba = null;
                }
            }
        }
    }
}

 

### 回答1: Allied Standard Avionics Architecture Council(ASAAC)是一个专门负责开发和管理航空电子标准的组织。这个组织致力于确保航空电子系统的互操作性、可靠性、安全性和性能,并与航空电子相关的其他组织和标准之间建立合作关系,以实现广泛的标准化和协作。 ASAAC标准体系架构的主要目标是组织并简化现有的航空电子标准,以提高整个行业的效率和一致性。该架构分为七个主题模块,涵盖了包括航空电子硬件、软件和数据在内的各种方面。这些模块为航空电子系统提供了一个通用的框架,并指导开发人员设计和构建航空电子系统。 ASAAC标准体系架构的优点在于它提供了一种统一的航空电子管理方式,并为整个行业提供了一些共同的规范,这为航空电子设备的互换性和可重用性奠定了基础。此外,它还鼓励了各种设备的开放性,并为航空电子系统的未来发展提供了基础。因而ASAAC标准体系架构的实施为航空电子系统的规范化、高效性和可靠性奠定了良好的基础。 ### 回答2: Allied Standard Avionics Architecture Council(ASAAC)是一个由顶级飞机制造商组成的国际组织,旨在制定统一标准的飞机航空电子架构。ASAAC标准体系架构是该组织制定的标准体系架构,旨在确保飞机航空电子的兼容性、互操作性和相互连接的可靠性。它为飞机的舱内外所有系统提供一个规范的基础架构,包括通信、导航、飞行管理和性能监控等方面的系统。ASAAC标准体系架构的另一个优点是,它可以减少所需的开发时间和成本,以及提高航空电子系统可靠性和可重用性。此外,该标准体系架构还可提高飞机操作的安全性和准确性,因为它确保了各种飞机电子产品之间的一致性和整体性。 总之,ASAAC标准体系架构是一个创新性的航空电子系统规范体系,它大大提高了飞机工业的标准化程度,使飞机制造商和航空公司能够更有效地协作和合作,加快了飞机航空电子系统的开发和部署。因此,它是现代飞机航空电子架构的标准之一,值得我们关注和学习。 ### 回答3: ASAAC是联合标准航空电子架构委员会的缩写,是由航空业内的一些组织所组成的,旨在制定和推广航空电子领域的标准体系架构。 ASAAC标准体系架构的目的是为了在航空电子领域提供一种标准的体系结构,以帮助不同部门之间在设计、实现和维护时遵循共同的规范。它包括了几个具体的标准,比如硬件接口标准、软件架构标准、通信协议标准等。 这些标准是由ASAAC成员组织中的专业人士制定的,他们在航空电子领域拥有丰富的经验和专业知识,并始终关注行业中出现的新技术和创新。他们的工作旨在为航空电子系统提供工程结构,以满足系统可靠性、可维护性和安全性等要求的需求。 ASAAC标准体系架构对于航空电子行业的公司和专业人士来说非常有价值。它提供了一些技术指南和最佳实践,以帮助设计和实现更高质量的航空电子系统。此外,它还促进行业内的协作和互动,以加快新技术的采纳和发展,从而推动整个行业的进步。
评论 15
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值