예제 #1
0
        /// <summary>
        /// Detects if the list of installed cameras has changed
        /// since the previous run of ACAT
        /// </summary>
        /// <returns>true if it has</returns>
        private bool hasCameraListChanged()
        {
            var listFromSettings = VisionActuatorSettings.CameraList;
            var activeCameraList = Cameras.GetCameraNames();

            if (listFromSettings == null || activeCameraList == null)
            {
                return(true);
            }

            if (listFromSettings.Length != activeCameraList.Count())
            {
                return(true);
            }

            foreach (var cameraInstalled in activeCameraList)
            {
                bool found = listFromSettings.Any(cameraInSettings => String.Compare(cameraInstalled, cameraInSettings, false) == 0);

                if (!found)
                {
                    return(true);
                }
            }

            return(false);
        }
예제 #2
0
        /// <summary>
        /// Detects cameras installed on the computer and if reqd,
        /// asks the user to select from the list.  Saves the
        /// list of currently active cameras so if any change is detected
        /// the next time ACAT is run, we can display the list again.
        /// Also instructs ACAT Vision to use the selected camera
        /// </summary>
        /// <returns></returns>
        private bool detectAndSetPreferredCamera()
        {
            var  installedCameras = Cameras.GetCameraNames();
            var  preferredCamera  = String.Empty;
            bool retVal           = true;

            if (hasCameraListChanged() || !isCameraInstalled(VisionActuatorSettings.PreferredCamera))
            {
                VisionActuatorSettings.CameraList = installedCameras.ToArray();

                // if there is more than one camera, let the user pick
                if (installedCameras.Count() > 1)
                {
                    var form = new CameraSelectForm
                    {
                        CameraNames      = installedCameras,
                        Prompt           = R.GetString("SelectCamera"),
                        OKButtonText     = R.GetString("OK"),
                        CancelButtonText = R.GetString("Cancel"),
                        Name             = _title
                    };

                    var result = form.ShowDialog();

                    if (result == DialogResult.Cancel)
                    {
                        MessageBox.Show(R.GetString("NoCameraSelectedVisionWillNotBeActivated"),
                                        _title,
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Warning);
                        retVal = false;
                    }
                    else
                    {
                        MessageBox.Show(String.Format(R.GetString("SelectedCamera"), form.SelectedCamera),
                                        _title,
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Information);

                        preferredCamera = form.SelectedCamera;
                    }
                }
                else
                {
                    preferredCamera = installedCameras.ElementAt(0);
                }
            }
            else
            {
                preferredCamera = VisionActuatorSettings.PreferredCamera;
            }

            VisionActuatorSettings.PreferredCamera = preferredCamera;

            VisionActuatorSettings.Save();

            VisionSensor.selectCamera(preferredCamera);

            return(retVal);
        }
예제 #3
0
        /// <summary>
        /// Form load event handler.  Quit if there are no
        /// cameras.  If multiple cameras, let the user select
        /// the preferred one to use
        /// </summary>
        /// <param name="sender">event sender</param>
        /// <param name="e">event args</param>
        private void Form1_Load(object sender, EventArgs e)
        {
            Text = _title;

            var _installedCameras = Cameras.GetCameraNames();

            if (!_installedCameras.Any())
            {
                MessageBox.Show("No cameras detected. Exiting",
                                _title,
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Exclamation);

                Close();
                return;
            }

            var preferredCamera = String.Empty;

            if (_installedCameras.Count() > 1)
            {
                var form = new CameraSelectForm
                {
                    CameraNames      = _installedCameras,
                    Name             = _title,
                    Prompt           = "Select Camera",
                    OKButtonText     = "OK",
                    CancelButtonText = "Cancel"
                };

                var result = form.ShowDialog();

                if (result == DialogResult.Cancel)
                {
                    MessageBox.Show("No camera selected.  Exiting", _title);
                    Close();
                    return;
                }

                preferredCamera = form.SelectedCamera;
            }
            else
            {
                preferredCamera = _installedCameras.ElementAt(0);
            }

            VisionSensor.selectCamera(preferredCamera);

            Location = new Point(Screen.PrimaryScreen.WorkingArea.Width - Width,
                                 Screen.PrimaryScreen.WorkingArea.Height - Height);

            TopMost = false;
            TopMost = true;

            VisionSensor.SetVisionEventHandler(CallbackFromVision);
        }
예제 #4
0
        /// <summary>
        /// Checks if the specified camera is currently active
        /// </summary>
        /// <param name="camera">name of the camera</param>
        /// <returns>true if it is</returns>
        private bool isCameraInstalled(String camera)
        {
            var trimmedCamera = camera.Trim();

            if (String.IsNullOrEmpty(trimmedCamera))
            {
                return(false);
            }

            var activeCameraList = Cameras.GetCameraNames();

            return(activeCameraList.Any(c => String.Compare(c, camera, false) == 0));
        }
예제 #5
0
        /// <summary>
        /// Initialize the vision actuator.  Detect cameras,
        /// let the user select the preferred camera (if reqd),
        /// spawn threads etc.
        /// </summary>
        /// <returns>true on success, false otherwise</returns>
        public override bool Init()
        {
            Attributions.Add("ACAT Vision",
                             "Open Source Computer Vision Library (OpenCV) is licensed under the BSD license");

            if (!Cameras.GetCameraNames().Any())
            {
                MessageBox.Show(R.GetString("NoCamerasFoundACATVisionDisabled"),
                                _title,
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Exclamation);

                OnInitDone();

                return(true);
            }

            _initInProgress = true;

            // load settings from the settings file
            Settings.SettingsFilePath = UserManager.GetFullPath(SettingsFileName);
            VisionActuatorSettings    = Settings.Load();

            VisionSensor.init();

            bool retVal = detectAndSetPreferredCamera();

            if (retVal)
            {
                showCameraStatus(R.GetString("InitializingCamera"));

                _acatVisionThread = new Thread(visionThread)
                {
                    IsBackground = true
                };
                _acatVisionThread.Start();
            }
            else
            {
                _initInProgress = false;
                OnInitDone();
            }

            return(retVal);
        }
예제 #6
0
        /// <summary>
        /// Event handler for form loader
        /// </summary>
        /// <param name="sender">event sender</param>
        /// <param name="e">event args</param>
        private void PrefChooseForm_Load(object sender, EventArgs e)
        {
            float currentAspectRatio = (float)ClientSize.Height / ClientSize.Width;

            if (_designTimeAspectRatio != 0.0f && currentAspectRatio != _designTimeAspectRatio)
            {
                ClientSize = new System.Drawing.Size(ClientSize.Width, (int)(_designTimeAspectRatio * ClientSize.Width));
            }

            CenterToScreen();

            TopMost = true;

            _installedCameras = Cameras.GetCameraNames();
            if (!_installedCameras.Any())
            {
                buttonSelectCamera.Enabled = false;
            }
        }