private void m_AsyncSpeedCombo_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (!m_initializing && m_speedControlPanel.Visible)
     {
         try
         {
             if (m_camera.IsConnected() && m_camInfo.interfaceType == InterfaceType.Ieee1394 && m_AsyncSpeedCombo.Items.Count > 0) //Async speed can only be changed for Firewire
             {
                 BusSpeed  asyncSpeed = (BusSpeed)Enum.Parse(typeof(BusSpeed), m_AsyncSpeedCombo.SelectedItem.ToString(), true);
                 FC2Config config     = new FC2Config();
                 config = m_camera.GetConfiguration();
                 config.asyncBusSpeed = asyncSpeed;
                 m_camera.SetConfiguration(config);
                 OnISOSpeedChanged(EventArgs.Empty);
                 //config = m_camera.GetConfiguration(); Hal can not retrieve Async Speed at the moment
             }
         }
         catch (Exception ex)
         {
             string error = string.Format("Failed to set asynchronous bus speed: {0}", ex.Message);
             Debug.WriteLine(error);
             MessageBox.Show(error, "FlyCapture2", MessageBoxButtons.OK, MessageBoxIcon.Error);
             return;
         }
     }
 }
Beispiel #2
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;
            }
        }
 private void m_IsochSpeedCombo_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (!m_initializing && m_speedControlPanel.Visible)
     {
         try
         {
             if (m_camera.IsConnected() && m_camInfo.interfaceType == InterfaceType.Ieee1394 && m_IsochSpeedCombo.Items.Count > 0) //Isoch speed can only be changed for Firewire
             {
                 BusSpeed isochSpeed = (BusSpeed)Enum.Parse(typeof(BusSpeed), m_IsochSpeedCombo.SelectedItem.ToString(), true);
                 if (m_camera.ReadRegister(0x614) == 0) // Make sure camera is not streaming while changing Isoch speed
                 {
                     FC2Config config = new FC2Config();
                     config = m_camera.GetConfiguration();
                     config.isochBusSpeed = isochSpeed;
                     m_camera.SetConfiguration(config);
                     config = m_camera.GetConfiguration();
                     if (config.isochBusSpeed != (BusSpeed)Enum.Parse(typeof(BusSpeed), m_IsochSpeedCombo.SelectedItem.ToString()))
                     {
                         MessageBox.Show("Could not set new Isoch Speed.", "FlyCapture2", MessageBoxButtons.OK, MessageBoxIcon.Error);
                     }
                     else
                     {
                         OnISOSpeedChanged(EventArgs.Empty);
                     }
                 }
             }
         }
         catch (Exception ex)
         {
             string error = string.Format("Failed to set isochronous bus speed: {0}", ex.Message);
             Debug.WriteLine(error);
             MessageBox.Show(error, "FlyCapture2", MessageBoxButtons.OK, MessageBoxIcon.Error);
             return;
         }
     }
 }
Beispiel #4
0
        static void Main(string[] args)
        {
            PrintBuildInfo();

            const int NumImages          = 10;
            bool      useSoftwareTrigger = true;

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

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

            // Finish if there are no cameras
            if (numCameras == 0)
            {
                Console.WriteLine("Not enough cameras!");
                Console.WriteLine("Press Enter to exit...");
                Console.ReadLine();
                return;
            }

            ManagedPGRGuid guid = busMgr.GetCameraFromIndex(0);

            ManagedCamera cam = new ManagedCamera();

            cam.Connect(guid);

            // Power on the camera
            const uint CameraPower      = 0x610;
            const uint CameraPowerValue = 0x80000000;

            cam.WriteRegister(CameraPower, CameraPowerValue);

            const Int32 MillisecondsToSleep  = 100;
            uint        cameraPowerValueRead = 0;

            // Wait for camera to complete power-up
            do
            {
                System.Threading.Thread.Sleep(MillisecondsToSleep);

                cameraPowerValueRead = cam.ReadRegister(CameraPower);
            }while ((cameraPowerValueRead & CameraPowerValue) == 0);

            // 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!");
                    Console.WriteLine("Press enter to exit...");
                    Console.ReadLine();
                    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)
            {
                Console.WriteLine("Poll for trigger read failed!");
                Console.WriteLine("Press enter to exit...");
                Console.ReadLine();
                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");
                    Console.WriteLine("Press enter to exit...");
                    Console.ReadLine();
                    return;
                }
            }
            else
            {
                Console.WriteLine("Trigger the camera by sending a trigger pulse to GPIO%d.\n",
                                  triggerMode.source);
            }

            ManagedImage rawImage = new ManagedImage();

            for (int iImageCount = 0; iImageCount < 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!");
                        Console.WriteLine("Press enter to exit...");
                        Console.ReadLine();
                        return;
                    }
                }

                try
                {
                    // Retrieve an image
                    cam.RetrieveBuffer(rawImage);
                }
                catch (FC2Exception ex)
                {
                    Console.WriteLine("Error retrieving buffer : {0}", ex.Message);
                    continue;
                }

                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 enter to exit...");
            Console.ReadLine();
        }
        ///<summary>
        ///Take a picture and save it in file name
        /// </summary>
        /// <param name="fileName">File name where the picture is going to be saved> Must be a correct path</param>
        /// <exception cref="SoftwareTriggerNotSupportedException">Thrown when the camera doesn't support software triggering.</exception>
        /// <exception cref="ExternalTriggerNotSupportedException">Thrown when the camera doesn't support external triggering.</exception>
        /// <exception cref="TriggerFailedException">Thrown when the triggering had failed and the picture hasn't been taken.</exception>
        public void Snap(string fileName) // To thing of a possible separation to avoid setting  everything all the time
        {
            // Power on the camera
            const uint CameraPower      = 0x610;
            const uint CameraPowerValue = 0x80000000;

            cam.WriteRegister(CameraPower, CameraPowerValue);

            const Int32 MillisecondsToSleep = 100;
            uint        cameraPowerValueRead;

            // Wait for camera to complete power-up
            do
            {
                System.Threading.Thread.Sleep(MillisecondsToSleep);

                cameraPowerValueRead = cam.ReadRegister(CameraPower);
            }while ((cameraPowerValueRead & CameraPowerValue) == 0);



            // 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;


            // A source of 7 means software trigger
            triggerMode.source = 7;



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



            // 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);

            #region Taking picture

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


            using (ManagedImage rawImage = new ManagedImage())
            {
                // Check that the trigger is ready
                bool retVal = PollForTriggerReady();

                // Fire software trigger
                bool retVal1 = FireSoftwareTrigger();
                if (!(retVal && retVal1))
                {
                    throw new TriggerFailedException();
                }

                try
                {
                    // Retrieve an image
                    cam.RetrieveBuffer(rawImage);

                    rawImage.Save(fileName);
                }
                catch (FC2Exception ex)
                {
                    Console.WriteLine("Error retrieving buffer : {0}", ex.Message);
                }
            }
            #endregion

            // Stop capturing images
            cam.StopCapture();

            // Turn off trigger mode
            triggerMode.onOff = false;
            cam.SetTriggerMode(triggerMode);
        }
Beispiel #6
0
        unsafe void RunSingleCamera(ManagedPGRGuid guid, string save_location, int numImages)
        {
            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);
            // Make a 300 Frame Buffer
            FC2Config bufferFrame = cam.GetConfiguration();

            bufferFrame.grabMode   = GrabMode.BufferFrames;
            bufferFrame.numBuffers = 300;
            cam.SetConfiguration(bufferFrame);
            // Start capturing images
            cam.StartCapture();
            // Create a raw image

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

            System.Drawing.Size framesize = new System.Drawing.Size(1888, 1888);
            CvInvoke.NamedWindow("Prey Capture" + save_location, NamedWindowType.Normal);
            VideoWriter camvid = new VideoWriter(save_location, 0, 60, framesize, false);

            for (int imageCnt = 0; imageCnt < numImages; imageCnt++)
            {
                // Retrieve an image
                cam.RetrieveBuffer(rawImage);
                // Get the timestamp
                TimeStamp timeStamp = rawImage.timeStamp;
                // Convert the raw image
                //      rawImage.Convert(PixelFormat.PixelFormatBgr, convertedImage); // m
                rawImage.Convert(PixelFormat.PixelFormatRaw8, convertedImage); // use raw8 for GH3s but flea3 can be color.
                int    rws   = (int)convertedImage.rows;
                int    cols  = (int)convertedImage.cols;
                IntPtr point = (IntPtr)convertedImage.data;

                Mat cvimage = new Mat(framesize, Emgu.CV.CvEnum.DepthType.Cv8U, 1, point, cols);
                camvid.Write(cvimage);
                if (imageCnt % 200 == 0)
                {
                    CvInvoke.Imshow("Prey Capture" + save_location, cvimage);
                    CvInvoke.WaitKey(1);
                    Console.WriteLine(imageCnt);
                }
            }
            // Stop capturing images
            cam.StopCapture();
            camvid.Dispose();
            // Disconnect the camera
            Console.WriteLine("Done Brah");
            cam.Disconnect();
            CvInvoke.DestroyAllWindows();
        }
Beispiel #7
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();
        }