Example #1
0
        private void Awake()
        {
            _imgMode = Constants.ImgMode.CustomgrayWithCirclesOverlayed;
            _useInternImageProcessing = true;

            _defaultCameraProperties = new CameraProperties()
            {
                Width      = c.CameraResolutionWidth,
                Height     = c.CameraResolutionHeight,
                Exposure   = -7,
                Gain       = 2,
                Saturation = 55,
                Contrast   = 15
            };

            _ht21Parameters = new HT21Parameters()
            {
                ExecuteHT21       = false,
                ExecuteMedianBlue = false,
                Dp        = 1,
                MinDist   = 120,
                Param1    = 60,
                Param2    = 30,
                MinRadius = 12,
                MaxRadius = 160
            };
        }
Example #2
0
        public BallRadiusAndPosition UpdateImageProcessing()
        {
            if (Input.GetKeyDown(KeyCode.B))
            {
                _imgMode--;
                if ((int)_imgMode < 0)
                {
                    _imgMode = (Constants.ImgMode)Enum.GetNames(typeof(Constants.ImgMode)).Length - 1;
                }

                _captionView.SetText(Constants.Captions[(int)_imgMode]);
            }

            if (Input.GetKeyDown(KeyCode.N))
            {
                _captionView.SetText(Constants.Captions[(int)_imgMode]);
            }

            if (Input.GetKeyDown(KeyCode.M))
            {
                _imgMode++;
                if ((int)_imgMode >= Enum.GetNames(typeof(Constants.ImgMode)).Length)
                {
                    _imgMode = 0;
                }

                _captionView.SetText(Constants.Captions[(int)_imgMode]);
            }

            foreach (var c in _volume.profile.components)
            {
                if (c is OverlayComponent oc)
                {
                    if (_imgMode == Constants.ImgMode.Red)
                    {
                        oc.tintColor.value = Color.red;
                    }
                    else if (_imgMode == Constants.ImgMode.Green)
                    {
                        oc.tintColor.value = Color.green;
                    }
                    else if (_imgMode == Constants.ImgMode.Blue)
                    {
                        oc.tintColor.value = Color.blue;
                    }
                    else
                    {
                        oc.tintColor.value = Color.white;
                    }
                }
            }

            getCameraTexture(
                _camera,
                _pixelsPtr,
                _ht21Parameters.ExecuteHT21,
                _ht21Parameters.ExecuteMedianBlue,
                (int)_imgMode,
                _ht21Parameters.Dp,
                _ht21Parameters.MinDist,
                _ht21Parameters.Param1,
                _ht21Parameters.Param2,
                _ht21Parameters.MinRadius,
                _ht21Parameters.MaxRadius
                );

            _texture.SetPixels32(_pixels);
            _texture.Apply();

            Graphics.Blit(_texture, _renderTexture);

            return(new BallRadiusAndPosition()
            {
                Radius = (float)getCircleRadius(),
                PositionX = -(float)getCircleCenter_x() + c.CameraResolutionWidth / 2f,
                PositionY = -(float)getCircleCenter_y() + c.CameraResolutionHeight / 2f
            });
        }
Example #3
0
        public BallRadiusAndPosition UpdateImageProcessing()
        {
            if (Input.GetKeyDown(KeyCode.B))
            {
                _imgMode--;
                if ((int)_imgMode < 0)
                {
                    _imgMode = (Constants.ImgMode)Enum.GetNames(typeof(Constants.ImgMode)).Length - 1;
                }

                _captionView.SetText(Constants.Captions[(int)_imgMode]);
            }

            if (Input.GetKeyDown(KeyCode.N))
            {
                _captionView.SetText(Constants.Captions[(int)_imgMode]);
            }

            if (Input.GetKeyDown(KeyCode.M))
            {
                _imgMode++;
                if ((int)_imgMode >= Enum.GetNames(typeof(Constants.ImgMode)).Length)
                {
                    _imgMode = 0;
                }

                _captionView.SetText(Constants.Captions[(int)_imgMode]);
            }

            foreach (var c in _volume.profile.components)
            {
                if (c is OverlayComponent oc)
                {
                    if (_imgMode == Constants.ImgMode.Red)
                    {
                        oc.tintColor.value = Color.red;
                    }
                    else if (_imgMode == Constants.ImgMode.Green)
                    {
                        oc.tintColor.value = Color.green;
                    }
                    else if (_imgMode == Constants.ImgMode.Blue)
                    {
                        oc.tintColor.value = Color.blue;
                    }
                    else
                    {
                        oc.tintColor.value = Color.white;
                    }
                }
            }

            getCameraTexture(
                _camera,
                _pixelsPtr,
                _ht21Parameters.ExecuteHT21,
                _ht21Parameters.ExecuteMedianBlue,
                (int)_imgMode,
                _ht21Parameters.Dp,
                _ht21Parameters.MinDist,
                _ht21Parameters.Param1,
                _ht21Parameters.Param2,
                _ht21Parameters.MinRadius,
                _ht21Parameters.MaxRadius
                );

            if (_useInternImageProcessing)
            {
                int numberOfWhitePixels = 0;
                var pixelWidth          = c.CameraResolutionWidth;
                var accumulatedPixelX   = 0;
                var accumulatedPixelY   = 0;
                for (int i = 0; i < _pixels.Length; i++)
                {
                    if (_pixels[i].r > 70)
                    {
                        accumulatedPixelX += i % pixelWidth;
                        accumulatedPixelY += i / pixelWidth;
                        numberOfWhitePixels++;
                        _pixels[i].r = Byte.MaxValue;
                        _pixels[i].g = Byte.MaxValue;
                        _pixels[i].b = 0;
                    }
                }

                var meanPixelX = (float)accumulatedPixelX / numberOfWhitePixels;
                var meanPixelY = (float)accumulatedPixelY / numberOfWhitePixels;

                /*
                 * // color pixel at ball centre white
                 * var meanPixelIndex = (int) meanPixelY * c.CameraResolutionWidth + (int) meanPixelX;
                 * _pixels[meanPixelIndex].r = 1;
                 * _pixels[meanPixelIndex].g = 1;
                 * _pixels[meanPixelIndex].b = 1;
                 */

                // NOTE: use number of pixels and A_c = r^2 * PI
                //    radius.
                var pixelRadius = Mathf.Sqrt(numberOfWhitePixels / Mathf.PI);

                _texture.SetPixels32(_pixels);
                _texture.Apply();

                return(new BallRadiusAndPosition()
                {
                    Radius = pixelRadius,
                    PositionX = -meanPixelX + c.CameraResolutionWidth / 2f,
                    PositionY = -meanPixelY + c.CameraResolutionHeight / 2f
                });
            }

            return(new BallRadiusAndPosition()
            {
                Radius = (float)getCircleRadius(),
                PositionX = -(float)getCircleCenter_x() + c.CameraResolutionWidth / 2f,
                PositionY = -(float)getCircleCenter_y() + c.CameraResolutionHeight / 2f
            });
        }