Beispiel #1
0
        // Update is called once per frame
        void Update()
        {
            if (webCamTextureToMatHelper.isPlaying() && webCamTextureToMatHelper.didUpdateThisFrame())
            {
                Mat rgbaMat = webCamTextureToMatHelper.GetMat();


                Imgproc.cvtColor(rgbaMat, rgbMat, Imgproc.COLOR_RGBA2RGB);

                //first find blue objects
                Imgproc.cvtColor(rgbMat, hsvMat, Imgproc.COLOR_RGB2HSV);
                Core.inRange(hsvMat, blue.getHSVmin(), blue.getHSVmax(), thresholdMat);
                morphOps(thresholdMat);
                trackFilteredObject(blue, thresholdMat, hsvMat, rgbMat);
                //then yellows
                Imgproc.cvtColor(rgbMat, hsvMat, Imgproc.COLOR_RGB2HSV);
                Core.inRange(hsvMat, yellow.getHSVmin(), yellow.getHSVmax(), thresholdMat);
                morphOps(thresholdMat);
                trackFilteredObject(yellow, thresholdMat, hsvMat, rgbMat);
                //then reds
                Imgproc.cvtColor(rgbMat, hsvMat, Imgproc.COLOR_RGB2HSV);
                Core.inRange(hsvMat, red.getHSVmin(), red.getHSVmax(), thresholdMat);
                morphOps(thresholdMat);
                trackFilteredObject(red, thresholdMat, hsvMat, rgbMat);
                //then greens
                Imgproc.cvtColor(rgbMat, hsvMat, Imgproc.COLOR_RGB2HSV);
                Core.inRange(hsvMat, green.getHSVmin(), green.getHSVmax(), thresholdMat);
                morphOps(thresholdMat);
                trackFilteredObject(green, thresholdMat, hsvMat, rgbMat);

                Core.putText(rgbMat, "W:" + rgbMat.width() + " H:" + rgbMat.height() + " SO:" + Screen.orientation, new Point(5, rgbMat.rows() - 10), Core.FONT_HERSHEY_SIMPLEX, 1.0, new Scalar(255, 255, 255, 255), 2, Core.LINE_AA, false);

                Utils.matToTexture2D(rgbMat, texture, colors);
            }
        }
                // Update is called once per frame
                void Update ()
                {
                        if (!initDone)
                                return;

                        if (screenOrientation != Screen.orientation) {
                                screenOrientation = Screen.orientation;
                                updateLayout ();
                        }

                        #if UNITY_IOS && !UNITY_EDITOR && (UNITY_4_6_3 || UNITY_4_6_4 || UNITY_5_0_0 || UNITY_5_0_1)
                        if (webCamTexture.width > 16 && webCamTexture.height > 16) {
                        #else
                        if (webCamTexture.didUpdateThisFrame) {
                                #endif

                                Utils.webCamTextureToMat (webCamTexture, rgbMat, colors);

                                if (webCamDevice.isFrontFacing) {
                                        if (webCamTexture.videoRotationAngle == 0) {
                                                Core.flip (rgbMat, rgbMat, 1);
                                        } else if (webCamTexture.videoRotationAngle == 90) {
                                                Core.flip (rgbMat, rgbMat, 0);
                                        }
                                        if (webCamTexture.videoRotationAngle == 180) {
                                                Core.flip (rgbMat, rgbMat, 0);
                                        } else if (webCamTexture.videoRotationAngle == 270) {
                                                Core.flip (rgbMat, rgbMat, 1);
                                        }
                                } else {
                                        if (webCamTexture.videoRotationAngle == 180) {
                                                Core.flip (rgbMat, rgbMat, -1);
                                        } else if (webCamTexture.videoRotationAngle == 270) {
                                                Core.flip (rgbMat, rgbMat, -1);
                                        }
                                }

                                //create some temp fruit objects so that
                                //we can use their member functions/information
                                ColorObject blue = new ColorObject ("blue");
                                ColorObject yellow = new ColorObject ("yellow");
                                ColorObject red = new ColorObject ("red");
                                ColorObject green = new ColorObject ("green");

                                //first find blue objects
                                Imgproc.cvtColor (rgbMat, hsvMat, Imgproc.COLOR_RGB2HSV);
                                Core.inRange (hsvMat, blue.getHSVmin (), blue.getHSVmax (), thresholdMat);
                                morphOps (thresholdMat);
                                trackFilteredObject (blue, thresholdMat, hsvMat, rgbMat);
                                //then yellows
                                Imgproc.cvtColor (rgbMat, hsvMat, Imgproc.COLOR_RGB2HSV);
                                Core.inRange (hsvMat, yellow.getHSVmin (), yellow.getHSVmax (), thresholdMat);
                                morphOps (thresholdMat);
                                trackFilteredObject (yellow, thresholdMat, hsvMat, rgbMat);
                                //then reds
                                Imgproc.cvtColor (rgbMat, hsvMat, Imgproc.COLOR_RGB2HSV);
                                Core.inRange (hsvMat, red.getHSVmin (), red.getHSVmax (), thresholdMat);
                                morphOps (thresholdMat);
                                trackFilteredObject (red, thresholdMat, hsvMat, rgbMat);
                                //then greens
                                Imgproc.cvtColor (rgbMat, hsvMat, Imgproc.COLOR_RGB2HSV);
                                Core.inRange (hsvMat, green.getHSVmin (), green.getHSVmax (), thresholdMat);
                                morphOps (thresholdMat);
                                trackFilteredObject (green, thresholdMat, hsvMat, rgbMat);

                                Utils.matToTexture2D (rgbMat, texture, colors);
                        }

                }

                void OnDisable ()
                {
                        webCamTexture.Stop ();
                }
Beispiel #3
0
        // Update is called once per frame
        void Update()
        {
            if (!initDone)
            {
                return;
            }


            if (screenOrientation != Screen.orientation)
            {
                screenOrientation = Screen.orientation;
                updateLayout();
            }


                                                #if UNITY_IOS && !UNITY_EDITOR && (UNITY_4_6_3 || UNITY_4_6_4 || UNITY_5_0_0 || UNITY_5_0_1)
            if (webCamTexture.width > 16 && webCamTexture.height > 16)
            {
                                                #else
            if (webCamTexture.didUpdateThisFrame)
            {
                                                                #endif

                Utils.webCamTextureToMat(webCamTexture, rgbMat, colors);

                if (webCamDevice.isFrontFacing)
                {
                    if (webCamTexture.videoRotationAngle == 0)
                    {
                        Core.flip(rgbMat, rgbMat, 1);
                    }
                    else if (webCamTexture.videoRotationAngle == 90)
                    {
                        Core.flip(rgbMat, rgbMat, 0);
                    }
                    if (webCamTexture.videoRotationAngle == 180)
                    {
                        Core.flip(rgbMat, rgbMat, 0);
                    }
                    else if (webCamTexture.videoRotationAngle == 270)
                    {
                        Core.flip(rgbMat, rgbMat, 1);
                    }
                }
                else
                {
                    if (webCamTexture.videoRotationAngle == 180)
                    {
                        Core.flip(rgbMat, rgbMat, -1);
                    }
                    else if (webCamTexture.videoRotationAngle == 270)
                    {
                        Core.flip(rgbMat, rgbMat, -1);
                    }
                }



                //create some temp fruit objects so that
                //we can use their member functions/information
                ColorObject blue   = new ColorObject("blue");
                ColorObject yellow = new ColorObject("yellow");
                ColorObject red    = new ColorObject("red");
                ColorObject green  = new ColorObject("green");

                //first find blue objects
                Imgproc.cvtColor(rgbMat, hsvMat, Imgproc.COLOR_RGB2HSV);
                Core.inRange(hsvMat, blue.getHSVmin(), blue.getHSVmax(), thresholdMat);
                morphOps(thresholdMat);
                trackFilteredObject(blue, thresholdMat, hsvMat, rgbMat);
                //then yellows
                Imgproc.cvtColor(rgbMat, hsvMat, Imgproc.COLOR_RGB2HSV);
                Core.inRange(hsvMat, yellow.getHSVmin(), yellow.getHSVmax(), thresholdMat);
                morphOps(thresholdMat);
                trackFilteredObject(yellow, thresholdMat, hsvMat, rgbMat);
                //then reds
                Imgproc.cvtColor(rgbMat, hsvMat, Imgproc.COLOR_RGB2HSV);
                Core.inRange(hsvMat, red.getHSVmin(), red.getHSVmax(), thresholdMat);
                morphOps(thresholdMat);
                trackFilteredObject(red, thresholdMat, hsvMat, rgbMat);
                //then greens
                Imgproc.cvtColor(rgbMat, hsvMat, Imgproc.COLOR_RGB2HSV);
                Core.inRange(hsvMat, green.getHSVmin(), green.getHSVmax(), thresholdMat);
                morphOps(thresholdMat);
                trackFilteredObject(green, thresholdMat, hsvMat, rgbMat);



                Utils.matToTexture2D(rgbMat, texture, colors);
            }
        }

        void OnDisable()
        {
            webCamTexture.Stop();
        }