private void OpenCamera(CameraSelection cameraSelection)
        {
            CloseCamera();

            int cameraCount = 0;

            _cameraInfo = new Camera.CameraInfo();
            cameraCount = Camera.NumberOfCameras;
            for (int camIdx = 0; camIdx < cameraCount; camIdx++)
            {
                Camera.GetCameraInfo(camIdx, _cameraInfo);
                if (_cameraInfo.Facing == cameraSelection.ToCameraFacing())
                {
                    try
                    {
                        _camera = Camera.Open(camIdx);
                        //var size = new Camera.Size(_camera, 300, 300);
                        _cameraHardwareRotation = _cameraInfo.Orientation;

                        _selectedCamera  = cameraSelection;
                        _isCameraStarted = true;
                    }
                    catch (Exception e)
                    {
                        CloseCamera();
                        Log.Error("CustomCameraView OpenCamera", e.Message);
                    }
                }
            }
        }
Example #2
0
        public Form1()
            :base("GDI Video", 10, 10, 640, 480)
        {
            // Show a dialog box on the screen so the user
            // can select which camera to use if they have
            // multiple attached.
            CaptureDeviceDescription capDescription = new CaptureDeviceDescription();
            CameraSelection camForm = new CameraSelection();
            camForm.ShowDialog();

            //// Get the chosen configuration from the dialog 
            //// and use it to create a capture device.
            object config = camForm.SetupPage.GetConfiguration();
            m_CaptureDevice = (VideoCaptureDevice)capDescription.CreateVideoSource(config);

            // Another way to get a hold of a capture device
            //m_CaptureDevice = VideoCaptureDevice.CreateCaptureDeviceFromIndex(0, 320, 240);
            m_CamControl = new CameraControl(m_CaptureDevice);

            //Console.WriteLine("Capabilities: {0}", m_CaptureDevice.Capabilities.Count);
            // Let the capture device know what function to call
            // whenever a frame is received.
            m_CaptureDevice.NewFrame += OnFrameReceived;

            // Start the capture device on its own thread
            m_CaptureDevice.Start();

            fStick = new Joystick(winmm.JOYSTICKID1);
            dispatcher = new TimedDispatcher(1.0 / 2, OnJoystickDispatch, null);
            dispatcher.Start();

        }
 private void radioButtonEast_Checked(object sender, RoutedEventArgs e)
 {
     if (cameraSelection == CameraSelection.None)
     {
         //initial selction; connection can now be made
         connectButton.IsEnabled = true;
     }
     cameraSelection = CameraSelection.East;
 }
        public static CameraFacing ToCameraFacing(this CameraSelection cameraSelection)
        {
            switch (cameraSelection)
            {
            case CameraSelection.Back:
                return(CameraFacing.Back);

            case CameraSelection.Front:
                return(CameraFacing.Front);

            default:
                return(CameraFacing.Back);
            }
        }
        public static AVCaptureDevicePosition ToAVCaptureDevicePosition(this CameraSelection cameraSelection)
        {
            switch (cameraSelection)
            {
            case CameraSelection.Back:
                return(AVCaptureDevicePosition.Back);

            case CameraSelection.Front:
                return(AVCaptureDevicePosition.Front);

            case CameraSelection.None:
            default:
                return(AVCaptureDevicePosition.Unspecified);
            }
        }
        /// <summary>
        /// Starts the camera
        /// </summary>
        /// <param name="selectedCamera">The selected camera, default: Back</param>
        public void Start(CameraSelection selectedCamera = CameraSelection.Back)
        {
            _cameraOrientation = Abstractions.CameraOrientation.Automatic;

            if (_selectedCamera == CameraSelection.None)
            {
                _selectedCamera = selectedCamera;
            }

            _isCameraStarted = true;

            if (_surface != null)
            {
                OpenCamera(_selectedCamera);
            }
        }
Example #7
0
        void SetSelectedCamera(CameraSelection selectedCamera)
        {
            if (selectedCamera.ToAVCaptureDevicePosition() == _captureDeviceInput.Device.Position)
            {
                return;
            }

            var device = GetCamera(selectedCamera.ToAVCaptureDevicePosition());


            ConfigureCameraForDevice(device);

            _captureSession.BeginConfiguration();
            _captureSession.RemoveInput(_captureDeviceInput);
            _captureDeviceInput = AVCaptureDeviceInput.FromDevice(device);
            _captureSession.AddInput(_captureDeviceInput);
            _captureSession.CommitConfiguration();
        }
 private void BtnTakePhoto_Click(object sender, EventArgs e)
 {
     try
     {
         var frm = new CameraSelection();
         frm.StartPosition = FormStartPosition.CenterParent;
         if (frm.ShowDialog() == DialogResult.OK)
         {
             if (frm.CAMERA != null)
             {
                 isChangePhoto  = true;
                 picPhoto.Image = frm.CAMERA;
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Example #9
0
        /// <summary>
        /// Starts the camera
        /// </summary>
        /// <param name="selectedCamera">The selected camera, default: Back</param>
        public void Start(CameraSelection selectedCamera = CameraSelection.None)
        {
            if (selectedCamera == CameraSelection.None)
            {
                selectedCamera = _selectedCamera;
            }

            try
            {
                SetupUserInterface();
                //SetupEventHandlers();
                SetupLiveCameraStream();
                SetSelectedCamera(selectedCamera);
                AuthorizeCameraUse();
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(@"			ERROR: ", ex.Message);
            }
        }
Example #10
0
        // --------------------------------------------------------
        // Button handling
        // --------------------------------------------------------

        private void openWebcamClick(object sender, RoutedEventArgs e)
        {
            StopTracking();

            if (cam_sec == null)
            {
                cam_sec = new CameraSelection();
            }
            else
            {
                cam_sec            = new CameraSelection(cam_sec.cams);
                cam_sec.Visibility = System.Windows.Visibility.Visible;
            }

            // Set the icon
            Uri iconUri = new Uri("logo1.ico", UriKind.RelativeOrAbsolute);

            cam_sec.Icon = BitmapFrame.Create(iconUri);

            if (!cam_sec.no_cameras_found)
            {
                cam_sec.ShowDialog();
            }

            if (cam_sec.camera_selected)
            {
                int cam_id = cam_sec.selected_camera.Item1;
                int width  = cam_sec.selected_camera.Item2;
                int height = cam_sec.selected_camera.Item3;

                SequenceReader reader = new SequenceReader(cam_id, width, height);

                processing_thread      = new Thread(() => ProcessingLoop(reader));
                processing_thread.Name = "Webcam processing";
                processing_thread.Start();
            }
        }
Example #11
0
        void RegistryInit(string DefaultOysterAddress,int DefaultOysterConnectionPort, int DefaultOysterFilePort,string DefaultOysterDeviceID,string OysterDeviceFriendlyName, bool ManualConfiguration,
			RecordOptions.ScreenRecordType RecordType,
			string WindowTitleToRecord,
			ScreenEncoder.CapturePerformance ScreenCapturePerformance,
			RecordOptions.CameraSelection CamerasSelected,
			int MinutesToRecord, int SecondsToCountdown,
			string ScreenProfileDirectory, string ScreenWMVDirectory,
			RecordOptions.PrimaryCamera CameraPrimary)
        {
            m_sDefaultOysterDeviceAddress = (string)
                m_RegKey.GetValue("DefaultOysterDeviceAddress",DefaultOysterDeviceAddress);
            m_iDefaultOysterDeviceConnectionPort = (int)
                m_RegKey.GetValue("DefaultOysterDeviceConnectionPort",DefaultOysterDeviceConnectionPort);
            m_iDefaultOysterDeviceFilePort = (int)
                m_RegKey.GetValue("DefaultOysterDeviceFilePort",DefaultOysterDeviceFilePort);
            m_sDefaultOysterAddress = (string)
                m_RegKey.GetValue("DefaultOysterAddress",DefaultOysterAddress);
            m_iDefaultOysterConnectionPort = (int)
                m_RegKey.GetValue("DefaultOysterConnectionPort",DefaultOysterConnectionPort);
            m_iDefaultOysterFilePort = (int)
                m_RegKey.GetValue("DefaultOysterFilePort",DefaultOysterFilePort);
            m_sDefaultOysterDeviceID = (string)
                m_RegKey.GetValue("DefaultOysterDeviceID",DefaultOysterDeviceID);
            m_sOysterDeviceFriendlyName = (string)
                m_RegKey.GetValue("OysterDeviceFriendlyName",OysterDeviceFriendlyName);
            m_bManualConfiguration = bool.Parse((string)m_RegKey.GetValue("ManualConfiguration",ManualConfiguration.ToString()));
            m_ScreenRecordType = (RecordOptions.ScreenRecordType)
                System.Enum.Parse(typeof(RecordOptions.ScreenRecordType),
                (string)m_RegKey.GetValue("RecordType",RecordType.ToString()));
            m_sWindowTitleToRecord = (string)
                m_RegKey.GetValue("WindowTitleToRecord",WindowTitleToRecord);
            m_ScreenCapturePerformance = (ScreenEncoder.CapturePerformance)
                System.Enum.Parse(typeof(ScreenEncoder.CapturePerformance),
                (string)m_RegKey.GetValue("CapturePerformance",ScreenCapturePerformance.ToString()));
            m_CameraSelection = (RecordOptions.CameraSelection)
                System.Enum.Parse(typeof(RecordOptions.CameraSelection),
                (string)m_RegKey.GetValue("SelectedCamera",CamerasSelected.ToString()));
            m_iMinutesToRecord = (int)m_RegKey.GetValue("MinutesToRecord",MinutesToRecord);
            m_iMinutesToCountdown = (int)m_RegKey.GetValue("SecondsToCountdown",SecondsToCountdown);
            m_sProfileDirectory =
                (string)m_RegKey.GetValue("ProfileDirectory",ScreenProfileDirectory);
            m_sProfileDirectory = RemoveTrailingBackslashFromPath(m_sProfileDirectory);
            m_sWMVDirectory = (string) m_RegKey.GetValue("WMVDirectory",ScreenWMVDirectory);
            m_sWMVDirectory = RemoveTrailingBackslashFromPath(m_sWMVDirectory);
            m_PrimaryCamera = (RecordOptions.PrimaryCamera)
                System.Enum.Parse(typeof(RecordOptions.PrimaryCamera),
                (string)m_RegKey.GetValue("CameraPrimary",CameraPrimary.ToString()));
            m_bHasBeenSaved = bool.Parse((string)m_RegKey.GetValue("HasBeenSaved",false.ToString()));
        }
        private void btnReadCard_Click(object sender, EventArgs e)
        {
            try
            {
                var frm = new CameraSelection();
                frm.StartPosition = FormStartPosition.CenterParent;
                if (frm.ShowDialog() == DialogResult.OK)
                {
                    if (frm.CAMERA != null)
                    {
                        isChangeCardPhoto = true;
                        picCard.Image     = frm.CAMERA;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            #region === Old ===
            //try
            //{
            //    var frm = new CardSelection();
            //    frm.StartPosition = FormStartPosition.CenterParent;
            //    if (frm.ShowDialog() == DialogResult.OK)
            //    {
            //        if (frm.READ_CARD_STATUS)
            //        {
            //            if (frm.CARD_TYPE == "PID")
            //            {
            //                //บัตรประชาชน
            //                txtFirstName.Text = frm.CARD.TH_FIRST_NAME;
            //                txtLastName.Text = frm.CARD.TH_LAST_NAME;
            //                txtIDCard.Text = frm.CARD.NO;
            //                picCard.Image = (Image)frm.CARD.PHOTO;
            //                CARD_IMAGE = frm.CARD.CARD_IMAGE;
            //                BYTE_IMAGE = frm.CARD.BYTE_IMAGE;
            //                isChangeCardPhoto = true;
            //                var data = _blService.GetBlackListByIdCard(txtIDCard.Text);
            //                if (data.TRN_BLACKLIST == null)
            //                {
            //                    MessageBox.Show("อ่านข้อมูลจากบัตรประชาชน เรียบร้อย!!!");
            //                }
            //                else
            //                {
            //                    var blData = data.TRN_BLACKLIST;
            //                    var msg = "เลขบัตรประชาชน : " + blData.ID_CARD + Environment.NewLine + "ชื่อ-สกุล : " + blData.FIRST_NAME + " " + blData.LAST_NAME;
            //                    msg += Environment.NewLine + "เหตุผล : " + blData.REASON;
            //                    msg += Environment.NewLine + "ณ วันที่ : " + blData.UPDATED_DATE;
            //                    MessageBox.Show(msg, "บุคคล Blacklist", MessageBoxButtons.OK, MessageBoxIcon.Error);
            //                    //this.Close();
            //                }

            //            }
            //            else
            //            {
            //                //ใบขับขี่
            //                txtFirstName.Text = frm.DID.FIRST_NAME_EN;
            //                txtLastName.Text = frm.DID.LAST_NAME_EN;
            //                txtIDCard.Text = frm.DID.NO;
            //                var data = _blService.GetBlackListByIdCard(txtIDCard.Text);
            //                if (data.TRN_BLACKLIST == null)
            //                {
            //                    MessageBox.Show("อ่านข้อมูลจากใบขับขี่ เรียบร้อย!!!");
            //                }
            //                else
            //                {
            //                    var blData = data.TRN_BLACKLIST;
            //                    var msg = "เลขบัตรประชาชน : " + blData.ID_CARD + Environment.NewLine + "ชื่อ-สกุล : " + blData.FIRST_NAME + " " + blData.LAST_NAME;
            //                    msg += Environment.NewLine + "เหตุผล : " + blData.REASON;
            //                    msg += Environment.NewLine + "ณ วันที่ : " + blData.UPDATED_DATE;
            //                    MessageBox.Show(msg, "บุคคล Blacklist", MessageBoxButtons.OK, MessageBoxIcon.Error);
            //                    //this.Close();
            //                }

            //            }
            //        }
            //    }
            //}
            //catch (Exception ex)
            //{
            //    MessageBox.Show(ex.Message);

            //}
            #endregion
        }