예제 #1
0
파일: PtGreyCamera.cs 프로젝트: wpiyong/n3
        bool RestoreDefaultSettings()
        {
            bool result = false;

            try
            {
                for (int i = 0; i < 3; i++)
                {
                    try
                    {
                        managedCamera.UserSetSelector.Value = UserSetSelectorEnums.Default.ToString();
                        managedCamera.UserSetLoad.Execute();
                        result = true;
                        break;
                    }
                    catch (SpinnakerException s)
                    {
                        managedCamera.AcquisitionMode.Value = AcquisitionModeEnums.Continuous.ToString();
                        managedCamera.BeginAcquisition();
                        System.Threading.Thread.Sleep(500);
                        managedCamera.EndAcquisition();
                    }
                }

                //TODO: stream buffer default count mode to manual
                // Set stream buffer Count Mode to manual
                // Retrieve Stream Parameters device nodemap
                INodeMap sNodeMap = managedCamera.GetTLStreamNodeMap();
                IEnum    streamBufferCountMode = sNodeMap.GetNode <IEnum>("StreamBufferCountMode");
                if (streamBufferCountMode == null || !streamBufferCountMode.IsWritable)
                {
                    return(false);
                }

                IEnumEntry streamBufferCountModeManual = streamBufferCountMode.GetEntryByName("Manual");
                if (streamBufferCountModeManual == null || !streamBufferCountModeManual.IsReadable)
                {
                    return(false);
                }

                streamBufferCountMode.Value = streamBufferCountModeManual.Value;
            }
            catch (Exception ex)
            {
                result = false;
            }

            return(result);
        }
예제 #2
0
        public bool SetStreamBufferCount(long count)
        {
            try
            {
                // set to manual
                INodeMap sNodeMap             = managedCamera.GetTLStreamNodeMap();
                IEnum    sBufferCountSelector = sNodeMap.GetNode <IEnum>("StreamBufferCountMode");
                if (sBufferCountSelector == null || !sBufferCountSelector.IsWritable)
                {
                    return(false);
                }
                IEnumEntry iBufferCountManual = sBufferCountSelector.GetEntryByName("Manual");
                if (iBufferCountManual == null || !iBufferCountManual.IsReadable)
                {
                    return(false);
                }
                sBufferCountSelector.Value = iBufferCountManual.Symbolic;

                // set the value
                IInteger streamNode = sNodeMap.GetNode <IInteger>("StreamDefaultBufferCount");
                if (streamNode == null || !streamNode.IsWritable)
                {
                    return(false);
                }

                streamNode.Value = count;
            }
            catch
            {
                return(false);
            }

            return(true);
        }
예제 #3
0
        public override bool SetStreamBufferCount(int bufCount)
        {
            bool ret = false;

            try
            {
                INodeMap sNodeMap   = m_Camera.GetTLStreamNodeMap();
                IInteger streamNode = sNodeMap.GetNode <IInteger>("StreamDefaultBufferCount");
                streamNode.Value = bufCount;
                ret = true;
            }
            catch (Exception ex)
            {
                LogHelper.AppLoger.Error(ex);
            }
            return(ret);
        }
예제 #4
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);
 }
예제 #5
0
        //void SetCameraVideoModeAndFrameRate(VideoMode newVideoMode, FrameRate newFrameRate)
        //{
        //    bool restartCapture = true;
        //    try
        //    {
        //        camera.StopCapture();
        //    }
        //    catch (FC2Exception ex)
        //    {
        //        if (ex.Type != ErrorType.IsochNotStarted)
        //        {
        //            throw;
        //        }
        //        else
        //            restartCapture = false;
        //    }

        //    try
        //    {
        //        camera.SetVideoModeAndFrameRate(newVideoMode, newFrameRate);
        //    }
        //    catch (FC2Exception /*ex*/)
        //    {
        //        throw;
        //    }

        //    if (restartCapture)
        //    {
        //        camera.StartCapture();
        //    }
        //}


        //void SetAbsolutePropertyValue(PropertyType property, float newValue)
        //{
        //    CameraProperty camProp = camera.GetProperty(property);
        //    CameraPropertyInfo propInfo = camera.GetPropertyInfo(property);

        //    if (!camProp.autoManualMode && propInfo.manualSupported && propInfo.absValSupported)
        //    {
        //        float difference = camProp.absValue - newValue;
        //        if (difference != 0)
        //        {
        //            // The brightness abs register sometimes starts drifting
        //            // due to a rounding error between the camera and the
        //            // actual value being held by the adjustment. To prevent
        //            // this, only apply the change to the camera if the
        //            // difference is greater than a specified amount.

        //            // Check if the difference is greater than 0.005f.
        //            if (property != PropertyType.Brightness ||
        //                Math.Abs(difference) > 0.005f)
        //            {
        //                camProp.absControl = true;
        //                camProp.absValue = newValue;
        //                camera.SetProperty(camProp);
        //            }
        //        }
        //    }
        //    else
        //    {
        //        throw new ApplicationException("Trying to set a property that cannot be adjusted");
        //    }
        //}
        public void SetAbsolutePropertyValue(string property, string newValue)
        {
            try
            {
                if (property == "Hue")
                {
                    IFloat hue = nodeMap.GetNode <IFloat>("Hue");
                    hue.Value = Convert.ToDouble(newValue);
                }
                else if (property == "Gamma")
                {
                    IFloat gamma = nodeMap.GetNode <IFloat>("Gamma");
                    gamma.Value = Convert.ToDouble(newValue);
                }
                else if (property == "Width")
                {
                    IInteger width = nodeMap.GetNode <IInteger>("Width");
                    width.Value = Convert.ToInt32(newValue);
                }
                else if (property == "Height")
                {
                    IInteger height = nodeMap.GetNode <IInteger>("Height");
                    height.Value = Convert.ToInt32(newValue);
                }
                else if (property == "Gain")
                {
                    IEnum gainAuto = nodeMap.GetNode <IEnum>("GainAuto");
                    gainAuto.Value = "Off";

                    IFloat gainValue = nodeMap.GetNode <IFloat>("Gain");
                    gainValue.Value = Convert.ToDouble(newValue);
                }
                else if (property == "Saturation")
                {
                    IEnum saturationAuto = nodeMap.GetNode <IEnum>("SaturationAuto");
                    saturationAuto.Value = "Off";

                    IFloat saturationValue = nodeMap.GetNode <IFloat>("Saturation");
                    saturationValue.Value = Convert.ToDouble(newValue);
                }
                else if (property == "Binning")
                {
                    IInteger binningValue = nodeMap.GetNode <IInteger>("BinningVertical");
                    binningValue.Value = Convert.ToInt32(newValue);
                }
                else if (property == "FrameRate")
                {
                    IEnum frameRateAuto = nodeMap.GetNode <IEnum>("AcquisitionFrameRateAuto");
                    frameRateAuto.Value = "Off";

                    IFloat frameRateValue = nodeMap.GetNode <IFloat>("AcquisitionFrameRate");
                    frameRateValue.Value = Convert.ToDouble(newValue);
                }
                else if (property == "PixelFormat")
                {
                    IEnum      pixelFormat     = nodeMap.GetNode <IEnum>("PixelFormat");
                    IEnumEntry pixelFormatItem = pixelFormat.GetEntryByName(newValue);

                    if (pixelFormatItem?.IsReadable == true)
                    {
                        pixelFormat.Value = pixelFormatItem.Symbolic;
                    }
                }
                else if (property == "VideoMode")
                {
                    IEnum acquisitionMode = nodeMap.GetNode <IEnum>("AcquisitionMode");
                    if (acquisitionMode?.IsWritable == true)
                    {
                        IEnumEntry acquisitionModeItem = acquisitionMode.GetEntryByName(newValue);
                        if (acquisitionModeItem?.IsReadable == true)
                        {
                            acquisitionMode.Value = acquisitionModeItem.Symbolic;
                        }
                        else
                        {
                            Debug.WriteLine("Error: SetAbsolutePropertyValue for " + property);
                        }
                    }
                    else
                    {
                        Debug.WriteLine("Error: SetAbsolutePropertyValue for " + property);
                    }
                }
                else if (property == "ShutterMode")
                {
                    IEnum exposureMode = nodeMap.GetNode <IEnum>("ExposureMode");
                    if (exposureMode?.IsWritable == true)
                    {
                        IEnumEntry exposureModeItem = exposureMode.GetEntryByName(newValue);
                        if (exposureModeItem?.IsReadable == true)
                        {
                            exposureMode.Value = exposureModeItem.Symbolic;
                        }
                        else
                        {
                            Debug.WriteLine("Error: SetAbsolutePropertyValue for " + property);
                        }
                    }
                    else
                    {
                        Debug.WriteLine("Error: SetAbsolutePropertyValue for " + property);
                    }
                }
                else if (property == "StreamBufferMode")
                {
                    INodeMap nodeMapStream = camera.GetTLStreamNodeMap();
                    IEnum    bufferMode    = nodeMapStream.GetNode <IEnum>("StreamBufferHandlingMode");
                    if (bufferMode?.IsWritable == true)
                    {
                        IEnumEntry bufferModeItem = bufferMode.GetEntryByName(newValue);
                        if (bufferModeItem?.IsReadable == true)
                        {
                            bufferMode.Value = bufferModeItem.Symbolic;
                        }
                        else
                        {
                            Debug.WriteLine("Error: SetAbsolutePropertyValue for " + property);
                        }
                    }
                    else
                    {
                        Debug.WriteLine("Error: SetAbsolutePropertyValue for " + property);
                    }
                }
                else if (property == "ExposureCompensation")
                {
                    IFloat expoCompensation = nodeMap.GetNode <IFloat>("pgrExposureCompensation");
                    expoCompensation.Value = Convert.ToDouble(newValue);
                }
                else
                {
                    Debug.WriteLine("Error: SetAbsolutePropertyValue for " + property + " not implemented.");
                }
            }
            catch (SpinnakerException e)
            {
                Debug.WriteLine("Error: SetAbsolutePropertyValue for " + property + " exceptoin: " + e.Message);
            }
        }