Exemple #1
0
        private void gammaTrackBar_Scroll(object sender, EventArgs e)
        {
            int    trackbarpercentage = gammaTrackBar.Value;
            double gainvalue          = (double)trackbarpercentage / 100.00 * (4.00 - 0.50) + 0.50;

            gammaNumericUpDown.Value = (decimal)gainvalue;

            try
            {
                flyCap1.Start = 0;
                ActiveFlyCapLib.CameraProperty camprop = new ActiveFlyCapLib.CameraProperty();
                camprop.present        = 1;
                camprop.onOff          = 1;
                camprop.absControl     = 1;
                camprop.onePush        = 0;
                camprop.autoManualMode = 0;
                camprop.absValue       = (float)gammaNumericUpDown.Value;
                flyCap1.SetProperty(ActiveFlyCapLib.CameraPropertyType.Gamma, ref camprop);
                outputBox.AppendText("Camera gamma set to " + Convert.ToString(gammaNumericUpDown.Value) + "\n");
                flyCap1.Start = 1;
            }
            catch
            {
                MessageBox.Show("Error setting camera gamma");
            }
        }
Exemple #2
0
        private void gainNumericUpDown_ValueChanged(object sender, EventArgs e)
        {
            try
            {
                flyCap1.Start = 0;
                ActiveFlyCapLib.CameraProperty camprop = new ActiveFlyCapLib.CameraProperty();
                camprop.present        = 1;
                camprop.onOff          = 1;
                camprop.absControl     = 1;
                camprop.onePush        = 0;
                camprop.autoManualMode = 0;
                camprop.absValue       = (float)gainNumericUpDown.Value;
                flyCap1.SetProperty(ActiveFlyCapLib.CameraPropertyType.Gain, ref camprop);
                outputBox.AppendText("Camera gain set to " + Convert.ToString(gainNumericUpDown.Value) + " dB\n");
                flyCap1.Start = 1;
            }
            catch
            {
                MessageBox.Show("Error setting camera 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
        }
Exemple #3
0
        private void sharpnessNumericUpDown_ValueChanged(object sender, EventArgs e)
        {
            try
            {
                flyCap1.Start = 0;
                ActiveFlyCapLib.CameraProperty camprop = new ActiveFlyCapLib.CameraProperty();
                camprop.present        = 1;
                camprop.onOff          = 1;
                camprop.absControl     = 0;
                camprop.onePush        = 0;
                camprop.autoManualMode = 0;
                camprop.valueA         = (uint)sharpnessNumericUpDown.Value;
                flyCap1.SetProperty(ActiveFlyCapLib.CameraPropertyType.Sharpness, ref camprop);
                outputBox.AppendText("Camera sharpness set to " + Convert.ToString(sharpnessNumericUpDown.Value) + "\n");
                flyCap1.Start = 1;
            }
            catch
            {
                MessageBox.Show("Error setting camera sharpness");
            }

            double 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
        }
Exemple #4
0
        private void startButton_Click(object sender, EventArgs e)
        {
            try
            {
                flyCap1.Start = 0;
                flyCap1.SetGrabMode(ActiveFlyCapLib.GrabMode.FreeRunning);

                ActiveFlyCapLib.CameraProperty camprop = new ActiveFlyCapLib.CameraProperty();
                camprop.present        = 1;
                camprop.onOff          = 0;
                camprop.absControl     = 1;
                camprop.onePush        = 0;
                camprop.autoManualMode = 0;
                flyCap1.SetProperty(ActiveFlyCapLib.CameraPropertyType.AutoExposure, ref camprop); //no auto exposure
                flyCap1.SetProperty(ActiveFlyCapLib.CameraPropertyType.Brightness, ref camprop);   //no brightness

                //camprop.onOff = 1;
                //camprop.onePush = 1;

                //flyCap1.SetProperty(ActiveFlyCapLib.CameraPropertyType.Gain, ref camprop); //onepush gain
                //flyCap1.SetProperty(ActiveFlyCapLib.CameraPropertyType.Gamma, ref camprop); //onepush gamma
                //flyCap1.SetProperty(ActiveFlyCapLib.CameraPropertyType.Hue, ref camprop); //onepush hue
                //flyCap1.SetProperty(ActiveFlyCapLib.CameraPropertyType.Iris, ref camprop); //onepush iris
                //flyCap1.SetProperty(ActiveFlyCapLib.CameraPropertyType.Saturation, ref camprop); //onepush saturation
                //flyCap1.SetProperty(ActiveFlyCapLib.CameraPropertyType.WhiteBalance, ref camprop); //onepush whitebalance

                flyCap1.Start   = 1; //start grabbing images. this will not draw any image to screen.
                flyCap1.Display = 1; //draws all incoming images onto the control.
            }
            catch
            {
                MessageBox.Show("Some error has occurred in starting the camera, displaying the video, allowing it to resize, and/or getting the frame rate");
            }
        }
Exemple #5
0
        private void sharpnessTrackBar_Scroll(object sender, EventArgs e)
        {
            int    trackbarpercentage = sharpnessTrackBar.Value;
            double gainvalue          = (double)trackbarpercentage / 100.00 * (4095.00 - 0.00) + 0.00;

            sharpnessNumericUpDown.Value = (decimal)gainvalue;

            try
            {
                flyCap1.Start = 0;
                ActiveFlyCapLib.CameraProperty camprop = new ActiveFlyCapLib.CameraProperty();
                camprop.present        = 1;
                camprop.onOff          = 1;
                camprop.absControl     = 0;
                camprop.onePush        = 0;
                camprop.autoManualMode = 0;
                camprop.valueA         = (uint)sharpnessNumericUpDown.Value;
                flyCap1.SetProperty(ActiveFlyCapLib.CameraPropertyType.Sharpness, ref camprop);
                outputBox.AppendText("Camera sharpness set to " + Convert.ToString(sharpnessNumericUpDown.Value) + "\n");
                flyCap1.Start = 1;
            }
            catch
            {
                MessageBox.Show("Error setting camera sharpness");
            }
        }
Exemple #6
0
 private void shutterUpDown_ValueChanged(object sender, EventArgs e)
 {
     try
     {
         flyCap1.Start = 0;
         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 " + Convert.ToString(shutterUpDown.Value) + " ms\n");
         flyCap1.Start = 1;
     }
     catch
     {
         MessageBox.Show("Error setting camera shutter");
     }
 }
Exemple #7
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;
            }
        }
Exemple #8
0
        private void bw_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker worker = sender as BackgroundWorker;

            List <object> genericlist = e.Argument as List <object>;

            AxActiveFlyCapLib.AxActiveFlyCapControl flycap2 = genericlist[0] as AxActiveFlyCapLib.AxActiveFlyCapControl;

            String pathString2 = genericlist[1] as String;

            float FPSvalue = (float)genericlist[2];

            flycap2.Start = 0;
            ActiveFlyCapLib.TriggerStruct my_triggers = new ActiveFlyCapLib.TriggerStruct();

            if (trigger_type == 0)
            {
                my_triggers.isOnOff = 0;
                outputBox.AppendText("No triggering selected.\n");
            }

            else if (trigger_type == 1)
            {
                my_triggers.isOnOff = 1;
                my_triggers.source  = 7; //For software triggering
                my_triggers.mode    = 0; //This is for classical triggering.
                outputBox.AppendText("Software triggering selected.\n");
                flycap2.SetTrigger(ref my_triggers);
            }

            else if (trigger_type == 2)
            {
                //use registers to set this
                const uint k_triggerVal = 0xC2000000; //presence_inq = 1, abs_control = 1, on_off = 1, trigger_polarity = 0, trigger_source = 0, trigger_mode = 0

                flycap2.WriteRegister(k_triggerMode, k_triggerVal);

                outputBox.AppendText("Hardware triggering selected.\n");
            }


            ActiveFlyCapLib.CameraProperty camprop = new ActiveFlyCapLib.CameraProperty();
            camprop.present        = 1;
            camprop.absControl     = 1;
            camprop.onePush        = 0;
            camprop.onOff          = 1;
            camprop.autoManualMode = 0;
            camprop.absValue       = FPSvalue;
            flycap2.SetProperty(ActiveFlyCapLib.CameraPropertyType.FrameRate, ref camprop);

            camprop.present        = 1;
            camprop.absControl     = 1;
            camprop.onePush        = 0;
            camprop.onOff          = 1;
            camprop.autoManualMode = 0;
            camprop.absValue       = (float)shutterUpDown.Value; //1ms exposure time should be ok?
            flycap2.SetProperty(ActiveFlyCapLib.CameraPropertyType.Shutter, ref camprop);


            /*float brightness_val = flycap2.GetProperty(ActiveFlyCapLib.CameraPropertyType.Brightness).absValue;
             * float gain_val = flycap2.GetProperty(ActiveFlyCapLib.CameraPropertyType.Gain).absValue;
             * float gamma_val = flycap2.GetProperty(ActiveFlyCapLib.CameraPropertyType.Gamma).absValue;
             * float hue_val = flycap2.GetProperty(ActiveFlyCapLib.CameraPropertyType.Hue).absValue;
             * float iris_val = flycap2.GetProperty(ActiveFlyCapLib.CameraPropertyType.Iris).absValue;
             * float saturation_val = flycap2.GetProperty(ActiveFlyCapLib.CameraPropertyType.Saturation).absValue;
             * float whitebalance_val = flycap2.GetProperty(ActiveFlyCapLib.CameraPropertyType.WhiteBalance).absValue;
             *
             * camprop.absValue = brightness_val;
             * flycap2.SetProperty(ActiveFlyCapLib.CameraPropertyType.Brightness, ref camprop);
             *
             * camprop.absValue = gain_val;
             * flycap2.SetProperty(ActiveFlyCapLib.CameraPropertyType.Gain, ref camprop);
             *
             * camprop.absValue = gamma_val;
             * flycap2.SetProperty(ActiveFlyCapLib.CameraPropertyType.Gamma, ref camprop);
             *
             * camprop.absValue = hue_val;
             * flycap2.SetProperty(ActiveFlyCapLib.CameraPropertyType.Hue, ref camprop);
             *
             * camprop.absValue = iris_val;
             * flycap2.SetProperty(ActiveFlyCapLib.CameraPropertyType.Iris, ref camprop);
             *
             * camprop.absValue = saturation_val;
             * flycap2.SetProperty(ActiveFlyCapLib.CameraPropertyType.Saturation, ref camprop);
             *
             * camprop.absValue = whitebalance_val;
             * flycap2.SetProperty(ActiveFlyCapLib.CameraPropertyType.WhiteBalance, ref camprop);*/


            flycap2.SetGrabMode(ActiveFlyCapLib.GrabMode.LockNext);
            flycap2.Start   = 1;
            flycap2.Display = 0;

            flycap2.ImageGrabbed += new EventHandler(flycap2_ImageGrabbed);

            time_limit = recording_duration;

            process_timer.Reset();
            process_timer.Start();

            while (process_timer.ElapsedMilliseconds <= time_limit || process_timer.ElapsedMilliseconds <= write_out_time)
            {
                if (worker.CancellationPending)
                {
                    flycap2.Start = 0;
                    e.Cancel      = true;
                    break;
                }

                else
                {
                    flycap2.GrabImage();

                    /*if (process_timer.ElapsedMilliseconds <= time_limit)
                     * {
                     *  worker.ReportProgress((int)(process_timer.ElapsedMilliseconds / (float)time_limit * 100));
                     * }*/

                    if (trigger_save_to_disc)
                    {
                        save_to_disc();
                        trigger_save_to_disc = false;
                    }

                    if (bitmaps_changed)
                    {
                        List <object> my_bitmaps = new List <object>();
                        my_bitmaps.Add(diff_bitmap);
                        my_bitmaps.Add(sum_bitmap);
                        worker.ReportProgress((int)(process_timer.ElapsedMilliseconds / (float)time_limit * 100), my_bitmaps);
                        bitmaps_changed = false;
                    }
                }
            }//end while

            if (!(Array.TrueForAll(diff_array, isZero)) || !(Array.TrueForAll(sum_array, isZero)))
            {
                write_out_time = 0; //we want ImageGrabbed event to write to disc the moment an even number_of_integrations is obtained.
                //We set write_out_time to zero so process_timer.ElapsedMilliseconds will always be greater than it.

                while (number_of_integrations % 2 != 0)
                {
                    flycap2.GrabImage();
                }
            }

            flycap2.Start = 0;
        } //end bw_DoWork