Inheritance: MonoBehaviour
Exemple #1
0
 public override void Start()
 {
     base.Start();
     audio        = GetComponent <AudioSource>();
     audio.volume = Toolbox.Instance.soundEffectsVolume;
     edge         = Camera.main.GetComponent <EdgeDetection>();
 }
Exemple #2
0
 void Start()
 {
     objetoSomSub = new GameObject();
     objetoSomSub.AddComponent(typeof(AudioSource));
     objetoSomSub.GetComponent <AudioSource> ().loop = true;
     objetoSomSub.transform.localPosition            = new Vector3(0, 0, 0);
     objetoSomSub.GetComponent <AudioSource> ().clip = somSubmerso;
     objetoSomSub.transform.parent = transform;
     objetoSomSub.SetActive(false);
     //
     _fisheye = GetComponent <Fisheye> ();
     _blur    = GetComponent <Blur> ();
     _edge    = GetComponent <EdgeDetection> ();
     _vortex  = GetComponent <Vortex> ();
     //
     GetComponent <SphereCollider> ().radius    = 0.005f;
     GetComponent <SphereCollider> ().isTrigger = false;
     GetComponent <Rigidbody> ().isKinematic    = true;
     GetComponent <Camera> ().nearClipPlane     = 0.01f;
     //
     _blur.iterations = 5 - DistanciaDeVisib;
     _blur.blurSpread = 1 - (Visibilidade / 10);
     //
     _vortex.radius = new Vector2(1, 1);
     _vortex.center = new Vector2(0.5f, 0.5f);
     //
     _edge.mode             = EdgeDetection.EdgeDetectMode.TriangleLuminance;
     _edge.lumThreshold     = 0;
     _edge.sampleDist       = 0;
     _edge.edgesOnly        = intensidadeCor;
     _edge.edgesOnlyBgColor = corAgua;
     //
     _blur.enabled    = false;
     _fisheye.enabled = false;
     _edge.enabled    = false;
     _vortex.enabled  = false;
     //
     planoGotas = GameObject.CreatePrimitive(PrimitiveType.Plane);
     Destroy(planoGotas.GetComponent <MeshCollider> ());
     planoGotas.transform.localScale       = new Vector3(0.02f, 0.02f, 0.02f);
     planoGotas.transform.parent           = transform;
     planoGotas.transform.localPosition    = new Vector3(0, 0, 0.05f);
     planoGotas.transform.localEulerAngles = new Vector3(90, 180, 0);
     planoGotas.GetComponent <Renderer>().material.shader = Shader.Find("FX/Glass/Stained BumpDistort");
     planoGotas.GetComponent <Renderer> ().material.SetTexture("_BumpMap", TexturaPingos);
     planoGotas.GetComponent <Renderer> ().material.SetFloat("_BumpAmt", 0);
     //
     if (GetComponent <SunShafts> () != null)
     {
         temSunShafts  = true;
         _sunShafts    = GetComponent <SunShafts> ();
         intSolInicial = _sunShafts.sunShaftIntensity;
     }
     else
     {
         temSunShafts = false;
     }
     //
     _audSourc = GetComponent <AudioSource> ();
 }
Exemple #3
0
        public WriteableBitmap GetImage(string _strImgName)
        {
            WriteableBitmap bitmap = null;

            switch (m_strCurImgName)
            {
            case ComInfo.IMG_NAME_EDGE_DETECTION:
                EdgeDetection edge = (EdgeDetection)m_imgProc;
                if (edge != null)
                {
                    bitmap = edge.WriteableBitmap;
                }
                break;

            case ComInfo.IMG_NAME_GRAY_SCALE:
                GrayScale gray = (GrayScale)m_imgProc;
                if (gray != null)
                {
                    bitmap = gray.WriteableBitmap;
                }
                break;

            case ComInfo.IMG_NAME_BINARIZATION:
                Binarization binarization = (Binarization)m_imgProc;
                if (binarization != null)
                {
                    bitmap = binarization.WriteableBitmap;
                }
                break;

            case ComInfo.IMG_NAME_GRAY_SCALE_2DIFF:
                GrayScale2Diff gray2Diff = (GrayScale2Diff)m_imgProc;
                if (gray2Diff != null)
                {
                    bitmap = gray2Diff.WriteableBitmap;
                }
                break;

            case ComInfo.IMG_NAME_COLOR_REVERSAL:
                ColorReversal colorReversal = (ColorReversal)m_imgProc;
                if (colorReversal != null)
                {
                    bitmap = colorReversal.WriteableBitmap;
                }
                break;

            case ComInfo.IMG_NAME_GRAY_SCALE_DIFF:
                GrayScaleDiff grayDiff = (GrayScaleDiff)m_imgProc;
                if (grayDiff != null)
                {
                    bitmap = grayDiff.WriteableBitmap;
                }
                break;

            default:
                break;
            }

            return(bitmap);
        }
Exemple #4
0
        /// <inheritdoc />
        public override void Apply(byte[] data, bool eos)
        {
            if (this.FullTestFrame)
            {
                MMALLog.Logger.LogDebug("Have full test frame");

                // If we have a full test frame stored then we can start storing subsequent frame data to check.
                base.Apply(data, eos);
            }
            else
            {
                this.TestFrame.AddRange(data);

                if (eos)
                {
                    this.FullTestFrame = true;
                    MMALLog.Logger.LogDebug("EOS reached for test frame. Applying edge detection.");

                    // We want to apply Edge Detection to the test frame to make it easier to detect changes.
                    var edgeDetection = new EdgeDetection(this.MotionConfig.Sensitivity);
                    this.ImageContext.Data = this.TestFrame.ToArray();
                    edgeDetection.ApplyConvolution(edgeDetection.Kernel, EdgeDetection.KernelWidth, EdgeDetection.KernelHeight, this.ImageContext);
                }
            }

            if (this.FullFrame)
            {
                MMALLog.Logger.LogDebug("Have full frame, checking for changes.");

                // TODO: Check for changes.
                this.CheckForChanges(this.OnDetect);
            }
        }
Exemple #5
0
        private void UpdateImage()
        {
            Bitmap         bmp = new Bitmap(original.Width, original.Height);
            EdgeFilterMode EFM = EdgeFilterMode.Sharpen;

            switch (comboBox1.Text)
            {
            case "Sharpen":
                EFM = EdgeFilterMode.Sharpen;
                break;

            case "Mono":
                EFM = EdgeFilterMode.EdgeDetectMono;
                break;

            case "Gradient":
                EFM = EdgeFilterMode.EdgeDetectionGradient;
                break;

            case "Gradient sharpen":
                EFM = EdgeFilterMode.SharpenGradient;
                break;

            default:
                EFM = EdgeFilterMode.Sharpen;
                break;
            }
            bmp = EdgeDetection.GradientEdgeDetection(original, EFM, ((radioButton1.Checked) ? DeriviationLevel.First : DeriviationLevel.Second), new float[] { (float)trackBar1.Value / 10, (float)trackBar2.Value / 10, (float)trackBar3.Value / 10 }, (byte)trackBar4.Value);
            using (Graphics gdx = Graphics.FromImage(parent.Space.SelectedLayerW.LayerImage))
            {
                gdx.DrawImage(bmp, new Point(0, 0));
            }
            parent.DrawUpdater(true);
        }
Exemple #6
0
        // TODO EdgeDetection?
        public void RegisterInterruptCallback(int pinId, Action callback,
                                              EdgeDetection mode = EdgeDetection.FallingAndRisingEdge)
        {
            var pin = Pi.Gpio[pinId];

            if (!pins.ContainsKey(pinId) || pins[pinId] != GpioPinDriveMode.Input)
            {
                pins[pinId]       = GpioPinDriveMode.Input;
                pin.PinMode       = GpioPinDriveMode.Input;
                pin.InputPullMode = GpioPinResistorPullMode.PullUp;
            }
            pin.RegisterInterruptCallback(mode, callback);
        }
Exemple #7
0
        /// <summary>
        /// Detects any edges within the image.
        /// </summary>
        /// <typeparam name="TPixel">The pixel format.</typeparam>
        /// <param name="source">The image this method extends.</param>
        /// <param name="filter">The filter for detecting edges.</param>
        /// <param name="rectangle">
        /// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
        /// </param>
        /// <param name="grayscale">Whether to convert the image to Grayscale first. Defaults to true.</param>
        /// <returns>The <see cref="Image{TPixel}"/>.</returns>
        public static Image<TPixel> DetectEdges<TPixel>(this Image<TPixel> source, EdgeDetection filter, Rectangle rectangle, bool grayscale = true)
            where TPixel : struct, IPixel<TPixel>
        {
            IEdgeDetectorProcessor<TPixel> processor;

            switch (filter)
            {
                case EdgeDetection.Kayyali:
                    processor = new KayyaliProcessor<TPixel> { Grayscale = grayscale };
                    break;

                case EdgeDetection.Kirsch:
                    processor = new KirschProcessor<TPixel> { Grayscale = grayscale };
                    break;

                case EdgeDetection.Lapacian3X3:
                    processor = new Laplacian3X3Processor<TPixel> { Grayscale = grayscale };
                    break;

                case EdgeDetection.Lapacian5X5:
                    processor = new Laplacian5X5Processor<TPixel> { Grayscale = grayscale };
                    break;

                case EdgeDetection.LaplacianOfGaussian:
                    processor = new LaplacianOfGaussianProcessor<TPixel> { Grayscale = grayscale };
                    break;

                case EdgeDetection.Prewitt:
                    processor = new PrewittProcessor<TPixel> { Grayscale = grayscale };
                    break;

                case EdgeDetection.RobertsCross:
                    processor = new RobertsCrossProcessor<TPixel> { Grayscale = grayscale };
                    break;

                case EdgeDetection.Robinson:
                    processor = new RobinsonProcessor<TPixel> { Grayscale = grayscale };
                    break;

                case EdgeDetection.Scharr:
                    processor = new ScharrProcessor<TPixel> { Grayscale = grayscale };
                    break;

                default:
                    processor = new SobelProcessor<TPixel> { Grayscale = grayscale };
                    break;
            }

            return DetectEdges(source, rectangle, processor);
        }
Exemple #8
0
    public override int GetHashCode()
    {
        int hash = 1;

        if (Id.Length != 0)
        {
            hash ^= Id.GetHashCode();
        }
        hash ^= tiles_.GetHashCode();
        if (master_ != null)
        {
            hash ^= Master.GetHashCode();
        }
        if (Random != false)
        {
            hash ^= Random.GetHashCode();
        }
        if (TileWidth != 0)
        {
            hash ^= TileWidth.GetHashCode();
        }
        if (TileHeight != 0)
        {
            hash ^= TileHeight.GetHashCode();
        }
        if (ColourBlended != false)
        {
            hash ^= ColourBlended.GetHashCode();
        }
        if (Enhanced != false)
        {
            hash ^= Enhanced.GetHashCode();
        }
        if (EnhancedThreshold != 0)
        {
            hash ^= EnhancedThreshold.GetHashCode();
        }
        if (EdgeDetection != false)
        {
            hash ^= EdgeDetection.GetHashCode();
        }
        hash ^= edges_.GetHashCode();
        if (_unknownFields != null)
        {
            hash ^= _unknownFields.GetHashCode();
        }
        return(hash);
    }
Exemple #9
0
        private void CheckForChanges(Action onDetect)
        {
            var edgeDetection = new EdgeDetection(EDStrength.Medium);

            this.ImageContext.Data = this.WorkingData.ToArray();
            edgeDetection.ApplyConvolution(EdgeDetection.MediumStrengthKernel, 3, 3, this.ImageContext);
            var diff = this.Analyse();

            MMALLog.Logger.LogDebug($"Diff size: {diff}");

            if (diff >= this.MotionConfig.Threshold)
            {
                MMALLog.Logger.LogInformation("Motion detected!");
                onDetect();
            }
        }
Exemple #10
0
        public bool SelectGoImgProc(ComImgInfo _comImgInfo, CancellationToken _token)
        {
            bool bRst = true;

            switch (_comImgInfo.CurImgName)
            {
            case ComInfo.IMG_NAME_EDGE_DETECTION:
                EdgeDetection edge = (EdgeDetection)m_imgProc;
                bRst = edge.GoImgProc(_token);
                break;

            case ComInfo.IMG_NAME_GRAY_SCALE:
                GrayScale gray = (GrayScale)m_imgProc;
                bRst = gray.GoImgProc(_token);
                break;

            case ComInfo.IMG_NAME_BINARIZATION:
                Binarization binarization = (Binarization)m_imgProc;
                binarization.Thresh = _comImgInfo.BinarizationInfo.Thresh;
                bRst = binarization.GoImgProc(_token);
                break;

            case ComInfo.IMG_NAME_GRAY_SCALE_2DIFF:
                GrayScale2Diff gray2Diff = (GrayScale2Diff)m_imgProc;
                bRst = gray2Diff.GoImgProc(_token);
                break;

            case ComInfo.IMG_NAME_COLOR_REVERSAL:
                ColorReversal colorReversal = (ColorReversal)m_imgProc;
                bRst = colorReversal.GoImgProc(_token);
                break;

            case ComInfo.IMG_NAME_GRAY_SCALE_DIFF:
                GrayScaleDiff grayDiff = (GrayScaleDiff)m_imgProc;
                bRst = grayDiff.GoImgProc(_token);
                break;

            default:
                break;
            }

            return(bRst);
        }
Exemple #11
0
        private System.Windows.Point GetEdgePoint(System.Windows.Controls.Image rawImage, System.Windows.Controls.Image overlayImage)
        {
            Bitmap            rawbmp      = LoadImagetoBMP(rawImage);
            Bitmap            filteredbmp = FilterImage(rawbmp);
            Image <Bgr, Byte> rawImg      = new Image <Bgr, Byte>(rawbmp);

            rawImg = rawImg.SmoothGaussian(3, 3, .1, .1);
            rawImg.Save("TestRawImage.jpg");
            Image <Gray, Byte> filteredImg = rawImg.Canny(80.0, 200.0);

            filteredImg.Save("TestFiltered.jpg");

            EdgeDetection edge = new EdgeDetection();

            edge.bitmap = filteredImg.ToBitmap();
            System.Drawing.Point start = new System.Drawing.Point();
            System.Drawing.Point end   = new System.Drawing.Point();

            start.X = (int)_startPoint.X;
            start.Y = (int)_startPoint.Y;
            end.X   = (int)_endPoint.X;
            end.Y   = (int)_endPoint.Y;

            edge.CreateParametricLine(start, end);

            List <System.Drawing.Color> colorList = new List <System.Drawing.Color>();
            List <PointF> points = new List <PointF>();

            edge.GetPixelsPoints(colorList, points);
            int           indexMaxPoint    = edge.FindMaxPixelIntensity(colorList);
            List <double> colorGradient    = edge.GetGradientPoints(colorList);
            int           indexMaxGradient = edge.FindMaxGradient(colorGradient);

            Bitmap overlaybmp = LoadImagetoBMP(overlayImage);

            DrawEllipse(overlaybmp, points[indexMaxGradient]);

            overlayImage.Source = LoadBMPtoImage(overlaybmp);

            System.Windows.Point imagePoint = new System.Windows.Point(points[indexMaxGradient].X, points[indexMaxGradient].Y);
            return(imagePoint);
        }
        /// <summary>
        /// ビデオ描画
        /// </summary>
        /// <param name="sender">オブジェクト</param>
        /// <param name="eventArgs">NewFrameEventのデータ</param>
        private async void VideoRendering(object sender, NewFrameEventArgs eventArgs)
        {
            Bitmap bitmap = (Bitmap)eventArgs.Frame.Clone();

            if (checkBoxImgProcOn.Checked == true)
            {
                EdgeDetection proc    = new EdgeDetection(bitmap);
                bool          bResult = await Task.Run(() => proc.GoImgProc());

                if (bResult)
                {
                    pictureBox.Image = proc.BitmapAfter;
                }
            }
            else
            {
                pictureBox.Image = bitmap;
            }

            return;
        }
        public Bitmap SelectGetBitmap(string _strImgName)
        {
            Bitmap bitmap = null;

            switch (_strImgName)
            {
            case ComInfo.IMG_NAME_EDGE_DETECTION:
                EdgeDetection edge = (EdgeDetection)m_imgProc;
                bitmap = edge.BitmapAfter;
                break;

            case ComInfo.IMG_NAME_GRAY_SCALE:
                GrayScale gray = (GrayScale)m_imgProc;
                bitmap = gray.BitmapAfter;
                break;

            case ComInfo.IMG_NAME_BINARIZATION:
                Binarization binarization = (Binarization)m_imgProc;
                bitmap = binarization.BitmapAfter;
                break;

            case ComInfo.IMG_NAME_GRAY_SCALE_2DIFF:
                GrayScale2Diff gray2Diff = (GrayScale2Diff)m_imgProc;
                bitmap = gray2Diff.BitmapAfter;
                break;

            case ComInfo.IMG_NAME_COLOR_REVERSAL:
                ColorReversal colorReversal = (ColorReversal)m_imgProc;
                bitmap = colorReversal.BitmapAfter;
                break;

            default:
                break;
            }

            return(bitmap);
        }
Exemple #14
0
 private void FindComponents()
 {
     _edgeDetection = transform.Find("Camera").GetComponent<EdgeDetection>();
     _camera = transform.Find("Camera").GetComponent<Camera>();
 }