Esempio n. 1
0
        /// <summary>
        /// Handle camera removal
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void axFlyCapActiveXControl_CameraRemoval(object sender, AxActiveFlyCapLib._IActiveFlyCapControlEvents_CameraRemovalEvent e)
        {
            Debug.WriteLine("Camera removal #" + e.lSerialNum.ToString());

            if (this.InvokeRequired)
            {
                this.BeginInvoke(new MethodInvoker(delegate()
                {
                    try
                    {
                        axActiveFlyCapControl.Start = 0;

                        axActiveFlyCapControl.BusEnumerateCameras();

                        if (axActiveFlyCapControl.ShowCameraSelectionModal() == 1)
                        {
                            // Start the selected camera
                            m_cameraInfo = axActiveFlyCapControl.GetCameraInfo();
                            axActiveFlyCapControl.Start = 1;
                            updateStartStopButton();
                            populateCameraInfo();
                        }
                    }
                    catch (System.Exception eException)
                    {
                        Debug.WriteLine(eException.ToString());
                    }
                }));
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Form constructor
        /// </summary>
        public ActiveFlyCapForm()
        {
            InitializeComponent();

            m_grabLoopExitEvent = new AutoResetEvent(false);

            object camList = axActiveFlyCapControl.BusEnumerateCameras();

            if (camList != null)
            {
                Array arCamList = (Array)camList;
                Debug.WriteLine("Enumerating cameras...");
                foreach (string s in arCamList)
                {
                    Debug.WriteLine(s);
                }
                Debug.WriteLine("Done");

                if (axActiveFlyCapControl.ShowCameraSelectionModal() == 1)
                {
                    // Get camera info
                    m_cameraInfo = axActiveFlyCapControl.GetCameraInfo();

                    // Change the following line to determine which grab mode to use
                    axActiveFlyCapControl.SetGrabMode(ActiveFlyCapLib.GrabMode.LockNext);

                    // Start the selected camera
                    axActiveFlyCapControl.Start = 1;

                    if (axActiveFlyCapControl.GetGrabMode() != ActiveFlyCapLib.GrabMode.FreeRunning)
                    {
                        // Create a grab thread
                        m_workerThread = new Thread(new ThreadStart(this.GrabLoop));
                        m_workerThread.Start();
                    }

                    updateStartStopButton();

                    populateCameraInfo();
                }
                else
                {
                    // TODO: Disable the GUI
                }
            }
            else
            {
                // TODO: Disable the GUI
            }
        }
Esempio n. 3
0
        /// <summary>
        /// New camera handler
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void newCameraToolStripMenuItem_Click(object sender, EventArgs e)
        {
            axActiveFlyCapControl.Start = 0;

            object camList = axActiveFlyCapControl.BusEnumerateCameras();

            if (camList != null)
            {
                axActiveFlyCapControl.ShowCameraSelectionModal();

                m_cameraInfo = axActiveFlyCapControl.GetCameraInfo();
                axActiveFlyCapControl.Start = 1;

                updateStartStopButton();
                populateCameraInfo();
            }
            else
            {
                // Disable GUI
            }
        }
Esempio n. 4
0
        public Form1()
        {
            InitializeComponent();
            frm2.Show();
            frm2.setText("This is a title");

            outputBox.AppendText("Number of cameras connected is:" + Convert.ToString(flyCap1.GetNumOfCameras()) + "\n");
            folderBox.Text = folderName;

            var diff_pal = diff_bitmap.Palette;
            var sum_pal  = sum_bitmap.Palette;

            for (int i = 0; i < 256; i++)
            {
                diff_pal.Entries[i] = System.Drawing.Color.FromArgb(255, i, i, i);
                sum_pal.Entries[i]  = System.Drawing.Color.FromArgb(255, i, i, i);
            }//This code sets the palette for each bitmap accordingly.

            diff_bitmap.Palette = diff_pal;
            sum_bitmap.Palette  = sum_pal;


            if (flyCap1.GetNumOfCameras() > 0)
            {
                try
                {
                    object   cameralist       = flyCap1.GetCameraList();
                    object[] cameralist_array = (object[])cameralist;
                    foreach (object element in cameralist_array)
                    {
                        outputBox.AppendText("Camera list: " + element.ToString() + "\n");
                    }

                    flyCap1.Camera = 0;

                    ActiveFlyCapLib.CameraInfo caminfo = flyCap1.GetCameraInfo();
                    outputBox.AppendText("Camera serial number: " + caminfo.serialNumber.ToString() + "\n");
                    outputBox.AppendText("Camera sensor resolution: " + caminfo.sensorResolution + "\n");

                    flyCap1.SetGrabMode(ActiveFlyCapLib.GrabMode.FreeRunning);
                    outputBox.AppendText("Grab mode set to: " + flyCap1.GetGrabMode().ToString() + "\n");
                    flyCap1.videoMode = ActiveFlyCapLib.DCAMVideoMode.VideoMode_640_480_Y8;
                    outputBox.AppendText("Video mode set to: " + flyCap1.videoMode.ToString() + "\n");
                    flyCap1.AutoResize = 1; //resizes image to fit the control.
                    if (flyCap1.AutoResize == 1)
                    {
                        outputBox.AppendText("Autoresize enabled \n");
                    }
                    else
                    {
                        outputBox.AppendText("Autoresize disabled \n");
                    }
                }
                catch
                {
                    outputBox.AppendText("Problem setting grab mode or video mode \n");
                }

                try
                {
                    ActiveFlyCapLib.CameraProperty camprop = new ActiveFlyCapLib.CameraProperty();
                    camprop.present        = 1;
                    camprop.absControl     = 1;
                    camprop.onePush        = 0;
                    camprop.onOff          = 1;
                    camprop.autoManualMode = 0;
                    camprop.absValue       = (float)setFPSUpDown.Value;
                    flyCap1.SetProperty(ActiveFlyCapLib.CameraPropertyType.FrameRate, ref camprop);
                    outputBox.AppendText("Camera frame rate set to " + setFPSUpDown.Value.ToString() + " Hz\n");
                }
                catch
                {
                    MessageBox.Show("Error setting camera FPS");
                }

                try
                {
                    ActiveFlyCapLib.CameraProperty camprop = new ActiveFlyCapLib.CameraProperty();
                    camprop.present        = 1;
                    camprop.onOff          = 1;
                    camprop.absControl     = 1;
                    camprop.onePush        = 0;
                    camprop.autoManualMode = 0;
                    camprop.absValue       = (float)shutterUpDown.Value;
                    flyCap1.SetProperty(ActiveFlyCapLib.CameraPropertyType.Shutter, ref camprop);
                    outputBox.AppendText("Camera shutter set to " + shutterUpDown.Value.ToString() + " ms\n");
                }
                catch
                {
                    MessageBox.Show("Error setting camera shutter");
                }

                try
                {
                    ActiveFlyCapLib.CameraProperty camprop = new ActiveFlyCapLib.CameraProperty();
                    camprop.present        = 1;
                    camprop.onOff          = 1;
                    camprop.absControl     = 1; //control with value in abs value CSR. the value in the Value field is read-only.
                    camprop.onePush        = 0;
                    camprop.autoManualMode = 0;
                    camprop.absValue       = (float)gainNumericUpDown.Value;
                    flyCap1.SetProperty(ActiveFlyCapLib.CameraPropertyType.Gain, ref camprop);
                    outputBox.AppendText("Camera gain set to " + gainNumericUpDown.Value.ToString() + " dB\n");
                }
                catch
                {
                    MessageBox.Show("Error setting gain");
                }

                double trackbarpercentage = ((float)gainNumericUpDown.Value + 2.81) / (24.00 + 2.81) * 100.00; //min -2.81, max 24
                gainTrackBar.Value = (int)trackbarpercentage;                                                  //updates the gain trackbar percentage approximately

                try
                {
                    ActiveFlyCapLib.CameraProperty camprop = new ActiveFlyCapLib.CameraProperty();
                    camprop.present        = 1;
                    camprop.onOff          = 1;
                    camprop.absControl     = 1; //control with value in abs value CSR. the value in the Value field is read-only.
                    camprop.onePush        = 0;
                    camprop.autoManualMode = 0;
                    camprop.absValue       = (float)gammaNumericUpDown.Value;
                    flyCap1.SetProperty(ActiveFlyCapLib.CameraPropertyType.Gamma, ref camprop);
                    outputBox.AppendText("Camera gamma set to " + gammaNumericUpDown.Value.ToString() + "\n");
                }
                catch
                {
                    MessageBox.Show("Error setting gamma");
                }

                trackbarpercentage  = ((float)gammaNumericUpDown.Value - 0.50) / (4.00 - 0.50) * 100.00; //min 0.5, max 4
                gammaTrackBar.Value = (int)trackbarpercentage;                                           //updates the gamma trackbar percentage approximately

                try
                {
                    ActiveFlyCapLib.CameraProperty camprop = new ActiveFlyCapLib.CameraProperty();
                    camprop.present        = 1;
                    camprop.onOff          = 1;
                    camprop.absControl     = 0; //no absolute value for sharpness
                    camprop.onePush        = 0;
                    camprop.autoManualMode = 0;
                    camprop.valueA         = (uint)sharpnessNumericUpDown.Value;
                    flyCap1.SetProperty(ActiveFlyCapLib.CameraPropertyType.Sharpness, ref camprop);
                    outputBox.AppendText("Camera sharpness set to " + sharpnessNumericUpDown.Value.ToString() + "\n");
                }
                catch
                {
                    MessageBox.Show("Error setting sharpness");
                }

                trackbarpercentage      = ((float)sharpnessNumericUpDown.Value - 0.00) / (4095.00 - 0.00) * 100.00; //min 0, max 4095
                sharpnessTrackBar.Value = (int)trackbarpercentage;                                                  //updates the sharpness trackbar percentage approximately

                bw.WorkerSupportsCancellation = true;
                bw.WorkerReportsProgress      = true;

                //add the event handlers to the Backgroundworker's instance events
                bw.DoWork             += new DoWorkEventHandler(bw_DoWork);
                bw.ProgressChanged    += new ProgressChangedEventHandler(bw_ProgressChanged);
                bw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bw_RunWorkerCompleted);

                flyCap1.Start = 1;
            }
        }