Ejemplo n.º 1
0
        private void InitializeCurrentVideoModeAndFrameRate()
        {
            if (IsIIDC())
            {
                ManagedCamera camera = (ManagedCamera)m_camera;

                try
                {
                    camera.GetVideoModeAndFrameRate(ref m_currentVideoMode, ref m_currentFrameRate);
                }
                catch (FC2Exception ex)
                {
                    string error = string.Format("Error getting current video mode and frame rate {0}", ex.Message);
                    Console.WriteLine(error);
                    MessageBox.Show(error, "FlyCapture2 Camera Control", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else if (IsGEV())
            {
                m_currentFrameRate = FrameRate.FrameRateFormat7;
                m_currentVideoMode = VideoMode.VideoModeFormat7;
            }
            else
            {
                Debug.WriteLine("The Camera is unknown tpye. Can not get Current Frame Rate.");
                return;
            }
        }
Ejemplo n.º 2
0
        private void OpenCamera()
        {
            try
            {
                System.Diagnostics.Debug.WriteLine("OpenCamera:" + DateTime.Now.ToString("HH:mm:ss.fff"));
                ManagedBusManager busMgr = new ManagedBusManager();
                uint numCameras          = busMgr.GetNumOfCameras();
                if (numCameras == 0)
                {
                    System.Diagnostics.Debug.WriteLine("没有发现相机!");
                    return;
                }
                m_camera = new ManagedCamera();

                //m_processedImage = new ManagedImage();
                m_grabThreadExited = new AutoResetEvent(false);
                ManagedPGRGuid m_guid = busMgr.GetCameraFromIndex(0);

                // Connect to the first selected GUID
                m_camera.Connect(m_guid);

                // Set embedded timestamp to on
                EmbeddedImageInfo embeddedInfo = m_camera.GetEmbeddedImageInfo();
                embeddedInfo.timestamp.onOff = true;
                m_camera.SetEmbeddedImageInfo(embeddedInfo);

                m_camera.StartCapture();
                System.Diagnostics.Debug.WriteLine("OpenCamera:" + DateTime.Now.ToString("HH:mm:ss.fff"));
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }
        }
        // calibrator constructor#2
        public Flea3Calibrator(int horiz_corner_count, int vert_corner_count,
                               float rect_width, float rect_height, int frame_count, PictureBox displaybox)
        {
            DisplayBox = displaybox;
            // 1. creating the camera object
            Cam = new ManagedCamera();
            // 2. creating the bus manager in order to handle (potentially)
            // multiple cameras
            BusMgr = new ManagedBusManager();

            // 3. retrieving the List of all camera ids connected to the bus
            CamIDs = new List <ManagedPGRGuid>();
            int camCount = (int)BusMgr.GetNumOfCameras();

            for (int i = 0; i < camCount; i++)
            {
                ManagedPGRGuid guid = BusMgr.GetCameraFromIndex((uint)i);
                CamIDs.Add(guid);
            }


            FrameCount      = frame_count;
            ChessHorizCount = horiz_corner_count;
            ChessVertCount  = vert_corner_count;

            RectWidth  = rect_width;
            RectHeight = rect_height;

            // creatring the imageViewer to display the calibration frame sequence
            //imageViewer = new ImageViewer();


            state = ST_IDLE;
        }
        // calibrator deafult constructor
        public Flea3Calibrator(PictureBox displaybox)
        {
            DisplayBox = displaybox;
            // 1. creating the camera object
            Cam = new ManagedCamera();
            // 2. creating the bus manager in order to handle (potentially)
            // multiple cameras
            BusMgr = new ManagedBusManager();

            // 3. retrieving the List of all camera ids connected to the bus
            CamIDs = new List <ManagedPGRGuid>();
            int camCount = (int)BusMgr.GetNumOfCameras();

            for (int i = 0; i < camCount; i++)
            {
                ManagedPGRGuid guid = BusMgr.GetCameraFromIndex((uint)i);
                CamIDs.Add(guid);
            }


            FrameCount      = FRAME_COUNT;
            ChessHorizCount = CHESS_HORIZ_CORNER_COUNT;
            ChessVertCount  = CHESS_VERT_CORNER_COUNT;

            RectWidth  = RECT_WIDTH;
            RectHeight = RECT_HEIGHT;

            // creatring the imageViewer to display the calibration frame sequence
            //imageViewer = new ImageViewer();


            state = ST_IDLE;
        }
Ejemplo n.º 5
0
        private bool FireSoftwareTrigger(ManagedCamera cam)
        {
            const uint k_softwareTrigger = 0x62C;
            const uint k_fireVal         = 0x80000000;

            cam.WriteRegister(k_softwareTrigger, k_fireVal);
            return(true);
        }
Ejemplo n.º 6
0
        static bool FireSoftwareTrigger(ManagedCamera cam)
        {
            const uint k_softwareTrigger = 0x62C;
            const uint k_fireVal = 0x80000000;

            cam.WriteRegister(k_softwareTrigger, k_fireVal);

            return true;
        }
Ejemplo n.º 7
0
        static bool FireSoftwareTrigger(ManagedCamera cam)
        {
            const uint SoftwareTrigger          = 0x62C;
            const uint SoftwareTriggerFireValue = 0x80000000;

            cam.WriteRegister(SoftwareTrigger, SoftwareTriggerFireValue);

            return(true);
        }
Ejemplo n.º 8
0
        private void OnConfigurationButtonClick(object sender, EventArgs e)
        {
            ManagedPGRGuid[] guids = GetCurrentSelectedGuids();
            foreach (ManagedPGRGuid guid in guids)
            {
                try
                {
                    InterfaceType ifType = m_busMgr.GetInterfaceTypeFromGuid(guid);

                    ManagedCameraBase camera;
                    if (ifType == InterfaceType.GigE)
                    {
                        camera = new ManagedGigECamera();
                    }
                    else
                    {
                        camera = new ManagedCamera();
                    }

                    camera.Connect(guid);

                    CameraInfo camInfo = camera.GetCameraInfo();

                    DialogHolder dialogHolder;
                    if (m_activeDialogs.TryGetValue(camInfo.serialNumber, out dialogHolder))
                    {
                        camera.Disconnect();
                        dialogHolder.camCtlMF.ReconnectCamera(guid);
                        dialogHolder.camCtlMF.ShowWindow();
                    }
                    else
                    {
                        CameraControlMainFrame camControlDialog;
                        camControlDialog = new CameraControlMainFrame();
                        camControlDialog.Connect(camera);

                        if (m_currentCustomTitle != null)
                        {
                            camControlDialog.SetTitle(m_currentCustomTitle);
                        }

                        camControlDialog.ShowWindow();
                        dialogHolder = new DialogHolder(camera, camControlDialog);
                        m_activeDialogs.Add(camInfo.serialNumber, dialogHolder);
                    }
                }
                catch (FC2Exception ex)
                {
                    string error = string.Format("Failed to launch camera control dialog for camera: {0}", ex.Message);
                    Debug.WriteLine(error);
                    MessageBox.Show(error, "FlyCapture2", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    ex.Dispose();
                    return;
                }
            }
        }
Ejemplo n.º 9
0
        public void ChooseCamera()
        {
            StopStreaming();
            DeleteCamera();

beginSelecCamera:
            CameraSelectionDialog selectDialog = new CameraSelectionDialog();

            if (selectDialog.ShowModal() == true)
            {
                ManagedPGRGuid[] guids = selectDialog.GetSelectedCameraGuids();

                if (guids.Length < 1)
                {
                    if (MessageBox.Show("You have not selected a camera. Do you want to restart camera selection diaolog?", "No camera", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
                    {
                        goto beginSelecCamera;
                    }
                    else
                    {
                        Application.Current.Shutdown();
                    }
                }
                m_busManager = new ManagedBusManager();

                var interfaceType = m_busManager.GetInterfaceTypeFromGuid(guids[0]);
                if (interfaceType == InterfaceType.GigE)
                {
                    m_camera = new ManagedGigECamera();
                }
                else
                {
                    m_camera = new ManagedCamera();
                }

                m_camera.Connect(guids[0]);

                EmbeddedImageInfo embeddedInfo = m_camera.GetEmbeddedImageInfo();
                embeddedInfo.timestamp.onOff = true;
                embeddedInfo.exposure.onOff  = true;
                embeddedInfo.shutter.onOff   = true;
                embeddedInfo.gain.onOff      = true;
                m_camera.SetEmbeddedImageInfo(embeddedInfo);

                float shutterMin = m_camera.GetPropertyInfo(PropertyType.Shutter).absMin, shutterMax = m_camera.GetPropertyInfo(PropertyType.Shutter).absMax;
                m_commonViewModel.CameraShutterRangeBegin = shutterMin; m_commonViewModel.CameraShutterRangeEnd = shutterMax;
                FC2Config config = m_camera.GetConfiguration();
                config.grabMode = GrabMode.BufferFrames;
                m_camera.SetConfiguration(config);
                m_cameraCtrlDialog.Connect(m_camera);
                m_commonViewModel.IsCameraChosen        = true;
                m_commonViewModel.IsStreamingWasStarted = false;
            }
        }
Ejemplo n.º 10
0
        static bool CheckSoftwareTriggerPresence(ManagedCamera cam)
        {
            const uint k_triggerInq = 0x530;
            uint regVal = cam.ReadRegister(k_triggerInq);

            if ((regVal & 0x10000) != 0x10000)
            {
                return false;
            }

            return true;
        }
Ejemplo n.º 11
0
        static bool CheckSoftwareTriggerPresence(ManagedCamera cam)
        {
            const uint k_triggerInq = 0x530;
            uint       regVal       = cam.ReadRegister(k_triggerInq);

            if ((regVal & 0x10000) != 0x10000)
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 12
0
        static bool CheckSoftwareTriggerPresence(ManagedCamera cam)
        {
            const uint TriggerInquiry      = 0x530;
            uint       triggerInquiryValue = cam.ReadRegister(TriggerInquiry);

            if ((triggerInquiryValue & 0x10000) != 0x10000)
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 13
0
        static bool PollForTriggerReady(ManagedCamera cam)
        {
            const uint SoftwareTrigger = 0x62C;

            uint softwareTriggerValue = 0;

            do
            {
                softwareTriggerValue = cam.ReadRegister(SoftwareTrigger);
            }while ((softwareTriggerValue >> 31) != 0);

            return(true);
        }
Ejemplo n.º 14
0
        static bool PollForTriggerReady(ManagedCamera cam)
        {
            const uint k_softwareTrigger = 0x62C;

            uint regVal = 0;

            do
            {
                regVal = cam.ReadRegister(k_softwareTrigger);
            }while ((regVal >> 31) != 0);

            return(true);
        }
Ejemplo n.º 15
0
        private string GenerateToolTipString(ManagedPGRGuid guid)
        {
            if (guid.Equals(m_lastTooltipGuid))
            {
                return(m_tooltipString);
            }

            m_lastTooltipGuid = guid;

            if (guid.Equals(m_currCameraGuid))
            {
                StringBuilder tooltipStr = new StringBuilder();
                tooltipStr.AppendFormat("Camera: {0} {1} ({2})", m_camInfo.vendorName, m_camInfo.modelName, m_camInfo.serialNumber).AppendLine();
                tooltipStr.AppendFormat("Sensor: {0}", m_camInfo.sensorInfo).AppendLine();
                tooltipStr.AppendFormat("Firmware: {0} Built: {1}", m_camInfo.firmwareVersion, m_camInfo.firmwareBuildTime).AppendLine();
                tooltipStr.AppendFormat("Driver: {0}", m_camInfo.driverName).AppendLine();

                m_tooltipString = tooltipStr.ToString();
                return(m_tooltipString);
            }

            ManagedCameraBase tempCamera = null;

            if (m_busMgr.GetInterfaceTypeFromGuid(guid) == InterfaceType.GigE)
            {
                tempCamera = new ManagedGigECamera();
            }
            else
            {
                tempCamera = new ManagedCamera();
            }

            using (tempCamera)
            {
                tempCamera.Connect(guid);
                CameraInfo camInfo = tempCamera.GetCameraInfo();

                StringBuilder tooltipStr = new StringBuilder();
                tooltipStr.AppendFormat("Camera: {0} {1} ({2})", camInfo.vendorName, camInfo.modelName, camInfo.serialNumber).AppendLine();
                tooltipStr.AppendFormat("Sensor: {0}", camInfo.sensorInfo).AppendLine();
                tooltipStr.AppendFormat("Firmware: {0} Built: {1}", camInfo.firmwareVersion, camInfo.firmwareBuildTime).AppendLine();
                tooltipStr.AppendFormat("Driver: {0}", camInfo.driverName).AppendLine();

                m_tooltipString = tooltipStr.ToString();
                return(m_tooltipString);
            }
        }
Ejemplo n.º 16
0
        static void Main()
        {
            ManagedBusManager busMgr = new ManagedBusManager();

            // Pop up the camera selection dialog
            FlyCapture2Managed.Gui.CameraSelectionDialog camSlnDlg = new FlyCapture2Managed.Gui.CameraSelectionDialog();
            if (camSlnDlg.ShowModal() == false)
            {
                MessageBox.Show("No cameras selected.", "Flycapture2", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            ManagedPGRGuid[] selectedGuids = camSlnDlg.GetSelectedCameraGuids();

            // Only start the first selected camera
            ManagedPGRGuid    guid = selectedGuids[0];
            InterfaceType     ifType;
            ManagedCameraBase camera;

            try
            {
                ifType = busMgr.GetInterfaceTypeFromGuid(guid);//unable to handle this error
            }
            catch (FC2Exception ex)
            {
                string error = string.Format("Failed to get interface for camera. {0}", ex.Message);
                Console.WriteLine(error);
                MessageBox.Show(error, "Flycapture 2", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (ifType == InterfaceType.GigE)
            {
                camera = new ManagedGigECamera();
            }
            else
            {
                camera = new ManagedCamera();
            }
            camera.Connect(guid);

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            CameraControlMainFrame mainWindow = new CameraControlMainFrame();

            mainWindow.Connect(camera);
            mainWindow.ShowWindow();
        }
Ejemplo n.º 17
0
        void RunSingleCamera(ManagedPGRGuid guid)
        {
            const int k_numImages = 10;

            ManagedCamera cam = new ManagedCamera();

            // Connect to a camera
            cam.Connect(guid);

            // Get the camera information
            CameraInfo camInfo = cam.GetCameraInfo();

            PrintCameraInfo(camInfo);

            // Get embedded image info from camera
            EmbeddedImageInfo embeddedInfo = cam.GetEmbeddedImageInfo();

            // Enable timestamp collection
            if (embeddedInfo.timestamp.available == true)
            {
                embeddedInfo.timestamp.onOff = true;
            }

            // Set embedded image info to camera
            cam.SetEmbeddedImageInfo(embeddedInfo);

            // Start capturing images
            cam.StartCapture(OnImageGrabbed);

            CameraProperty frameRateProp = cam.GetProperty(PropertyType.FrameRate);

            while (imageCnt < 10)
            {
                int millisecondsToSleep = (int)(1000 / frameRateProp.absValue);
                Thread.Sleep(millisecondsToSleep);
            }

            // Stop capturing images
            cam.StopCapture();

            // Disconnect the camera
            cam.Disconnect();

            // Reset counter for next iteration
            imageCnt = 0;
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Retrieve F7 info from camera
        /// </summary>
        /// <returns></returns>
        private Format7Info QueryFormat7Info()
        {
            ManagedCamera camera = (ManagedCamera)m_camera;

            Format7ImageSettings imageSettings = new Format7ImageSettings();
            uint  packetSize = 0;
            float speed      = 0;

            camera.GetFormat7Configuration(imageSettings, ref packetSize, ref speed);

            Format7Info fmt7Info  = new Format7Info();
            bool        supported = false;

            fmt7Info = camera.GetFormat7Info(imageSettings.mode, ref supported);

            return(fmt7Info);
        }
Ejemplo n.º 19
0
        private ArrayList GetIIDCSupportedVideoMode(ManagedCamera camera)
        {
            ArrayList supportedVideoMode = new ArrayList();

            for (VideoMode videoModeIterator = k_theFirstVideoMode;
                 videoModeIterator < VideoMode.NumberOfVideoModes; // VideoMode.NumberOfVideoModes is always the last element in the enum
                 videoModeIterator++)
            {
                if (videoModeIterator == VideoMode.VideoModeFormat7)
                {
                    //skip this video mode, it is for ManagedGigECamera (GEV)
                    continue;
                }

                for (FrameRate frameRateIterator = k_theFirstFrameRateType; frameRateIterator < FrameRate.NumberOfFrameRates; frameRateIterator++)
                {
                    bool supported = false;
                    if (frameRateIterator == FrameRate.FrameRateFormat7)
                    {
                        //skip this frame rate, it is for ManagedGigECamera (GEV)
                        continue;
                    }

                    try
                    {
                        supported = camera.GetVideoModeAndFrameRateInfo(videoModeIterator, frameRateIterator);
                    }
                    catch (FC2Exception ex)
                    {
                        string error = string.Format("Error querying video mode and frame rate {0}", ex.Message);
                        Console.WriteLine(error);
                        MessageBox.Show(error, "FlyCapture2 Camera Control", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        break;
                    }

                    if (supported)
                    {
                        supportedVideoMode.Add(videoModeIterator);
                        break;
                    }
                }
            }

            return(supportedVideoMode);
        }
Ejemplo n.º 20
0
        /// <summary>
        ///Initialize a point Grey Camera, it take the first that it detect if their is more than one.
        ///Give the default setting.
        /// </summary>
        /// <exception cref="NoCameraDetectedException">Thrown if no camera is detected.</exception>
        public PtGreyCamera()
        {
            using ManagedBusManager busMgr = new ManagedBusManager();
            setting = new PtGreyCameraSetting();
            uint numCameras = busMgr.GetNumOfCameras();

            if (numCameras == 0)
            {
                throw new NoCameraDetectedException {
                          Source = "PointGrey"
                };
            }

            ManagedPGRGuid guid = busMgr.GetCameraFromIndex(0); //If there is more than 1 camera, we take the first one

            cam = new ManagedCamera();
            cam.Connect(guid);
            SetProp();
        }
        public void add(ManagedCamera cam)
        {
            cam.RetrieveBuffer(temp);

            BufSemaphore.WaitOne();

            if (isEmpty())
            {
                first = last = 0;
                //Buffer[last] = img;

            } else {
                last = (last + 1) % MAX_LEN;
                //Buffer[last] = img;
            }
            Buffer[last] = temp;

            BufSemaphore.Release();
        }
Ejemplo n.º 22
0
        public FullImageWindow()
        {
            InitializeComponent();
            this.Title = string.Format("Point Grey Research. Zoom Demo. Tier {0}", (RenderCapability.Tier >> 16).ToString());

            m_busmgr    = new ManagedBusManager();
            m_cam       = new ManagedCamera();
            m_ctldlg    = new CameraControlDialog();
            m_selDlg    = new CameraSelectionDialog();
            m_image     = new ManagedImage();
            m_converted = new ManagedImage();

            m_bitmap = new BitmapImage();
            m_worker = new BackgroundWorker();
            m_worker.WorkerReportsProgress = true;
            m_worker.DoWork          += new DoWorkEventHandler(m_worker_DoWork);
            m_worker.ProgressChanged += new ProgressChangedEventHandler(m_worker_ProgressChanged);
            m_Done = new AutoResetEvent(false);

            RenderOptions.SetBitmapScalingMode(myImage, BitmapScalingMode.LowQuality);
            RenderOptions.SetEdgeMode(myImage, EdgeMode.Aliased);

            if (m_selDlg.ShowModal())
            {
                ManagedPGRGuid[] guids = m_selDlg.GetSelectedCameraGuids();
                m_cam.Connect(guids[0]);
                m_ctldlg.Connect(m_cam);
                m_cam.StartCapture();

                btn_nearfast.IsChecked = true;

                WorkerHelper helper = new WorkerHelper();
                helper.converted = m_converted;
                helper.raw       = m_image;
                helper.cam       = m_cam;
                m_continue       = true;
                m_worker.RunWorkerAsync(helper);
            }
            else
            {
                Application.Current.Shutdown();
            }
        }
Ejemplo n.º 23
0
        public void add(ManagedCamera cam)
        {
            cam.RetrieveBuffer(temp);

            BufSemaphore.WaitOne();

            if (isEmpty())
            {
                first = last = 0;
                //Buffer[last] = img;
            }
            else
            {
                last = (last + 1) % MAX_LEN;
                //Buffer[last] = img;
            }
            Buffer[last] = temp;

            BufSemaphore.Release();
        }
Ejemplo n.º 24
0
        private FrameRate UpdateCurrentAvailableFrameRate(VideoMode currentVideoMode)
        {
            //this function will return the current fastest frame rate for this video mode
            ManagedCamera camera           = (ManagedCamera)m_camera;
            FrameRate     fastestFrameRate = FrameRate.NumberOfFrameRates;

            for (int i = 0; i < m_frameRateRadioButton.Length; i++)
            {
                if (m_frameRateRadioButton[i] == null)
                {
                    //skip unmapped radio buttons
                    continue;
                }

                bool      supported        = false;
                FrameRate currentFrameRate = (FrameRate)m_frameRateRadioButton[i].Tag;
                try
                {
                    supported = camera.GetVideoModeAndFrameRateInfo(currentVideoMode, currentFrameRate);
                }
                catch (FC2Exception ex)
                {
                    string error = string.Format("Error querying video mode and frame rate {0}", ex.Message);
                    Console.WriteLine(error);
                    MessageBox.Show(error, "FlyCapture2 Camera Control", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    break;
                }

                if (supported)
                {
                    m_frameRateRadioButton[i].Visible = true;
                    fastestFrameRate = currentFrameRate;
                }
                else
                {
                    m_frameRateRadioButton[i].Visible = false;
                }
            }

            return(fastestFrameRate);
        }
Ejemplo n.º 25
0
        /// <summary>
        ///Initialize a point Grey Camera, it take the first that it detect if their is more than one.
        ///Utilize the given settings to initialize the camera.
        /// </summary>
        /// <exception cref="NoCameraDetectedException">Thrown if no camera is detected.</exception>
        /// <param name="setting">Setting used for the camera</param>
        public PtGreyCamera(PtGreyCameraSetting setting)
        {
            using ManagedBusManager busMgr = new ManagedBusManager();
            this.setting = setting;
            uint numCameras = busMgr.GetNumOfCameras();

            Console.WriteLine(numCameras);
            // Finish if there are no cameras
            if (numCameras == 0)
            {
                throw new NoCameraDetectedException();
            }

            ManagedPGRGuid guid = busMgr.GetCameraFromIndex(0); //If there is more than 1 camera, we take the first one

            cam = new ManagedCamera();

            cam.Connect(guid);

            SetProp();
        }
Ejemplo n.º 26
0
        /// <summary>
        /// Check whether camera is currently in F7
        /// </summary>
        /// <returns></returns>
        private bool IsCurrentlyInFormat7()
        {
            if (IsGEV() == true)
            {
                return(true);
            }

            VideoMode     currVideoMode = VideoMode.NumberOfVideoModes;
            FrameRate     currFrameRate = FrameRate.NumberOfFrameRates;
            ManagedCamera camera        = (ManagedCamera)m_camera;

            try
            {
                camera.GetVideoModeAndFrameRate(ref currVideoMode, ref currFrameRate);
            }
            catch (FC2Exception ex)
            {
                ShowErrorMessageDialog("Error getting current video mode and frame rate", ex);
            }

            return(currVideoMode == VideoMode.VideoModeFormat7);
        }
        // A timer used to sample the IMU during the intervals betweem frame captures
        //private System.Timers.Timer IMUSamplingTimer;


        public Flea3Recorder(GPSReceiver gpsReceiver, IMUCommsDevice imu)
        {
            int i;

            IMUcomms = imu;



            // 1. creating the camera object
            Cam = new ManagedCamera();
            // 2. creating the bus manager in order to handle (potentially)
            // multiple cameras
            BusMgr = new ManagedBusManager();

            // 3. retrieving the List of all camera ids connected to the bus
            CamIDs = new List <ManagedPGRGuid>();
            int camCount = (int)BusMgr.GetNumOfCameras();

            for (i = 0; i < camCount; i++)
            {
                ManagedPGRGuid guid = BusMgr.GetCameraFromIndex((uint)i);
                CamIDs.Add(guid);
            }

            // 4. assigning values to properties
            GpsReceiver = gpsReceiver;

            // 5. init flags
            RecordingThreadActive = false;

            RecordToFile = false;

            OutOfRecordingThread = OutOfDumpingThread = true;

            // 6. Creating the Frame data queue
            FrameQueue = new ManagedImageRollingBuffer(MAX_FRAMEQUEUE_LEN);
        }
Ejemplo n.º 28
0
        private void UpdateNodeInformation(ManagedPGRGuid guidToUse)
        {
            // Fix for Bug 22724
            if (guidToUse.Equals(m_currCameraGuid))
            {
                UpdateNodeModelInformation(m_camInfo);
                UpdateNodeProductIDInformation();
                UpdateNodeVoltageInformation(m_camera);
                UpdateNodeCurrentInformation(m_camera, m_camInfo);
                UpdatePhyRegisters();
            }
            else
            {
                using (ManagedCamera camera = new ManagedCamera())
                {
                    CameraInfo camInfo;

                    try
                    {
                        camera.Connect(guidToUse);
                        camInfo = camera.GetCameraInfo();
                    }
                    catch (FC2Exception ex)
                    {
                        UpdatePhyRegisters();
                        ex.Dispose();
                        return;
                    }

                    UpdateNodeModelInformation(camInfo);
                    UpdateNodeProductIDInformation();
                    UpdateNodeVoltageInformation(camera);
                    UpdateNodeCurrentInformation(camera, camInfo);
                    UpdatePhyRegisters();
                }
            }
        }
Ejemplo n.º 29
0
		void Refresh()
		{
			int nDevices = (int)Context.Bus.GetNumOfCameras();
			ManagedPGRGuid guid;
			ManagedCamera cam = new ManagedCamera();

			FPinOutGUID.SliceCount = nDevices;
			FPinOutInfo.SliceCount = nDevices;
			FPinOutCount[0] = nDevices;

			for (int i = 0; i < nDevices; i++)
			{
				guid = Context.Bus.GetCameraFromIndex((uint)i);

				FPinOutGUID[i] = guid;

				cam.Connect(guid);
				FPinOutInfo[(int)i] = cam.GetCameraInfo();
				cam.Disconnect();
			}

			
			cam.Dispose();
		}
Ejemplo n.º 30
0
        void Refresh()
        {
            int            nDevices = (int)Context.Bus.GetNumOfCameras();
            ManagedPGRGuid guid;
            ManagedCamera  cam = new ManagedCamera();

            FPinOutGUID.SliceCount = nDevices;
            FPinOutInfo.SliceCount = nDevices;
            FPinOutCount[0]        = nDevices;

            for (int i = 0; i < nDevices; i++)
            {
                guid = Context.Bus.GetCameraFromIndex((uint)i);

                FPinOutGUID[i] = guid;

                cam.Connect(guid);
                FPinOutInfo[(int)i] = cam.GetCameraInfo();
                cam.Disconnect();
            }


            cam.Dispose();
        }
Ejemplo n.º 31
0
        static void Main(string[] args)
        {
            PrintBuildInfo();

            const Mode        k_fmt7Mode        = Mode.Mode0;
            const PixelFormat k_fmt7PixelFormat = PixelFormat.PixelFormatMono8;
            const int         k_numImages       = 10;

            // Since this application saves images in the current folder
            // we must ensure that we have permission to write to this folder.
            // If we do not have permission, fail right away.
            FileStream fileStream;

            try
            {
                fileStream = new FileStream(@"test.txt", FileMode.Create);
                fileStream.Close();
                File.Delete("test.txt");
            }
            catch
            {
                Console.WriteLine("Failed to create file in current folder.  Please check permissions.\n");
                return;
            }

            ManagedBusManager busMgr = new ManagedBusManager();
            uint numCameras          = busMgr.GetNumOfCameras();

            Console.WriteLine("Number of cameras detected: {0}", numCameras);

            ManagedPGRGuid guid = busMgr.GetCameraFromIndex(0);

            ManagedCamera cam = new ManagedCamera();

            cam.Connect(guid);

            // Get the camera information
            CameraInfo camInfo = cam.GetCameraInfo();

            PrintCameraInfo(camInfo);

            // Query for available Format 7 modes
            bool        supported = false;
            Format7Info fmt7Info  = cam.GetFormat7Info(k_fmt7Mode, ref supported);

            PrintFormat7Capabilities(fmt7Info);

            if ((k_fmt7PixelFormat & (PixelFormat)fmt7Info.pixelFormatBitField) == 0)
            {
                // Pixel format not supported!
                return;
            }

            Format7ImageSettings fmt7ImageSettings = new Format7ImageSettings();

            fmt7ImageSettings.mode        = k_fmt7Mode;
            fmt7ImageSettings.offsetX     = 0;
            fmt7ImageSettings.offsetY     = 0;
            fmt7ImageSettings.width       = fmt7Info.maxWidth;
            fmt7ImageSettings.height      = fmt7Info.maxHeight;
            fmt7ImageSettings.pixelFormat = k_fmt7PixelFormat;

            // Validate the settings to make sure that they are valid
            bool settingsValid = false;
            Format7PacketInfo fmt7PacketInfo = cam.ValidateFormat7Settings(
                fmt7ImageSettings,
                ref settingsValid);

            if (settingsValid != true)
            {
                // Settings are not valid
                return;
            }

            // Set the settings to the camera
            cam.SetFormat7Configuration(
                fmt7ImageSettings,
                fmt7PacketInfo.recommendedBytesPerPacket);

            // Get embedded image info from camera
            EmbeddedImageInfo embeddedInfo = cam.GetEmbeddedImageInfo();

            // Enable timestamp collection
            if (embeddedInfo.timestamp.available == true)
            {
                embeddedInfo.timestamp.onOff = true;
            }

            // Set embedded image info to camera
            cam.SetEmbeddedImageInfo(embeddedInfo);

            // Start capturing images
            cam.StartCapture();

            // Retrieve frame rate property
            CameraProperty frmRate = cam.GetProperty(PropertyType.FrameRate);

            Console.WriteLine("Frame rate is {0:F2} fps", frmRate.absValue);

            Console.WriteLine("Grabbing {0} images", k_numImages);

            ManagedImage rawImage = new ManagedImage();

            for (int imageCnt = 0; imageCnt < k_numImages; imageCnt++)
            {
                // Retrieve an image
                cam.RetrieveBuffer(rawImage);

                // Get the timestamp
                TimeStamp timeStamp = rawImage.timeStamp;

                Console.WriteLine(
                    "Grabbed image {0} - {1} {2} {3}",
                    imageCnt,
                    timeStamp.cycleSeconds,
                    timeStamp.cycleCount,
                    timeStamp.cycleOffset);

                // Create a converted image
                ManagedImage convertedImage = new ManagedImage();

                // Convert the raw image
                rawImage.Convert(PixelFormat.PixelFormatBgr, convertedImage);

                // Create a unique filename
                string filename = String.Format(
                    "CustomImageEx_CSharp-{0}-{1}.bmp",
                    camInfo.serialNumber,
                    imageCnt);

                // Get the Bitmap object. Bitmaps are only valid if the
                // pixel format of the ManagedImage is RGB or RGBU.
                System.Drawing.Bitmap bitmap = convertedImage.bitmap;

                // Save the image
                bitmap.Save(filename);
            }

            // Stop capturing images
            cam.StopCapture();

            // Disconnect the camera
            cam.Disconnect();

            Console.WriteLine("Done! Press any key to exit...");
            Console.ReadKey();
        }
Ejemplo n.º 32
0
        public void RunSingleCamera(ManagedPGRGuid guid)
        {
            const int k_numImages = 10;

            ManagedCamera cam = new ManagedCamera();

            // Connect to a camera
            cam.Connect(guid);

            // Get the camera information
            CameraInfo camInfo = cam.GetCameraInfo();

            PrintCameraInfo(camInfo);

            // Get embedded image info from camera
            EmbeddedImageInfo embeddedInfo = cam.GetEmbeddedImageInfo();

            // Enable timestamp collection
            if (embeddedInfo.timestamp.available == true)
            {
                embeddedInfo.timestamp.onOff = true;
            }

            // Set embedded image info to camera
            cam.SetEmbeddedImageInfo(embeddedInfo);

            // Start capturing images
            cam.StartCapture();

            // Create a raw image
            ManagedImage rawImage = new ManagedImage();

            // Create a converted image
            ManagedImage convertedImage = new ManagedImage();

            for (int imageCnt = 0; imageCnt < k_numImages; imageCnt++)
            {
                // Retrieve an image
                cam.RetrieveBuffer(rawImage);

                // Get the timestamp
                TimeStamp timeStamp = rawImage.timeStamp;

                Console.WriteLine(
                    "Grabbed image {0} - {1} {2} {3}",
                    imageCnt,
                    timeStamp.cycleSeconds,
                    timeStamp.cycleCount,
                    timeStamp.cycleOffset);

                // Convert the raw image
                rawImage.Convert(PixelFormat.PixelFormatBgr, convertedImage);

                // Create a unique filename
                string filename = String.Format(
                    "FlyCapture2Test_CSharp-{0}-{1}.bmp",
                    camInfo.serialNumber,
                    imageCnt);

                // Get the Bitmap object. Bitmaps are only valid if the
                // pixel format of the ManagedImage is RGB or RGBU.
                System.Drawing.Bitmap bitmap = convertedImage.bitmap;

                // Save the image
                bitmap.Save(filename);
            }

            // Stop capturing images
            cam.StopCapture();

            // Disconnect the camera
            cam.Disconnect();
        }
Ejemplo n.º 33
0
        static void Main(string[] args)
        {
            PrintBuildInfo();

            const int k_numImages = 10;
            bool useSoftwareTrigger = true;

            ManagedBusManager busMgr = new ManagedBusManager();
            uint numCameras = busMgr.GetNumOfCameras();

            Console.WriteLine("Number of cameras detected: {0}", numCameras);

            ManagedPGRGuid guid = busMgr.GetCameraFromIndex(0);

            ManagedCamera cam = new ManagedCamera();

            cam.Connect(guid);

            // Get the camera information
            CameraInfo camInfo = cam.GetCameraInfo();

            PrintCameraInfo(camInfo);

            if (!useSoftwareTrigger)
            {
                // Check for external trigger support
                TriggerModeInfo triggerModeInfo = cam.GetTriggerModeInfo();
                if (triggerModeInfo.present != true)
                {
                    Console.WriteLine("Camera does not support external trigger! Exiting...\n");
                    return;
                }
            }

            // Get current trigger settings
            TriggerMode triggerMode = cam.GetTriggerMode();

            // Set camera to trigger mode 0
            // A source of 7 means software trigger
            triggerMode.onOff = true;
            triggerMode.mode = 0;
            triggerMode.parameter = 0;

            if (useSoftwareTrigger)
            {
                // A source of 7 means software trigger
                triggerMode.source = 7;
            }
            else
            {
                // Triggering the camera externally using source 0.
                triggerMode.source = 0;
            }

            // Set the trigger mode
            cam.SetTriggerMode(triggerMode);

            // Poll to ensure camera is ready
            bool retVal = PollForTriggerReady(cam);
            if (retVal != true)
            {
                return;
            }

            // Get the camera configuration
            FC2Config config = cam.GetConfiguration();

            // Set the grab timeout to 5 seconds
            config.grabTimeout = 5000;

            // Set the camera configuration
            cam.SetConfiguration(config);

            // Camera is ready, start capturing images
            cam.StartCapture();

            if (useSoftwareTrigger)
            {
                if (CheckSoftwareTriggerPresence(cam) == false)
                {
                    Console.WriteLine("SOFT_ASYNC_TRIGGER not implemented on this camera!  Stopping application\n");
                    return;
                }
            }
            else
            {
                Console.WriteLine("Trigger the camera by sending a trigger pulse to GPIO%d.\n",
                  triggerMode.source);
            }

            ManagedImage image = new ManagedImage();
            for (int iImageCount = 0; iImageCount < k_numImages; iImageCount++)
            {
                if (useSoftwareTrigger)
                {

                    // Check that the trigger is ready
                    retVal = PollForTriggerReady(cam);

                    Console.WriteLine("Press the Enter key to initiate a software trigger.\n");
                    Console.ReadLine();

                    // Fire software trigger
                    retVal = FireSoftwareTrigger(cam);
                    if (retVal != true)
                    {
                        Console.WriteLine("Error firing software trigger!");
                        return;
                    }
                }

                // Grab image
                cam.RetrieveBuffer(image);

                Console.WriteLine(".\n");
            }

            Console.WriteLine("Finished grabbing images");

            // Stop capturing images
            cam.StopCapture();

            // Turn off trigger mode
            triggerMode.onOff = false;
            cam.SetTriggerMode(triggerMode);

            // Disconnect the camera
            cam.Disconnect();

            Console.WriteLine("Done! Press any key to exit...");
            Console.ReadKey();
        }
Ejemplo n.º 34
0
        void RunSingleCamera(ManagedPGRGuid guid)
        {
            const int k_numImages = 10;

            ManagedCamera cam = new ManagedCamera();

            // Connect to a camera
            cam.Connect(guid);

            // Get the camera information
            CameraInfo camInfo = cam.GetCameraInfo();

            PrintCameraInfo(camInfo);

            // Get embedded image info from camera
            EmbeddedImageInfo embeddedInfo = cam.GetEmbeddedImageInfo();

            // Enable timestamp collection
            if (embeddedInfo.timestamp.available == true)
            {
                embeddedInfo.timestamp.onOff = true;
            }

            // Set embedded image info to camera
            cam.SetEmbeddedImageInfo(embeddedInfo);

            // Start capturing images
            cam.StartCapture(OnImageGrabbed);

            CameraProperty frameRateProp = cam.GetProperty(PropertyType.FrameRate);

            while (imageCnt < 10)
            {
                int millisecondsToSleep = (int)(1000 / frameRateProp.absValue);
                Thread.Sleep(millisecondsToSleep);
            }

            // Stop capturing images
            cam.StopCapture();

            // Disconnect the camera
            cam.Disconnect();
        }
Ejemplo n.º 35
0
        static bool PollForTriggerReady(ManagedCamera cam)
        {
            const uint k_softwareTrigger = 0x62C;

            uint regVal = 0;

            do
            {
                regVal = cam.ReadRegister(k_softwareTrigger);
            }
            while ((regVal >> 31) != 0);

            return true;
        }
Ejemplo n.º 36
0
        static void Main(string[] args)
        {
            PrintBuildInfo();

            const Mode k_fmt7Mode = Mode.Mode0;
            const PixelFormat k_fmt7PixelFormat = PixelFormat.PixelFormatMono8;
            const int k_numImages = 10;

            // Since this application saves images in the current folder
            // we must ensure that we have permission to write to this folder.
            // If we do not have permission, fail right away.
            FileStream fileStream;
            try
            {
                fileStream = new FileStream(@"test.txt", FileMode.Create);
                fileStream.Close();
                File.Delete("test.txt");
            }
            catch
            {
                Console.WriteLine("Failed to create file in current folder.  Please check permissions.\n");
                return;
            }

            ManagedBusManager busMgr = new ManagedBusManager();
            uint numCameras = busMgr.GetNumOfCameras();

            Console.WriteLine("Number of cameras detected: {0}", numCameras);

            ManagedPGRGuid guid = busMgr.GetCameraFromIndex(0);

            ManagedCamera cam = new ManagedCamera();

            cam.Connect(guid);

            // Get the camera information
            CameraInfo camInfo = cam.GetCameraInfo();

            PrintCameraInfo(camInfo);

            // Query for available Format 7 modes
            bool supported = false;
            Format7Info fmt7Info = cam.GetFormat7Info(k_fmt7Mode, ref supported);

            PrintFormat7Capabilities(fmt7Info);

            if ((k_fmt7PixelFormat & (PixelFormat)fmt7Info.pixelFormatBitField) == 0)
            {
                // Pixel format not supported!
                return;
            }

            Format7ImageSettings fmt7ImageSettings = new Format7ImageSettings();
            fmt7ImageSettings.mode = k_fmt7Mode;
            fmt7ImageSettings.offsetX = 0;
            fmt7ImageSettings.offsetY = 0;
            fmt7ImageSettings.width = fmt7Info.maxWidth;
            fmt7ImageSettings.height = fmt7Info.maxHeight;
            fmt7ImageSettings.pixelFormat = k_fmt7PixelFormat;

            // Validate the settings to make sure that they are valid
            bool settingsValid = false;
            Format7PacketInfo fmt7PacketInfo = cam.ValidateFormat7Settings(
                fmt7ImageSettings,
                ref settingsValid);

            if (settingsValid != true)
            {
                // Settings are not valid
                return;
            }

            // Set the settings to the camera
            cam.SetFormat7Configuration(
               fmt7ImageSettings,
               fmt7PacketInfo.recommendedBytesPerPacket);

            // Get embedded image info from camera
            EmbeddedImageInfo embeddedInfo = cam.GetEmbeddedImageInfo();

            // Enable timestamp collection
            if (embeddedInfo.timestamp.available == true)
            {
                embeddedInfo.timestamp.onOff = true;
            }

            // Set embedded image info to camera
            cam.SetEmbeddedImageInfo(embeddedInfo);

            // Start capturing images
            cam.StartCapture();

            // Retrieve frame rate property
            CameraProperty frmRate = cam.GetProperty(PropertyType.FrameRate);

            Console.WriteLine("Frame rate is {0:F2} fps", frmRate.absValue);

            Console.WriteLine("Grabbing {0} images", k_numImages);

            ManagedImage rawImage = new ManagedImage();
            for (int imageCnt = 0; imageCnt < k_numImages; imageCnt++)
            {
                // Retrieve an image
                cam.RetrieveBuffer(rawImage);

                // Get the timestamp
                TimeStamp timeStamp = rawImage.timeStamp;

                Console.WriteLine(
                   "Grabbed image {0} - {1} {2} {3}",
                   imageCnt,
                   timeStamp.cycleSeconds,
                   timeStamp.cycleCount,
                   timeStamp.cycleOffset);

                // Create a converted image
                ManagedImage convertedImage = new ManagedImage();

                // Convert the raw image
                rawImage.Convert(PixelFormat.PixelFormatBgr, convertedImage);

                // Create a unique filename
                string filename = String.Format(
                   "CustomImageEx_CSharp-{0}-{1}.bmp",
                   camInfo.serialNumber,
                   imageCnt);

                // Get the Bitmap object. Bitmaps are only valid if the
                // pixel format of the ManagedImage is RGB or RGBU.
                System.Drawing.Bitmap bitmap = convertedImage.bitmap;

                // Save the image
                bitmap.Save(filename);
            }

            // Stop capturing images
            cam.StopCapture();

            // Disconnect the camera
            cam.Disconnect();

            Console.WriteLine("Done! Press any key to exit...");
            Console.ReadKey();
        }
        // calibrator deafult constructor
        public Flea3Calibrator(PictureBox displaybox)
        {
            DisplayBox = displaybox;
             // 1. creating the camera object
            Cam = new ManagedCamera();
            // 2. creating the bus manager in order to handle (potentially)
            // multiple cameras
            BusMgr = new ManagedBusManager();

            // 3. retrieving the List of all camera ids connected to the bus
            CamIDs = new List<ManagedPGRGuid>();
            int camCount = (int)BusMgr.GetNumOfCameras();
            for (int i = 0; i < camCount; i++)
            {
                ManagedPGRGuid guid = BusMgr.GetCameraFromIndex((uint)i);
                CamIDs.Add(guid);
            }

            FrameCount = FRAME_COUNT;
            ChessHorizCount = CHESS_HORIZ_CORNER_COUNT;
            ChessVertCount = CHESS_VERT_CORNER_COUNT;

            RectWidth = RECT_WIDTH;
            RectHeight = RECT_HEIGHT;

            // creatring the imageViewer to display the calibration frame sequence
            //imageViewer = new ImageViewer();

            state = ST_IDLE;
        }
        // calibrator constructor#2
        public Flea3Calibrator(int horiz_corner_count, int vert_corner_count, 
                                        float rect_width, float rect_height, int frame_count, PictureBox displaybox)
        {
            DisplayBox = displaybox;
            // 1. creating the camera object
            Cam = new ManagedCamera();
            // 2. creating the bus manager in order to handle (potentially)
            // multiple cameras
            BusMgr = new ManagedBusManager();

            // 3. retrieving the List of all camera ids connected to the bus
            CamIDs = new List<ManagedPGRGuid>();
            int camCount = (int)BusMgr.GetNumOfCameras();
            for (int i = 0; i < camCount; i++)
            {
                ManagedPGRGuid guid = BusMgr.GetCameraFromIndex((uint)i);
                CamIDs.Add(guid);
            }

            FrameCount = frame_count;
            ChessHorizCount = horiz_corner_count;
            ChessVertCount = vert_corner_count;

            RectWidth = rect_width;
            RectHeight = rect_height;

            // creatring the imageViewer to display the calibration frame sequence
            //imageViewer = new ImageViewer();

            state = ST_IDLE;
        }
Ejemplo n.º 39
0
        private void PopulateCameraList()
        {
            uint numCameras = 0;

            CameraInfo[] discoveredCameras = new CameraInfo[0];

            try
            {
                numCameras        = m_busMgr.GetNumOfCameras();
                discoveredCameras = ManagedBusManager.DiscoverGigECameras();
            }
            catch (FC2Exception ex)
            {
                BasePage.ShowErrorMessageDialog("Error getting number of cameras.", ex);
            }

            if (numCameras == 0 && discoveredCameras.Length == 0)
            {
                m_cameraListLabel.Text = string.Format("Camera List (No cameras detected)");
                m_cameraDataGridView.Rows.Clear();
                m_cameraInfoPanel.ClearInformation();
                HideGigEInformation();
                AdjustWindowMinimumSize();
                this.Height = this.MinimumSize.Height;
                m_needShrinkWindowHeight = false;
                return;
            }

            SortedDictionary <uint, CameraInfo> discoveredCameraInfo = new SortedDictionary <uint, CameraInfo>();

            m_badCameraInfo  = new Dictionary <string, CameraInfo>();
            m_goodCameraInfo = new Dictionary <ManagedPGRGuid, CameraInfo>();

            for (uint currCamIdx = 0; currCamIdx < discoveredCameras.Length; currCamIdx++)
            {
                try
                {
                    Debug.WriteLine(
                        String.Format(
                            "Discovered camera: {0} ({1})",
                            discoveredCameras[currCamIdx].modelName,
                            discoveredCameras[currCamIdx].serialNumber));

                    // Check if the camera already exists - we sometimes get duplicate cameras
                    // returned from the discover call
                    if (!discoveredCameraInfo.ContainsKey(discoveredCameras[currCamIdx].serialNumber))
                    {
                        discoveredCameraInfo.Add(
                            discoveredCameras[currCamIdx].serialNumber,
                            discoveredCameras[currCamIdx]);
                    }
                }
                catch (ArgumentNullException ex)
                {
                    Debug.WriteLine("A null key was specified for discovered camera lookup.");
                    Debug.WriteLine(ex.Message);
                    Debug.WriteLine(ex.StackTrace);
                    continue;
                }
                catch (ArgumentException ex)
                {
                    Debug.WriteLine("An element with the same key already exists in the discovered camera dictionary.");
                    Debug.WriteLine(ex.Message);
                    Debug.WriteLine(ex.StackTrace);
                    continue;
                }
                catch (System.Exception ex)
                {
                    Debug.WriteLine("An error occurred while updating the discovered GigE camera list.");
                    Debug.WriteLine(ex.Message);
                    Debug.WriteLine(ex.StackTrace);
                    continue;
                }
            }

            List <DataGridViewRow> goodCameraList = new List <DataGridViewRow>();
            List <DataGridViewRow> badCameraList  = new List <DataGridViewRow>();

            for (uint i = 0; i < numCameras; i++)
            {
                try
                {
                    ManagedPGRGuid guid;
                    guid = m_busMgr.GetCameraFromIndex(i);

                    InterfaceType currInterface;
                    currInterface = m_busMgr.GetInterfaceTypeFromGuid(guid);

                    using (ManagedCamera camera = new ManagedCamera())
                    {
                        bool   compatibleDriver = true;
                        string errorMessage     = string.Empty;

                        try
                        {
                            camera.Connect(guid);
                        }
                        catch (FC2Exception ex)
                        {
                            if (ex.Type == ErrorType.IncompatibleDriver)
                            {
                                compatibleDriver = false;
                                errorMessage     = ex.Message;
                            }
                        }

                        CameraInfo camInfo;

                        if (compatibleDriver)
                        {
                            camInfo = camera.GetCameraInfo();

                            if (discoveredCameraInfo.ContainsKey(camInfo.serialNumber) == true)
                            {
                                // Remove good camera from dictionary
                                discoveredCameraInfo.Remove(camInfo.serialNumber);
                                m_goodCameraInfo.Add(guid, camInfo);
                            }

                            // Append the camera to the list
                            try
                            {
                                DataGridViewRow           newCamera = new DataGridViewRow();
                                DataGridViewTextBoxCell[] cells     = new DataGridViewTextBoxCell[4];
                                for (int ci = 0; ci < cells.Length; ci++)
                                {
                                    cells[ci] = new DataGridViewTextBoxCell();
                                }

                                cells[0].Value = camInfo.serialNumber.ToString();
                                cells[1].Value = camInfo.modelName;
                                cells[2].Value = InterfaceTranslator.GetInterfaceString(currInterface);
                                cells[3].Value = camInfo.ipAddress.Equals(new IPAddress(0))
                                    ? "N/A"
                                    : camInfo.ipAddress.ToString();

                                newCamera.Cells.AddRange(cells);
                                goodCameraList.Add(newCamera);
                            }
                            catch (InvalidOperationException ex)
                            {
                                Debug.WriteLine("Error appending new row to camera list.");
                                Debug.WriteLine(ex.Message);
                                Debug.WriteLine(ex.StackTrace);
                                continue;
                            }
                            catch (ArgumentNullException ex)
                            {
                                Debug.WriteLine("The cell in camera list contains null value.");
                                Debug.WriteLine(ex.Message);
                                Debug.WriteLine(ex.StackTrace);
                                continue;
                            }
                        }
                        else
                        {
                            camInfo = new CameraInfo();

                            DataGridViewRow newCamera = new DataGridViewRow();

                            newCamera.DefaultCellStyle.BackColor = IMCOMPATIBLE_DRIVER;
                            DataGridViewTextBoxCell[] cells = new DataGridViewTextBoxCell[4];
                            for (int ci = 0; ci < cells.Length; ci++)
                            {
                                cells[ci] = new DataGridViewTextBoxCell();
                            }

                            cells[0].Value = "N/A";
                            cells[1].Value = ManagedUtilities.GetDriverDeviceName(guid);
                            cells[2].Value = "Incompatible Driver";
                            cells[3].Value = "N/A";

                            cells[0].ToolTipText = "An incompatible driver is installed on this device.";

                            foreach (DataGridViewTextBoxCell cell in cells)
                            {
                                cell.ToolTipText = errorMessage;
                            }

                            newCamera.Cells.AddRange(cells);
                            badCameraList.Add(newCamera);
                        }
                    }
                }
                catch (FC2Exception ex)
                {
                    BasePage.ShowErrorMessageDialog("Error populating camera list.", ex);
                    continue;
                }
            }


            foreach (KeyValuePair <uint, CameraInfo> pair in discoveredCameraInfo)
            {
                try
                {
                    CameraInfo info = pair.Value;

                    m_badCameraInfo.Add(info.serialNumber.ToString(), info);

                    DataGridViewRow newCamera = new DataGridViewRow();

                    newCamera.DefaultCellStyle.BackColor = IP_PROBLEM;
                    DataGridViewTextBoxCell[] cells = new DataGridViewTextBoxCell[4];
                    for (int ci = 0; ci < cells.Length; ci++)
                    {
                        cells[ci] = new DataGridViewTextBoxCell();
                    }

                    cells[0].Value = info.serialNumber.ToString();
                    cells[1].Value = info.modelName;
                    cells[2].Value = "GigE";
                    cells[3].Value = info.ipAddress.Equals(new IPAddress(0)) ? "N/A" : info.ipAddress.ToString();

                    cells[0].ToolTipText = "This camera is discoverable but can not be controlled";

                    foreach (DataGridViewTextBoxCell cell in cells)
                    {
                        if (m_GigEEnumerationIsDisabled)
                        {
                            cell.ToolTipText = "This camera cannot be enumerated by FlyCapture2 because GigE camera enumeration \n" +
                                               "has been disabled)";
                        }
                        else
                        {
                            cell.ToolTipText = "Camera IP settings or local interface is mis-configured. Use \"Force IP\" to \n" +
                                               "correct it";
                        }
                    }

                    newCamera.Cells.AddRange(cells);
                    badCameraList.Add(newCamera);
                }
                catch (InvalidOperationException ex)
                {
                    Debug.WriteLine("Error appending new row to camera list.");
                    Debug.WriteLine(ex.Message);
                    Debug.WriteLine(ex.StackTrace);
                    continue;
                }
                catch (ArgumentNullException ex)
                {
                    Debug.WriteLine("The cell in camera list contains null value.");
                    Debug.WriteLine(ex.Message);
                    Debug.WriteLine(ex.StackTrace);
                    continue;
                }
            }

            m_cameraDataGridView.Rows.Clear();
            m_cameraListLabel.Text = string.Format("Camera List ({0} cameras detected)", (goodCameraList.Count + badCameraList.Count));
            for (int i = 0; i < goodCameraList.Count; i++)
            {
                try
                {
                    m_cameraDataGridView.Rows.Add(goodCameraList[i]);
                }
                catch (InvalidOperationException ex)
                {
                    Debug.WriteLine("Error adding camera list to the view.");
                    Debug.WriteLine(ex.Message);
                    Debug.WriteLine(ex.StackTrace);
                }
                catch (ArgumentNullException ex)
                {
                    Debug.WriteLine("The camera list contains null value.");
                    Debug.WriteLine(ex.Message);
                    Debug.WriteLine(ex.StackTrace);
                }
                catch (ArgumentException ex)
                {
                    Debug.WriteLine("The camera list contains invalid value.");
                    Debug.WriteLine(ex.Message);
                    Debug.WriteLine(ex.StackTrace);
                }
            }

            for (int i = 0; i < badCameraList.Count; i++)
            {
                try
                {
                    m_cameraDataGridView.Rows.Add(badCameraList[i]);
                }
                catch (InvalidOperationException ex)
                {
                    Debug.WriteLine("Error adding camera list to the view.");
                    Debug.WriteLine(ex.Message);
                    Debug.WriteLine(ex.StackTrace);
                }
                catch (ArgumentNullException ex)
                {
                    Debug.WriteLine("The camera list contains null value.");
                    Debug.WriteLine(ex.Message);
                    Debug.WriteLine(ex.StackTrace);
                }
                catch (ArgumentException ex)
                {
                    Debug.WriteLine("The camera list contains invalid value.");
                    Debug.WriteLine(ex.Message);
                    Debug.WriteLine(ex.StackTrace);
                }
            }

            if (m_cameraDataGridView.Rows.Count > 0)
            {
                // display first camera information
                DisplayCameraInformationFromRowIndex(0);
            }
            else
            {
                // Nothing need to display
                m_cameraInfoPanel.ClearInformation();
            }
        }
        // A timer used to sample the IMU during the intervals betweem frame captures
        //private System.Timers.Timer IMUSamplingTimer;
        public Flea3Recorder(GPSReceiver gpsReceiver, IMUCommsDevice imu)
        {
            int i;

            IMUcomms = imu;

            // 1. creating the camera object
            Cam = new ManagedCamera();
            // 2. creating the bus manager in order to handle (potentially)
            // multiple cameras
            BusMgr = new ManagedBusManager();

            // 3. retrieving the List of all camera ids connected to the bus
            CamIDs = new List<ManagedPGRGuid>();
            int camCount = (int)BusMgr.GetNumOfCameras();
            for (i = 0; i < camCount; i++)
            {
                ManagedPGRGuid guid = BusMgr.GetCameraFromIndex((uint)i);
                CamIDs.Add(guid);
            }

            // 4. assigning values to properties
            GpsReceiver = gpsReceiver;

            // 5. init flags
            RecordingThreadActive = false;

            RecordToFile = false;

            OutOfRecordingThread = OutOfDumpingThread = true;

            // 6. Creating the Frame data queue
            FrameQueue = new ManagedImageRollingBuffer(MAX_FRAMEQUEUE_LEN);
        }
Ejemplo n.º 41
0
        private void DisplayCameraInformationFromRowIndex(int rowIndex)
        {
            if (rowIndex == -1)
            {
                // Nothing is selected
                return;
            }

            bool   badCamera   = false;
            string cellContent = m_cameraDataGridView.Rows[rowIndex].Cells[0].Value.ToString();

            if (m_badCameraInfo.ContainsKey(cellContent))
            {
                badCamera = true;
            }

            if (m_cameraDataGridView.Rows[rowIndex].DefaultCellStyle.BackColor == IMCOMPATIBLE_DRIVER)
            {
                badCamera = true;
            }

            if (badCamera)
            {
                try
                {
                    CameraInfo camInfo;
                    m_badCameraInfo.TryGetValue(m_cameraDataGridView.Rows[rowIndex].Cells[0].Value.ToString(), out camInfo);

                    if (camInfo != null)
                    {
                        ShowGigEInformation();
                        m_cameraInfoPanel.Camera = null;
                        m_cameraInfoPanel.UpdateBadCameraInformation(camInfo);

                        m_cameraInfoDisplayPanel.Height = m_cameraInfoPanel.MinimumSize.Height;
                        m_cameraInfoDisplayPanel.Width  = m_cameraInfoPanel.MinimumSize.Width;

                        m_gigEInfoPanel.Camera = null;
                        m_gigEInfoPanel.UpdateBadGigECameraInformation(camInfo);
                        m_gigeInfoDisplayPanel.Height = m_gigEInfoPanel.MinimumSize.Height;
                        m_gigeInfoDisplayPanel.Width  = m_gigEInfoPanel.MinimumSize.Width;
                        m_needShrinkWindowHeight      = true;

                        AdjustWindowMinimumSize();
                    }
                    else
                    {
                        camInfo = new CameraInfo();
                        camInfo.interfaceType   = InterfaceType.Unknown;
                        camInfo.maximumBusSpeed = BusSpeed.Unknown;
                        camInfo.pcieBusSpeed    = PCIeBusSpeed.Unknown;
                        HideGigEInformation();
                        m_cameraInfoPanel.Camera = null;
                        m_cameraInfoPanel.UpdateBadCameraInformation(camInfo);

                        m_cameraInfoDisplayPanel.Height = m_cameraInfoPanel.MinimumSize.Height;
                        m_cameraInfoDisplayPanel.Width  = m_cameraInfoPanel.MinimumSize.Width;

                        m_needShrinkWindowHeight = true;

                        AdjustWindowMinimumSize();
                    }
                    ////if window shrink is needed and current interface
                    ////is not GigE then restore the window height (for bug 14937)
                    //this.Height = this.MinimumSize.Height;
                    //m_needShrinkWindowHeight = false;
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.ToString());
                }
            }
            else
            {
                ManagedPGRGuid guid;
                if (GetPGRGuidFromRowIndex(rowIndex, out guid) == false)
                {
                    MessageBox.Show("Error getting camera information", "FlyCapture2", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    m_cameraInfoPanel.ClearInformation();
                    return;
                }

                InterfaceType     ifType = m_busMgr.GetInterfaceTypeFromGuid(guid);
                ManagedCameraBase camera;
                if (ifType == InterfaceType.GigE)
                {
                    camera = new ManagedGigECamera();
                }
                else
                {
                    camera = new ManagedCamera();
                }

                using (camera)
                {
                    if (ifType == InterfaceType.GigE)
                    {
                        ShowGigEInformation();
                    }
                    else
                    {
                        HideGigEInformation();
                    }

                    try
                    {
                        camera.Connect(guid);
                    }
                    catch (FC2Exception ex)
                    {
                        Debug.WriteLine("Unable to connect to camera.");
                        Debug.WriteLine(ex.Message);
                        return;
                    }

                    // cheeck for filter driver compatibility
                    bool   compatibleFilterDriverInstalled = true;
                    string errorMessage = string.Empty;

                    if (ifType == InterfaceType.GigE)
                    {
                        try
                        {
                            ManagedUtilities.CheckDriver(guid);
                        }
                        catch (FC2Exception ex)
                        {
                            compatibleFilterDriverInstalled = false;
                            errorMessage = ex.Message;
                        }
                    }

                    CameraInfo camInfo;

                    try
                    {
                        camInfo = camera.GetCameraInfo();
                    }
                    catch (FC2Exception ex)
                    {
                        Debug.WriteLine("Unable to get Camera Info. {0}", ex.Message);
                        return;
                    }


                    m_cameraInfoPanel.Camera = camera;
                    m_cameraInfoPanel.UpdateCameraInformation(camInfo);

                    m_cameraInfoDisplayPanel.Height = m_cameraInfoPanel.MinimumSize.Height;
                    m_cameraInfoDisplayPanel.Width  = m_cameraInfoPanel.MinimumSize.Width;

                    if (ifType == InterfaceType.GigE)
                    {
                        m_gigEInfoPanel.Camera = camera;
                        m_gigEInfoPanel.UpdateGigECameraInformation(camInfo);
                        m_gigeInfoDisplayPanel.Height = m_gigEInfoPanel.MinimumSize.Height;
                        m_gigeInfoDisplayPanel.Width  = m_gigEInfoPanel.MinimumSize.Width;
                        m_needShrinkWindowHeight      = true;

                        if (!compatibleFilterDriverInstalled)
                        {
                            m_cameraInfoPanel.SetDriverCompatibilityStatus(compatibleFilterDriverInstalled, errorMessage);
                        }
                    }
                }
                AdjustWindowMinimumSize();
                if (m_needShrinkWindowHeight == true &&
                    ifType != InterfaceType.GigE)
                {
                    //if window shrink is needed and current interface
                    //is not GigE then restore the window height (for bug 14937)
                    this.Height = this.MinimumSize.Height;
                    m_needShrinkWindowHeight = false;
                }
            }
        }
Ejemplo n.º 42
0
        void RunSingleCamera(ManagedPGRGuid guid)
        {
            const int k_numImages = 10;

            ManagedCamera cam = new ManagedCamera();

            // Connect to a camera
            cam.Connect(guid);

            // Get the camera information
            CameraInfo camInfo = cam.GetCameraInfo();

            PrintCameraInfo(camInfo);

            // Get embedded image info from camera
            EmbeddedImageInfo embeddedInfo = cam.GetEmbeddedImageInfo();

            // Enable timestamp collection
            if (embeddedInfo.timestamp.available == true)
            {
                embeddedInfo.timestamp.onOff = true;
            }

            // Set embedded image info to camera
            cam.SetEmbeddedImageInfo(embeddedInfo);

            // Start capturing images
            cam.StartCapture();

            ManagedImage rawImage = new ManagedImage();
            for (int imageCnt = 0; imageCnt < k_numImages; imageCnt++)
            {
                // Retrieve an image
                cam.RetrieveBuffer(rawImage);

                // Get the timestamp
                TimeStamp timeStamp = rawImage.timeStamp;

                Console.WriteLine(
                   "Grabbed image {0} - {1} {2} {3}",
                   imageCnt,
                   timeStamp.cycleSeconds,
                   timeStamp.cycleCount,
               timeStamp.cycleOffset);

                // Create a converted image
                ManagedImage convertedImage = new ManagedImage();

                // Convert the raw image
                rawImage.Convert(PixelFormat.PixelFormatBgr, convertedImage);

                // Create a unique filename
                string filename = String.Format(
                   "FlyCapture2Test_CSharp-{0}-{1}.bmp",
                   camInfo.serialNumber,
                   imageCnt);

                // Get the Bitmap object. Bitmaps are only valid if the
                // pixel format of the ManagedImage is RGB or RGBU.
                System.Drawing.Bitmap bitmap = convertedImage.bitmap;

                // Save the image
                bitmap.Save(filename);
            }

            // Stop capturing images
            cam.StopCapture();

            // Disconnect the camera
            cam.Disconnect();
        }