Ejemplo n.º 1
0
 private void Initialize()
 {
     ic                 = new ICImagingControl();
     ic.Device          = device;
     ic.DeviceFrameRate = frameRate;
     ic.DeviceLost     += new EventHandler <ICImagingControl.DeviceLostEventArgs>(icImagingControl1_DeviceLost);
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Connect to camera. Will fail if configuration file referred to invalid or disconnected camera
        /// </summary>
        /// <returns>True if initialization is successful</returns>
        public bool Initialize(ICImagingControl ic)
        {
            this.ic = ic;
            try
            {
                this.ic.LoadDeviceStateFromFile(this.configFile, true);
                this.Available = true;
            }
            catch (TIS.Imaging.ICException err)
            {
                System.Windows.Forms.MessageBox.Show("Error occurred while initializing WFOV camera. WFOV will be unavailable.\n\n" + err.ToString());
                Logger.Out(err.ToString());
                this.Available = false;
                return(false);
            }
            catch (System.IO.IOException err)
            {
                System.Windows.Forms.MessageBox.Show("WFOV configuration file missing or invalid.");
                Logger.Out(err.ToString());
                this.Available = false;
                return(false);
            }

            if (this.ic.DeviceValid)
            {
                this.ic.LivePrepare();
                this.VCDProp        = VCDSimpleModule.GetSimplePropertyContainer(this.ic.VCDPropertyItems);
                this.ic.DeviceLost += this.handleDisconnect;
                return(true);
            }
            System.Windows.Forms.MessageBox.Show("Failed to initialize WFOV camera");
            return(false);
        }
Ejemplo n.º 3
0
        public Task GrabBackgroundImage()
        {
            return(Task.Run(() =>
            {
                if (connected)
                {
                    Bitmap background;
                    using (ICImagingControl ic1 = new ICImagingControl())
                    {
                        ic1.Device = device;
                        ic1.DeviceFrameRate = frameRate;
                        ic1.MemorySnapImage(60000);
                        background = ic1.ImageActiveBuffer.Bitmap;
                    }
                    int h = background.Height;
                    int w = background.Width;

                    // Regular method
                    backgroundArray = ImageToByte(background).Skip(1078).ToArray();

                    //// Lockbits method
                    //Rectangle section = new Rectangle(0, 0, background.Width, h);
                    //BitmapData imageData = background.LockBits(section, ImageLockMode.ReadWrite, PixelFormat.Format8bppIndexed);
                    //IntPtr ptr = imageData.Scan0;
                    //int bytes = Math.Abs(imageData.Stride) * h;
                    //backgroundArray = new byte[bytes];
                    //Marshal.Copy(ptr, backgroundArray, 0, bytes);
                }
            }));
        }
Ejemplo n.º 4
0
        private void Load_ic_cam_easy(ICImagingControl ic)
        {
            ic.ScrollbarsEnabled = true;
            // ReadAllSettingsFromFile(false);
            //    TestAvailability(false);
            //bool liverun = ic.LiveVideoRunning;

            /* try
             * {
             *  AnalyseFormats();
             *  m_oldSink = New_SetSelectedCamera_SignalStream_Format();
             * }
             *
             */


            //try { IC_Control.ImageRingBufferSize = 2; } catch { }; //на всякий случай

            ic.LiveDisplayDefault = false; //если false, то позволяет изменения размеров окна

            //ic.LiveCaptureLastImage = true; // отображает и захватывает последний фрейм при LiveStop;

            //ic.LiveCaptureContinuous = true; //нужно для FormatAdaptation и граба фреймов


            //if(!ic.LiveVideoRunning) ic.LiveStart();

            mainViewModel.IsLive = true;
        }
        public ICImagingCamera(ICImagingControl camera, int index)
        {
            this.camera      = camera;
            this.cameraIndex = index;

            VCDProp = VCDSimpleModule.GetSimplePropertyContainer(camera.VCDPropertyItems);
        }
Ejemplo n.º 6
0
        private void InitICCaptureControl()
        {
            try
            {
                TIS.Imaging.LibrarySetup.SetLocalizationLanguage("ru");

                IC_Control = new ICImagingControl();

                //Setup render view

                Host.Child.Controls.Add(IC_Control);

                IC_Control.SendToBack();
                //IC_Control.OverlayBitmapAtPath[PathPositions.Display].Enable = true;
                Panel = Host.Child as System.Windows.Forms.Panel;
                Refresh_IC_BackColor();

                mainViewModel.ICImagingControl = IC_Control;

                mainViewModel.ICImagingControl.ScrollbarsEnabled  = true;
                mainViewModel.ICImagingControl.LiveDisplayDefault = false; //если false, то позволяет изменения размеров окна

                //mainViewModel.IsLive = true;
            }
            catch (Exception exc)
            {
                FLog.Log("ERROR:" + exc.Message);
            }
        }
Ejemplo n.º 7
0
        static void Main(string[] args)
        {
            // Declare and create IC Imaging Control
            ICImagingControl IC_Control = new ICImagingControl();

            // Open a camera. This must be connected already.
            IC_Control.Device = "DFK 37UX290";
            // Set a video format. Make sure, the camere supports that format.
            IC_Control.VideoFormat = "RGB32 (640x480)";
            // Set a frame rate.
            IC_Control.DeviceFrameRate = 30.0f;

            // Enable the trigger
            IC_Control.DeviceTrigger = true;
            // LiveCaptureContinuous must be set to true for saving all incoming images in memory
            // and call the ImageAvailable event.
            IC_Control.LiveCaptureContinuous = true;

            // Add the ImageAvailable event handeler
            IC_Control.ImageAvailable += new System.EventHandler <ICImagingControl.ImageAvailableEventArgs>(OnImageAvailable);

            // Start and stop the live video
            IC_Control.LiveStart();
            System.Threading.Thread.Sleep(1000);
            IC_Control.LiveStop();
        }
Ejemplo n.º 8
0
        private void Init_Properties(ICImagingControl ic)
        {
            vcdProp = new TIS.Imaging.VCDHelpers.VCDSimpleProperty(ic.VCDPropertyItems);
            var a = ic.VCDPropertyItems.CategoryMap;
            var b = ic.VCDPropertyItems.Count;
            var c = ic.VCDPropertyItems.get_Item(0);

            AbsValExp = (VCDAbsoluteValueProperty)ic.VCDPropertyItems.FindInterface(VCDIDs.VCDID_Exposure +
                                                                                    ":" + VCDIDs.VCDElement_Value + ":" + VCDIDs.VCDInterface_AbsoluteValue);
        }
Ejemplo n.º 9
0
        public Task GrabImage()
        {
            return(Task.Run(() =>
            {
                if (connected)
                {
                    Bitmap image;
                    using (ICImagingControl ic2 = new ICImagingControl())
                    {
                        ic2.Device = device;
                        ic2.DeviceFrameRate = frameRate;
                        ic2.MemorySnapImage(60000);
                        image = ic2.ImageActiveBuffer.Bitmap;
                    }
                    int h = image.Height;
                    int w = image.Width;

                    // Regular method
                    imageArray = ImageToByte(image).Skip(1078).ToArray();

                    // Lockbits method
                    //Rectangle section = new Rectangle(0, 0, image.Width, h);
                    //BitmapData imageData = image.LockBits(section, ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
                    //IntPtr ptr = imageData.Scan0;
                    //int bytes = Math.Abs(imageData.Stride) * h;
                    //imageArray = new byte[bytes];
                    //Marshal.Copy(ptr, imageArray, 0, bytes);

                    for (int i = 0; i < imageArray.Length; i++)
                    {
                        imageArray[i] = (byte)Math.Abs(imageArray[i] - backgroundArray[i]);
                    }
                    int j = 0;
                    intensityPlot = new double[w, h];
                    for (int y = 0; y < h; y++)
                    {
                        for (int x = 0; x < w; x++, j++)
                        {
                            if (x > 4 && x < w - 5 && y > 4 && y < h - 5)
                            {
                                intensityPlot[x, y] += (imageArray[j - 5] + imageArray[j - 4] + imageArray[j - 3] + imageArray[j - 2] + imageArray[j - 1] + imageArray[j] + imageArray[j + 1] + imageArray[j + 2] + imageArray[j + 3] + imageArray[j + 4] + imageArray[j + 5] +
                                                        imageArray[j - (5 * w)] + imageArray[j - (4 * w)] + imageArray[j - (3 * w)] + imageArray[j - (2 * w)] + imageArray[j - w] + imageArray[j + w] + imageArray[j + (2 * w)] + imageArray[j + (3 * w)] + imageArray[j + (4 * w)] + imageArray[j + (5 * w)]) / 21;
                            }
                            else
                            {
                                intensityPlot[x, y] += imageArray[j];
                            }
                        }
                    }

                    //Marshal.Copy(imageArray, 0, ptr, bytes);
                    //image.UnlockBits(imageData);
                }
            }));
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Constructor for Camera
        /// </summary>
        public Camera()
        {
            // create camera lock so only one thread can enter at a time
            _camLock = new object();

            // initialize variables
            subscribers = new List <CircularQueue <QueueElement> >();
            cam         = new ICImagingControl();
            isRunning   = false;
            lastTime    = -1;
            imageNumber = 0;
            cameraName  = "";
            exposure_s  = 0;
        }
Ejemplo n.º 11
0
        public CameraController(ICImagingControl ic, string _configFile)
        {
            camera     = ic;
            configFile = _configFile;

            camera.OverlayBitmap.Enable    = true;
            camera.OverlayBitmap.ColorMode = TIS.Imaging.OverlayColorModes.Color;
            try
            {
                camera.LoadDeviceStateFromFile(configFile, true); //attempts to load camera config file
                camera.DeviceTrigger = true;
                start();                                          // starts the live feed to the user interface
            }
            catch { } // do nothing if the above code produces errors
            camera.LiveDisplayDefault    = false;
            originalHeight               = camera.LiveDisplayHeight;
            originalWidth                = camera.LiveDisplayWidth;
            camera.LiveDisplayHeight     = camera.Height; // scales the camera view to the size of the window
            camera.LiveDisplayWidth      = camera.Width;
            camera.LiveCaptureLastImage  = false;
            camera.LiveCaptureContinuous = true;
        }
Ejemplo n.º 12
0
        public static HDMIInputInfo Query(ICImagingControl ic)
        {
            if (!ic.DeviceValid)
            {
                throw new InvalidOperationException("No device opened");
            }

            var sourceConnected = ic.VCDPropertyItems.Find <VCDSwitchProperty>(VCDID_SourceConnected, VCDGUIDs.VCDElement_Value);
            var signalDetected  = ic.VCDPropertyItems.Find <VCDSwitchProperty>(VCDGUIDs.VCDID_SignalDetected, VCDGUIDs.VCDElement_Value);
            var inputWidth      = ic.VCDPropertyItems.Find <VCDRangeProperty>(VCDGUIDs.VCDID_SignalDetected, VCDElement_InputWidth);
            var inputHeight     = ic.VCDPropertyItems.Find <VCDRangeProperty>(VCDGUIDs.VCDID_SignalDetected, VCDElement_InputHeight);
            var inputFp1ks      = ic.VCDPropertyItems.Find <VCDRangeProperty>(VCDGUIDs.VCDID_SignalDetected, VCDElement_InputFp1ks);
            var inputBitDepth   = ic.VCDPropertyItems.Find <VCDRangeProperty>(VCDGUIDs.VCDID_SignalDetected, VCDElement_InputBitDepth);

            return(new HDMIInputInfo
            {
                IsSourceConnected = sourceConnected.Switch,
                IsSignalDetected = signalDetected.Switch,
                InputWidth = inputWidth.Value,
                InputHeight = inputHeight.Value,
                InputFPS = inputFp1ks.Value / 1e3f,
                InputBitDepth = inputBitDepth.Value
            });
        }
 public PixelFixFilter(ICImagingControl icImagingControl1)
 {
     //TODO: Insert your own initializations here.
     ic = icImagingControl1;
 }
Ejemplo n.º 14
0
        static void Main(string[] args)
        {
            ICImagingControl ic = new ICImagingControl();

            UInt32      CamerasFound;
            IPConfigAPI ipconfigapi = new IPConfigAPI();

            CamerasFound = ipconfigapi.GetDeviceCount();
            Console.WriteLine("{0} Cameras found.", CamerasFound);

            for (int i = 0; i < CamerasFound; i++)
            {
                Console.WriteLine("Model             :{0}", ipconfigapi.GetModelName(i));
                Console.WriteLine("Manufacturer      :{0}", ipconfigapi.GetManufacturerName(i));
                Console.WriteLine("Serial Number     :{0}", ipconfigapi.GetSerialnumber(i));
                Console.WriteLine("User defined Name :{0}", ipconfigapi.GetUserDefinedName(i));
                Console.WriteLine("Firmware Version  :{0}", ipconfigapi.GetFirmwareversion(i));
                Console.WriteLine("Adapter GUID      :{0}", ipconfigapi.GetAdapterName(i));
                Console.WriteLine("IP Address        :{0}", ipconfigapi.GetIPAddress(i).ToString());
                Console.WriteLine("Subnet Mask       :{0}", ipconfigapi.GetSubnetmask(i).ToString());
                Console.WriteLine("Gateway           :{0}", ipconfigapi.GetGateway(i).ToString());
                Console.WriteLine("");
            }

            IPAddress IP = ipconfigapi.FindIPAdressForSerialnumber("00001234");

            Console.WriteLine("Found IP " + IP.ToString());

            IP = IPAddress.Parse("192.168.2.2");
            string SerialNumber = ipconfigapi.FindSerialNumberforIPaddress(IP);

            Console.WriteLine("Found serial number " + SerialNumber);

            if (SerialNumber != "")
            {
                foreach (Device dev in ic.Devices)
                {
                    String DevSerial;
                    dev.GetSerialNumber(out DevSerial);
                    // DevSerial can be shorter than 8 chars,
                    // therefore, fill the string with "0" from
                    // beginning. (Leading zeros)
                    while (DevSerial.Length < 8)
                    {
                        DevSerial = "0" + DevSerial;
                    }

                    if (DevSerial == SerialNumber)
                    {
                        ic.Device = dev;
                        break;
                    }
                }
            }

            if (ic.DeviceValid)
            {
                Console.WriteLine("Camera opened!");
                ic.Device = "";
            }

            Console.WriteLine("Done");
            Console.ReadKey();
        }
Ejemplo n.º 15
0
 public ICUsbCamera(ICImagingControl _icCam)
 {
     this.IcCam = _icCam;
 }
Ejemplo n.º 16
0
        private void Init_Sliders(ICImagingControl ic) //функция инициализации ползунка для регулировки отдельных свойст камеры
        {
            bool locallogging = false; int il = 0;     //отладочный режим

            if (locallogging)
            {
                FLog.Log("Init_sliders L" + (il++).ToString());
            }
            Init_Properties(ic);
            string VCDID_Exp        = VCDIDs.VCDID_Exposure;
            string VCDID_Gain       = VCDIDs.VCDID_Gain;
            string VCDID_Brightness = VCDIDs.VCDID_Brightness;

            if (locallogging)
            {
                FLog.Log("Init_sliders L" + (il++).ToString());
            }

            try
            {
                if (!vcdProp.AutoAvailable(VCDID_Exp))//если невозможна автоматическая регулировка,отключить возможность ее включения
                {
                    ChB_ExposureAuto.IsEnabled = false;
                    if (locallogging)
                    {
                        FLog.Log("Init_sliders L_tr" + (il++).ToString());
                    }
                }
                else
                {
                    if (locallogging)
                    {
                        FLog.Log("Init_sliders F_tr" + (il++).ToString());
                    }
                    ChB_ExposureAuto.IsEnabled    = true;
                    ChB_ExposureAuto.IsChecked    = Exposure_Auto;
                    vcdProp.Automation[VCDID_Exp] = false;

                    /* var a = vcdProp.RangeValue[VCDID_Exp] = 5;
                     * var b = AbsValExp.Value;*/
                }
            }
            catch
            {
                FLog.Log("Error on autoexposure detecting. Deiniting autoexposure...");
                ChB_ExposureAuto.IsEnabled = false;
            }
            if (locallogging)
            {
                FLog.Log("Init_sliders L" + (il++).ToString());
            }

            try
            {
                if (!vcdProp.AutoAvailable(VCDID_Gain))//если невозможна автоматическая регулировка,отключить возможность ее включения
                {
                    ChB_GainAuto.IsEnabled = false;
                }
                else
                {
                    ChB_GainAuto.IsEnabled         = true;
                    ChB_GainAuto.IsChecked         = Gain_Auto;
                    vcdProp.Automation[VCDID_Gain] = false;
                }
            }
            catch
            {
                FLog.Log("Error on autogain detecting. Deiniting autogain...");
                ChB_GainAuto.IsEnabled = false;
            }
            if (locallogging)
            {
                FLog.Log("Init_sliders L" + (il++).ToString());
            }

            try
            {
                if (!vcdProp.AutoAvailable(VCDID_Brightness))//если невозможна автоматическая регулировка,отключить возможность ее включения
                {
                    ChB_BrightnessAuto.IsEnabled = false;
                }
                else
                {
                    ChB_BrightnessAuto.IsEnabled         = true;
                    ChB_BrightnessAuto.IsChecked         = false;
                    vcdProp.Automation[VCDID_Brightness] = false;
                }
            }
            catch
            {
                FLog.Log("Error on autobrightness detecting. Deiniting autobrightness...");
                ChB_BrightnessAuto.IsEnabled = false;
            }
            if (locallogging)
            {
                FLog.Log("Init_sliders L" + (il++).ToString());
            }

            try
            {
                if (locallogging)
                {
                    FLog.Log("Init_sliders L_exp" + (il++).ToString());
                }
                if (!vcdProp.Available(VCDID_Exp))
                {
                    if (locallogging)
                    {
                        FLog.Log("Init_sliders L_noexp" + (il++).ToString());
                    }
                    TrB_ExposureVal.IsEnabled = false;
                    NUD_Exposure.IsEnabled    = false;
                }
                else
                {
                    if (locallogging)
                    {
                        FLog.Log("Init_sliders L_exp" + (il++).ToString());
                    }
                    TrB_ExposureVal.IsEnabled = true;
                    NUD_Exposure.IsEnabled    = true;
                    if (locallogging)
                    {
                        FLog.Log("Init_sliders L_exp" + (il++).ToString());
                    }
                    double Az = TrB_ExposureVal.Minimum = ServiceFunctions.Math.PerfectRounding((AbsValExp.RangeMin * zF), 0);
                    double Bz = TrB_ExposureVal.Maximum = ServiceFunctions.Math.PerfectRounding((AbsValExp.RangeMax * zF), 0);
                    alpha = (AbsValExp.RangeMin * AbsValExp.RangeMax - 0.25 * 0.25) / (AbsValExp.RangeMin + AbsValExp.RangeMax - 2 * 0.25);
                    xenta = Math.Pow((AbsValExp.RangeMax - alpha) / (AbsValExp.RangeMin - alpha), (zF / ((Bz - Az))));
                    beta  = (0.25 - alpha) / Math.Pow(xenta, (Bz + Az) / (2 * zF));
                    if (locallogging)
                    {
                        FLog.Log("Init_sliders L_exp" + (il++).ToString());
                    }
                    double val1slide = Az;
                    if (locallogging)
                    {
                        FLog.Log("Init_sliders L_exp_this" + (il++).ToString());
                    }
                    try { TrB_ExposureVal.Value = Exposure_real2slide(AbsValExp.Value); }
                    catch
                    {
                        if (TrB_ExposureVal.Value < TrB_ExposureVal.Minimum)
                        {
                            TrB_ExposureVal.Value = TrB_ExposureVal.Minimum;
                        }
                        else if (TrB_ExposureVal.Value > TrB_ExposureVal.Maximum)
                        {
                            TrB_ExposureVal.Value = TrB_ExposureVal.Maximum;
                        }
                    }
                    if (locallogging)
                    {
                        FLog.Log("Init_sliders L_exp" + (il++).ToString());
                    }
                    TrB_ExposureVal.TickFrequency = (TrB_ExposureVal.Maximum - TrB_ExposureVal.Minimum) / 10;
                    // ChangingActivatedTextBoxExp = false;
                    if (locallogging)
                    {
                        FLog.Log("Init_sliders L_exp" + (il++).ToString());
                    }
                    NUD_Exposure.FormatString = "F" + DetectTheNumberOfDecimalPositions(AbsValExp.RangeMin);
                    NUD_Exposure.Value        = ServiceFunctions.Math.PerfectRounding(Exposure_Slide2real(TrB_ExposureVal.Value), 4);
                    if (locallogging)
                    {
                        FLog.Log("Init_sliders L_exp" + (il++).ToString());
                    }
                    //ChangingActivatedTextBoxExp = true;
                }
            }
            catch
            {
                FLog.Log("Error on exposure detecting. Deiniting exposure...");
                TrB_ExposureVal.IsEnabled = false;
                NUD_Exposure.IsEnabled    = false;
            }
            if (locallogging)
            {
                FLog.Log("Init_sliders L" + (il++).ToString());
            }

            try
            {
                if (!vcdProp.Available(VCDID_Gain))
                {
                    TrB_GainVal.IsEnabled = false;
                    NUD_Gain.IsEnabled    = false;
                }
                else
                {
                    var a = vcdProp.RangeValue[VCDID_Gain];
                    TrB_GainVal.IsEnabled     = true;
                    NUD_Gain.IsEnabled        = true;
                    TrB_GainVal.Minimum       = vcdProp.RangeMin(VCDID_Gain);
                    TrB_GainVal.Maximum       = vcdProp.RangeMax(VCDID_Gain);
                    TrB_GainVal.Value         = a;
                    TrB_GainVal.TickFrequency = (TrB_GainVal.Maximum - TrB_GainVal.Minimum) / 10;
                    // ChangingActivatedTextBoxGain = false;
                    NUD_Gain.Minimum = vcdProp.RangeMin(VCDID_Gain);
                    NUD_Gain.Maximum = vcdProp.RangeMax(VCDID_Gain);
                    NUD_Gain.Value   = TrB_GainVal.Value;
                    // ChangingActivatedTextBoxGain = true;
                }
            }
            catch
            {
                FLog.Log("Error on gain detecting. Deiniting gain...");
                TrB_GainVal.IsEnabled = false;
                NUD_Gain.IsEnabled    = false;
            }
            if (locallogging)
            {
                FLog.Log("Init_sliders L" + (il++).ToString());
            }

            try
            {
                if (!vcdProp.Available(VCDID_Brightness))
                {
                    TrB_Brightness.IsEnabled = false;
                    NUD_Brightness.IsEnabled = false;
                }
                else
                {
                    TrB_Brightness.IsEnabled = true;
                    NUD_Brightness.IsEnabled = true;

                    TrB_Brightness.Minimum       = vcdProp.RangeMin(VCDID_Brightness);
                    TrB_Brightness.Maximum       = vcdProp.RangeMax(VCDID_Brightness);
                    TrB_Brightness.Value         = vcdProp.RangeValue[VCDID_Brightness];
                    TrB_Brightness.TickFrequency = (TrB_Brightness.Maximum - TrB_Brightness.Minimum) / 10;

                    // ChangingActivatedTextBoxGain = false;
                    NUD_Brightness.Minimum = vcdProp.RangeMin(VCDID_Brightness);
                    NUD_Brightness.Maximum = vcdProp.RangeMax(VCDID_Brightness);
                    NUD_Brightness.Value   = TrB_Brightness.Value;
                    // ChangingActivatedTextBoxGain = true;
                }
            }
            catch
            {
                FLog.Log("Error on brightness detecting. Deiniting brightness...");
                TrB_Brightness.IsEnabled = false;
                NUD_Brightness.IsEnabled = false;
            }

            if (locallogging)
            {
                FLog.Log("Init_sliders L" + (il++).ToString());
            }
            if (locallogging)
            {
                FLog.Log("Init_sliders completed");
            }
        }