Exemplo n.º 1
0
 /// <summary>
 /// Calls <see cref="StopController"/> if the controller is started.
 /// </summary>
 private void Dependency_Stopped(IConfigurableController dependency)
 {
     stoppedDependencies.Add(dependency);
     if (IsStarted)
     {
         StopController();
     }
 }
Exemplo n.º 2
0
 /// <summary>
 /// Calls <see cref="OnReady"/> if the controller is configured and all the dependencies are started.
 /// </summary>
 private void Dependency_Started(IConfigurableController dependency)
 {
     stoppedDependencies.Remove(dependency);
     if (IsConfigured && stoppedDependencies.Count == 0)
     {
         OnReady();
     }
 }
 protected void ConfigureCameraParameters(IConfigurableController arucoCamera)
 {
     if (SetParametersAtStart)
     {
         SetParametersToCamera();
     }
     else
     {
         GetParametersFromCamera();
     }
 }
Exemplo n.º 4
0
        public void RemoveDependency(IConfigurableController dependency)
        {
            if (IsStarted)
            {
                throw new Exception("Stop the controller before updating the dependencies.");
            }

            dependencies.Remove(dependency);
            stoppedDependencies.Remove(dependency);

            dependency.Started -= Dependency_Started;
            dependency.Stopped -= Dependency_Stopped;
        }
Exemplo n.º 5
0
        // IArucoCameraController methods

        public void AddDependency(IConfigurableController dependency)
        {
            if (IsStarted)
            {
                throw new Exception("Stop the controller before updating the dependencies.");
            }

            dependencies.Add(dependency);
            if (!dependency.IsStarted)
            {
                stoppedDependencies.Add(dependency);
            }

            dependency.Started += Dependency_Started;
            dependency.Stopped += Dependency_Stopped;
        }
        /// <summary>
        /// Configures the images display.
        /// </summary>
        protected void ConfigureUI(IConfigurableController controller)
        {
            // Configure the buttons
            addImagesButton.enabled = true;
            calibrateButton.enabled = false;
            resetButton.enabled     = false;

            // Configure the images display
            var arucoCamera = arucoCameraCalibration.ArucoCamera;

            calibrationReprojectionErrorTexts = new Text[arucoCamera.CameraNumber];

            // Configure the arucoCameraImagesRect as a grid of images
            int gridCols = 1, gridRows = 1;

            for (int i = 0; i < arucoCamera.CameraNumber; i++)
            {
                if (gridCols * gridRows > i)
                {
                    continue;
                }
                else if (arucoCameraImagesRect.rect.width / gridCols >= arucoCameraImagesRect.rect.height / gridRows)
                {
                    gridCols++;
                }
                else
                {
                    gridRows++;
                }
            }
            Vector2 gridCellSize = new Vector2(1f / gridCols, 1f / gridRows);

            // Configure the cells of the grid of images
            for (int cameraId = 0; cameraId < arucoCamera.CameraNumber; cameraId++)
            {
                int cellCol = cameraId % gridCols;                    // Range : 0 to (gridCols - 1), images from left to right
                int cellRow = (gridRows - 1) - (cameraId / gridCols); // Range : (gridRows - 1) to 0, images from top to bottom

                // Create a cell on the grid for each camera image
                GameObject    cell     = new GameObject("Image " + cameraId + " display");
                RectTransform cellRect = cell.AddComponent <RectTransform>();
                cellRect.SetParent(arucoCameraImagesRect);
                cellRect.anchorMin  = new Vector2(1f / gridCols * cellCol, 1f / gridRows * cellRow); // Cell's position
                cellRect.anchorMax  = cellRect.anchorMin + gridCellSize;                             // All cells have the same size
                cellRect.offsetMin  = cellRect.offsetMax = Vector2.zero;                             // No margins
                cellRect.localScale = Vector3.one;

                // Create an image display inside the cell
                GameObject cellDisplay = new GameObject("Image");
                cellDisplay.transform.SetParent(cellRect);
                cellDisplay.transform.localScale = Vector3.one;

                RawImage cellDisplayImage = cellDisplay.AddComponent <RawImage>();
                cellDisplayImage.texture = arucoCamera.Textures[cameraId];

                AspectRatioFitter cellDisplayFitter = cellDisplay.AddComponent <AspectRatioFitter>(); // Fit the image inside the cell
                cellDisplayFitter.aspectMode  = AspectRatioFitter.AspectMode.FitInParent;
                cellDisplayFitter.aspectRatio = arucoCamera.ImageRatios[cameraId];

                // Create a text for calibration reprojection error inside the cell
                GameObject    reproError     = new GameObject("CalibrationReprojectionErrorText");
                RectTransform reproErrorRect = reproError.AddComponent <RectTransform>();
                reproErrorRect.SetParent(cellRect);
                reproErrorRect.pivot      = Vector2.zero;
                reproErrorRect.anchorMin  = reproErrorRect.anchorMax = Vector2.zero;
                reproErrorRect.offsetMin  = Vector2.one * 5;      // Pos X and pos Y margins
                reproErrorRect.offsetMax  = new Vector2(120, 60); // width and Height
                reproErrorRect.localScale = Vector3.one;

                Text reproErrorText = reproError.AddComponent <Text>();
                reproErrorText.font     = Resources.GetBuiltinResource <Font>("Arial.ttf");
                reproErrorText.fontSize = 12;
                reproErrorText.color    = Color.red;
                calibrationReprojectionErrorTexts[cameraId] = reproErrorText;
            }

            // Configure the text
            UpdateImagesCountText();
            UpdateCalibrationReprojectionErrorText();
        }