Esempio n. 1
0
        // This function acts as the body of the example; please see
        // NodeMapInfo_CSharp example for more in-depth comments on setting up
        // cameras.
        public int RunSingleCamera(IManagedCamera cam)
        {
            int result = 0;

            try
            {
                // Retrieve TL device nodemap and print device information
                INodeMap nodeMapTLDevice = cam.GetTLDeviceNodeMap();

                result = PrintDeviceInfo(nodeMapTLDevice);

                // Initialize camera
                cam.Init();

                // Retrieve GenICam nodemap
                INodeMap nodeMap = cam.GetNodeMap();

                // Acquire images
                result = result | AcquireImages(cam, nodeMap, nodeMapTLDevice);

                // Deinitialize camera
                cam.DeInit();
            }
            catch (SpinnakerException ex)
            {
                writeLog(String.Format("Error: {0}\n", ex.Message));
                result = -1;
            }

            return(result);
        }
Esempio n. 2
0
 private void GetNodeMapsAndInitialize()
 {
     nodeMapTLDevice = managedCamera.GetTLDeviceNodeMap();
     nodeMapTLStream = managedCamera.GetTLStreamNodeMap();
     managedCamera.Init();
     nodeMap = managedCamera.GetNodeMap();
     Console.WriteLine("Camera number {0} opened and initialized on thread {1}", camNumber, Thread.CurrentThread.ManagedThreadId);
 }
Esempio n. 3
0
        private void frameRateManualDisable()
        {
            IEnum iAcquisitionFrameRateAuto = cam.GetNodeMap().GetNode <IEnum>("AcquisitionFrameRateAuto");

            if (iAcquisitionFrameRateAuto == null || !iAcquisitionFrameRateAuto.IsWritable)
            {
                Console.WriteLine("无法设置帧率模式\n");
                return;
            }

            IEnumEntry iAcquisitionFrameRateAutoOff = iAcquisitionFrameRateAuto.GetEntryByName("Continuous");

            if (iAcquisitionFrameRateAutoOff == null || !iAcquisitionFrameRateAutoOff.IsReadable)
            {
                Console.WriteLine("无法设置启用帧率自动模式\n");
                return;
            }
            // Set symbolic from entry node as new value for enumeration node
            iAcquisitionFrameRateAuto.Value = iAcquisitionFrameRateAutoOff.Symbolic;
        }
Esempio n. 4
0
        public override bool Connect()
        {
            bool result = false;

            try
            {
                system = new ManagedSystem();
                IList <IManagedCamera> camList = system.GetCameras();

                if (camList.Count != 1)
                {
                    int count = camList.Count;
                    foreach (IManagedCamera mc in camList)
                    {
                        mc.Dispose();
                    }

                    // Clear camera list before releasing system
                    camList.Clear();

                    // Release system
                    system.Dispose();
                    throw new Exception("Only one camera should be connected, but found " + count);
                }

                camera = camList[0];
                // Initialize camera
                camera.Init();

                SerialNumber    = Convert.ToUInt32(camera.DeviceSerialNumber);
                FirmwareVersion = camera.DeviceFirmwareVersion;

                // Retrieve GenICam nodemap
                nodeMap = camera.GetNodeMap();

                //initialise settings
                DefaultSettings();

                ImageWidth  = camera.Width;
                ImageHeight = camera.Height;

                result = true;
            }
            catch (Exception /*ex*/)
            {
                //App.LogEntry.AddEntry("Failed to Connect to Point Grey Camera : " + ex.Message);
                result = false;
            }

            return(result);
        }
Esempio n. 5
0
        public override bool Init(int index = 0)
        {
            bool ret = false;

            try
            {
                // Retrieve singleton reference to system object
                ManagedSystem system = new ManagedSystem();
                // Retrieve list of cameras from the system
                IList <IManagedCamera> camList = system.GetCameras();

                LogHelper.AppLoger.DebugFormat("Number of cameras detected: {0}", camList.Count);
                if (camList.Count == 0)
                {
                    LogHelper.AppLoger.Error("没有发现相机!");
                    return(ret);
                }

                m_Camera = camList[index];
                // Retrieve TL device nodemap and print device information
                INodeMap nodeMapTLDevice = m_Camera.GetTLDeviceNodeMap();

                // Initialize camera
                m_Camera.Init();
                // Retrieve GenICam nodemap
                m_NodeMap = m_Camera.GetNodeMap();

                //if (!m_camera.DeviceConnectionStatus.IsRegister)
                //{
                //    Dialogs.Show("连接相机失败!");
                //    return ret;
                //}
                //CameraInfo camInfo = m_camera.GetCameraInfo();
                IString iDeviceSerialNumber = nodeMapTLDevice.GetNode <IString>("DeviceSerialNumber");
                LogHelper.AppLoger.DebugFormat("camera serial number:{0}", iDeviceSerialNumber);
                //Set embedded timestamp to on
                //EmbeddedImageInfo embeddedInfo = m_camera.GetEmbeddedImageInfo();
                //embeddedInfo.timestamp.onOff = true;
                //m_camera.SetEmbeddedImageInfo(embeddedInfo);
                SetAcquisitionMode("Continuous");
                ret = true;
            }
            catch (Exception ex)
            {
                LogHelper.AppLoger.Error(ex);
            }
            return(ret);
        }
Esempio n. 6
0
        protected virtual void Configure(IManagedCamera camera)
        {
            var nodeMap   = camera.GetNodeMap();
            var chunkMode = nodeMap.GetNode <IBool>("ChunkModeActive");

            if (chunkMode != null && chunkMode.IsWritable)
            {
                chunkMode.Value = true;
                var chunkSelector = nodeMap.GetNode <IEnum>("ChunkSelector");
                if (chunkSelector != null && chunkSelector.IsReadable)
                {
                    var entries = chunkSelector.Entries;
                    for (int i = 0; i < entries.Length; i++)
                    {
                        var chunkSelectorEntry = entries[i];
                        if (!chunkSelectorEntry.IsAvailable || !chunkSelectorEntry.IsReadable)
                        {
                            continue;
                        }

                        chunkSelector.Value = chunkSelectorEntry.Value;
                        var chunkEnable = nodeMap.GetNode <IBool>("ChunkEnable");
                        if (chunkEnable == null || chunkEnable.Value || !chunkEnable.IsWritable)
                        {
                            continue;
                        }
                        chunkEnable.Value = true;
                    }
                }
            }

            var acquisitionMode = nodeMap.GetNode <IEnum>("AcquisitionMode");

            if (acquisitionMode == null || !acquisitionMode.IsWritable)
            {
                throw new InvalidOperationException("Unable to set acquisition mode to continuous.");
            }

            var continuousAcquisitionMode = acquisitionMode.GetEntryByName("Continuous");

            if (continuousAcquisitionMode == null || !continuousAcquisitionMode.IsReadable)
            {
                throw new InvalidOperationException("Unable to set acquisition mode to continuous.");
            }

            acquisitionMode.Value = continuousAcquisitionMode.Symbolic;
        }
Esempio n. 7
0
        // This function acts as the body of the example; please see
        // NodeMapInfo_CSharp example for more in-depth comments on setting up
        // cameras.
        int RunSingleCamera(IManagedCamera cam)
        {
            int result = 0;
            int err    = 0;

            try {
                // Retrieve TL device nodemap and print device information
                INodeMap nodeMapTLDevice = cam.GetTLDeviceNodeMap();

                result = PrintDeviceInfo(nodeMapTLDevice);

                // Initialize camera
                cam.Init();

                // Retrieve GenICam nodemap
                INodeMap nodeMap = cam.GetNodeMap();

                // Acquire images
                List <IManagedImage> images = new List <IManagedImage>();

                err = result | AcquireImages(cam, nodeMap, ref images);
                if (err < 0)
                {
                    return(err);
                }

                // Create video
                result = result | SaveListToVideo(nodeMap, nodeMapTLDevice, ref images);

                // Deinitialize camera
                cam.DeInit();
            } catch (SpinnakerException ex) {
                Console.WriteLine("Error: {0}", ex.Message);
                result = -1;
            }

            return(result);
        }
Esempio n. 8
0
        public IManagedImage RetrieveMonoImage()
        {
            IManagedImage imgResult = null;

            // Retrieve singleton reference to system object
            ManagedSystem system = new ManagedSystem();

            // Retrieve list of cameras from the system
            IList <IManagedCamera> camList = system.GetCameras();

            if (camList.Count < 1)
            {
                writeLog(String.Format("No camera detected. Aborted.\n\n"));
                return(null);
            }
            else
            {
                writeLog(String.Format("Number of cameras detected: {0}\n\n", camList.Count));
            }
            // Use the first camera
            using (camList[0])
            {
                writeLog(String.Format("Running example for the 1st camera...\n"));

                IManagedCamera cam = camList[0];

                try
                {
                    // Run for a camera

                    // Retrieve TL device nodemap and print device information
                    INodeMap nodeMapTLDevice = cam.GetTLDeviceNodeMap();

                    PrintDeviceInfo(nodeMapTLDevice);

                    // Initialize camera
                    cam.Init();

                    // Retrieve GenICam nodemap
                    INodeMap nodeMap = cam.GetNodeMap();

                    /*****  Acquire single BW image from the camera  *****/

                    writeLog(String.Format("\n*** BW IMAGE ACQUISITION ***\n\n"));
                    SetNodeMapItem(nodeMap, "AcquisitionMode", "Continuous");
                    cam.BeginAcquisition();
                    using (IManagedImage rawImage = cam.GetNextImage())
                    {
                        if (rawImage.IsIncomplete)
                        {
                            writeLog(String.Format(
                                         "Image incomplete with image status {0}...\n", rawImage.ImageStatus));
                            imgResult = null;
                        }
                        else
                        {
                            // TODO: Need to return the acquired rawImage here.
                            //IManagedImage monoImage = rawImage.Convert(
                            //    PixelFormatEnums.Mono16, ColorProcessingAlgorithm.EDGE_SENSING);
                            IManagedImage monoImage = rawImage.Convert(PixelFormatEnums.Mono8);
                            imgResult = monoImage;
                        }
                    }
                    cam.EndAcquisition();

                    /*****  Acquiring Complete  *****/

                    // Deinitialize camera
                    cam.DeInit();
                }
                catch (SpinnakerException ex)
                {
                    writeLog(String.Format("Error: {0}\n", ex.Message));
                    imgResult = null;
                }
                writeLog(String.Format("Camera example complete...\n"));
            }

            // Clear camera list before releasing system
            camList.Clear();

            // Release system
            system.Dispose();

            writeLog(String.Format("Done!\n"));

            return(imgResult);
        }
Esempio n. 9
0
        public override bool Connect()
        {
            bool result = false;

            //try
            //{
            //    CameraSelectionDialog m_selDlg = new CameraSelectionDialog();
            //    if (m_selDlg.ShowModal())
            //    {
            //        ManagedPGRGuid[] guids = m_selDlg.GetSelectedCameraGuids();
            //        if (guids.Length == 0)
            //        {
            //            //MessageBox.Show("Please select a camera", "No camera selected");
            //            return false;
            //        }

            //        camera = new ManagedCamera();
            //        m_ctldlg = new CameraControlDialog();
            //        camera.Connect(guids[0]);

            //        //initialise settings
            //        InitializeSettings();
            //        InitializeSettingsWB();

            //        CameraInfo ci = camera.GetCameraInfo();
            //        SerialNumber = ci.serialNumber;

            //        result = true;
            //    }
            //}
            //catch (Exception /*ex*/)
            //{
            //    //App.LogEntry.AddEntry("Failed to Connect to Point Grey Camera : " + ex.Message);
            //    result = false;
            //}
            system = new ManagedSystem();
            IList <IManagedCamera> camList = system.GetCameras();

            if (camList.Count != 1)
            {
                int count = camList.Count;
                foreach (IManagedCamera mc in camList)
                {
                    mc.Dispose();
                }

                // Clear camera list before releasing system
                camList.Clear();

                // Release system
                system.Dispose();
                throw new Exception("Only one camera should be connected, but found " + count);
            }

            camera = camList[0];
            // Initialize camera
            camera.Init();

            // Retrieve GenICam nodemap
            nodeMap = camera.GetNodeMap();

            SerialNumber = Convert.ToUInt32(camera.DeviceSerialNumber);

            //initialise settings
            try
            {
                InitializeSettings();
                InitializeSettingsWB();
                result = true;
            }
            catch (SpinnakerException ex)
            {
                result = false;
                Debug.WriteLine("PtGrey connect failed: " + ex.Message);
            }

            return(result);
        }
Esempio n. 10
0
        public bool Open(ConcurrentQueue <PtGreyCameraImage> imageQ, out string message)
        {
            bool result = false;

            message = "";

            system = new ManagedSystem();

            // Retrieve list of cameras from the system
            camList = system.GetCameras();

            // Finish if there are no cameras
            if (camList.Count != 1)
            {
                foreach (IManagedCamera mc in camList)
                {
                    mc.Dispose();
                }

                // Clear camera list before releasing system
                camList.Clear();

                // Release system
                system.Dispose();
                message = "Camera count is " + camList.Count;
            }
            else
            {
                try
                {
                    managedCamera = camList[0];

                    if (managedCamera.TLDevice.DeviceDisplayName != null && managedCamera.TLDevice.DeviceDisplayName.IsReadable)
                    {
                        message = managedCamera.TLDevice.DeviceDisplayName.ToString();
                    }

                    // Initialize camera
                    managedCamera.Init();

                    // Retrieve GenICam nodemap
                    nodeMap = managedCamera.GetNodeMap();

                    imageQueue = imageQ;
                    result     = true;
                }
                catch (SpinnakerException ex)
                {
                    Debug.WriteLine("Error: {0}", ex.Message);
                    message = ex.Message;
                    result  = false;;
                }
                catch (Exception ex)
                {
                    message = ex.Message;
                    result  = false;
                }
            }

            return(result);
        }
Esempio n. 11
0
        public bool Open(ConcurrentQueue <PtGreyCameraImage> imageQ, out string message, out long width, out long height)
        {
            bool result = false;

            message = "";
            width   = height = 0;

            system = new ManagedSystem();

            // Retrieve list of cameras from the system
            camList = system.GetCameras();

            // Finish if there are no cameras
            if (camList.Count != 1)
            {
                foreach (IManagedCamera mc in camList)
                {
                    mc.Dispose();
                }

                // Clear camera list before releasing system
                camList.Clear();

                // Release system
                system.Dispose();
                message = "Camera count is " + camList.Count;
            }
            else
            {
                try
                {
                    #region FlyCaptureAPI
                    FlyCapture2Managed.ManagedBusManager busMgr = new FlyCapture2Managed.ManagedBusManager();
                    var guid = busMgr.GetCameraFromIndex(0);
                    flycapManagedCamera = new FlyCapture2Managed.ManagedCamera();
                    flycapManagedCamera.Connect(guid);
                    #endregion

                    managedCamera = camList[0];

                    if (managedCamera.TLDevice.DeviceDisplayName != null && managedCamera.TLDevice.DeviceDisplayName.IsReadable)
                    {
                        message = managedCamera.TLDevice.DeviceDisplayName.ToString();
                    }

                    // Initialize camera
                    managedCamera.Init();

                    width  = managedCamera.Width.Value;
                    height = managedCamera.Height.Value;

                    // Retrieve GenICam nodemap
                    nodeMap = managedCamera.GetNodeMap();

                    imageQueue = imageQ;
                    result     = true;
                }
                catch (SpinnakerException ex)
                {
                    Debug.WriteLine("Error: {0}", ex.Message);
                    message = ex.Message;
                    result  = false;;
                }
                catch (Exception ex)
                {
                    message = ex.Message;
                    result  = false;
                }
            }

            return(result);
        }
Esempio n. 12
0
 public PtGreyCamera(IManagedCamera cam, CameraType camType)
 {
     camera     = cam;
     cameraType = camType;
     nodeMap    = camera.GetNodeMap();
 }
        /// <summary>Throws Spinnaker Exception</summary>
        /// <returns>The property node.</returns>
        protected bool GetNode(ref NodeType newNode)
        {
            try {
                if (camera == null)
                {
                    throw new SpinnakerException("Camera is null.");
                }

                INodeMap map = camera.GetNodeMap();
                if (map == null)
                {
                    throw new SpinnakerException("Could not retrieve node map.");
                }

                newNode = map.GetNode <NodeType>(NodeName);
                if (newNode == null)
                {
                    return(false);
                }
                return(true);
            } catch (SpinnakerException ex) {
                Console.Error.WriteLine("Unable to retrieve node: " + ex.Message);
                return(false);
            }
        }