Exemple #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="portName"></param>
        /// <param name="camDevice"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="fps"></param>
        /// <param name="bpp"></param>
        /// <returns></returns>
        public virtual bool Connect(string portName, DsDevice camDevice, int width, int height, int fps, int bpp)
        {
            if (pFrameBuffer != IntPtr.Zero)
            {
                Marshal.FreeHGlobal(pFrameBuffer);
                pFrameBuffer = IntPtr.Zero;
            }
            this.pFrameBuffer = Marshal.AllocHGlobal(width * height * bpp / 8);

            this.matFrame = new Mat(height, width, Emgu.CV.CvEnum.DepthType.Cv16U, 1);

            this.frameSize.Width  = width;
            this.frameSize.Height = height;
            this.frameFPS         = fps;
            this.frameBPP         = bpp;

            if (dsCamera == null && !string.IsNullOrWhiteSpace(portName))
            {
                this.dsDevice = camDevice;
                this.dsCamera = new DirectShowCam();
                if (this.dsCamera != null)
                {
                    this.dsCamera.Open(camDevice, width, height, fps, bpp, this, MediaSubFormat.Y16);
                    this.dsCamera.Run();

                    return(true);
                }
            }

            return(false);
        }
Exemple #2
0
        /// <summary>
        /// Enumerate UVC Cameras and enrolled
        /// </summary>
        private void enumerateCameras()
        {
            DsDevice[] systemCameras = DirectShowCam.GetCameraDeviceList();

            comboBox_camera_list.Items.Clear();
            foreach (var camera in systemCameras)
            {
                comboBox_camera_list.Items.Add(new { Text = camera.Name, Value = camera });
            }
        }
Exemple #3
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        virtual public bool Disconnect()
        {
            if (this.dsCamera != null)
            {
                this.dsCamera.Stop();
                this.dsCamera.Close();
                this.dsCamera.Dispose();
                this.dsCamera = null;
            }

            if (pFrameBuffer != IntPtr.Zero)
            {
                Marshal.FreeHGlobal(pFrameBuffer);
                pFrameBuffer = IntPtr.Zero;
            }

            if (this.matFrame != null)
            {
                this.matFrame.Dispose();
            }

            return(true);
        }
Exemple #4
0
        /// <summary>
        /// Connect selected camera from listbox
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button_Connect_Click(object sender, EventArgs e)
        {
            if (button_Connect.Text == "Connect")
            {
                if (comboBox_camera_list.SelectedIndex != -1)
                {
                    // Do Connection
                    button_Connect.Text = "Disconnect";

                    var itemObj = (comboBox_camera_list.SelectedItem as dynamic);
                    if (itemObj != null)
                    {
                        string[] listCap = DirectShowCam.GetCameraCapability(itemObj.Value);

                        DirectShowCam.CameraProperty camProperty;

                        //foreach (var cap in listCap)
                        {
                            camProperty = DirectShowCam.ParseCameraProperty(listCap[0]);    // select just first property
                        }

                        groupBox_status.Enabled    = true;
                        tabControl_Control.Enabled = true;

                        cameraUVC.Connect(itemObj.Text,
                                          new DsDevice(itemObj.Value.Mon),
                                          camProperty.Width, camProperty.Height, camProperty.FPS, camProperty.Bpp);

                        cameraUVC.frameEventHandler += frameEventHandler;
                        monitorTimer.Tick           += MonitorTimer_Tick;
                        monitorTimer.Start();
                    }
                }
                else
                {
                    MessageBox.Show("Select one of cameras in uvc camera list", "Information", MessageBoxButtons.OK);
                }
            }
            else
            {
                // Do Disconnection
                monitorTimer.Stop();
                cameraUVC.Disconnect();

                monitorTimer.Tick           -= MonitorTimer_Tick;
                cameraUVC.frameEventHandler -= frameEventHandler;

                tabControl_Control.Enabled = false;
                groupBox_status.Enabled    = false;

                button_Connect.Text = "Connect";

                if (imageBox_ThermalView.Image != null)
                {
                    imageBox_ThermalView.Image.Dispose();
                    imageBox_ThermalView.Image = null;
                }

                comboBox_camera_list.SelectedIndex = -1;    // unselect any item
            }
        }