Exemplo n.º 1
0
        // Update is called once per frame
        void Update()
        {
            if (webCamTextureToMatHelper.IsPlaying() && webCamTextureToMatHelper.DidUpdateThisFrame())
            {
                Mat rgbaMat = webCamTextureToMatHelper.GetMat();
//                Debug.Log ("rgbaMat.ToString() " + rgbaMat.ToString ());

//                Imgproc.cvtColor (rgbaMat, grayMat, Imgproc.COLOR_RGBA2GRAY);
//                Imgproc.equalizeHist (grayMat, grayMat);
//
//
//                Imgproc.rectangle (rgbaMat, new Point (0, 0), new Point (rgbaMat.width (), rgbaMat.height ()), new Scalar (0, 0, 0, 0), -1);
//
//
//                if (cascade != null)
//                    cascade.detectMultiScale (grayMat, faces, 1.1, 2, 2, // TODO: objdetect.CV_HAAR_SCALE_IMAGE
//                        new Size (/**grayMat.cols () * 0.2, grayMat.rows () * 0.2**/100, 100), new Size ());
//
//
//                OpenCVForUnity.CoreModule.Rect[] rects = faces.toArray ();
//                for (int i = 0; i < rects.Length; i++) {
//                    //              Debug.Log ("detect faces " + rects [i]);
//
//                    Imgproc.rectangle (rgbaMat, new Point (rects [i].x, rects [i].y), new Point (rects [i].x + rects [i].width, rects [i].y + rects [i].height), new Scalar (255, 0, 0, 255), 4);
//                }

                Imgproc.line(rgbaMat, new Point(0, 0), new Point(rgbaMat.width(), rgbaMat.height()), new Scalar(255, 0, 0, 255), 3);

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

                Utils.fastMatToTexture2D(rgbaMat, texture);
            }
        }
        // Update is called once per n frames (n=frameCount)
        void Update()
        {
            frameCount++;
            frameCount %= samplingRate;
            if (frameCount > 0)
            {
                return;
            }

            if (isImagesInputMode)
            {
                return;
            }

            if (webCamTextureToMatHelper.IsPlaying() && webCamTextureToMatHelper.DidUpdateThisFrame())
            {
                Mat rgbaMat = webCamTextureToMatHelper.GetMat();

                Imgproc.cvtColor(rgbaMat, grayMat, Imgproc.COLOR_RGBA2GRAY);

                if (shouldCaptureFrame)
                {
                    shouldCaptureFrame = false;
                    Mat    frameMat = grayMat.clone();
                    double e        = CaptureFrame(frameMat);
                    if (e > 0)
                    {
                        repErr = e;
                    }
                }

                DrawFrame(grayMat, bgrMat);
                Imgproc.cvtColor(bgrMat, rgbaMat, Imgproc.COLOR_BGR2RGBA);

                Utils.fastMatToTexture2D(rgbaMat, texture);
            }
        }