// Update is called once per frame
        void Update()
        {
            if (webCamTextureToMatHelper.IsPlaying() && webCamTextureToMatHelper.DidUpdateThisFrame())
            {
                Mat rgbaMat = webCamTextureToMatHelper.GetMat();

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

                detector.detect(rgbaMat, keypoints);
//                Debug.Log ("keypoints.ToString() " + keypoints.ToString());
                Features2d.drawKeypoints(rgbMat, keypoints, rgbaMat, Scalar.all(-1), Features2d.NOT_DRAW_SINGLE_POINTS);

                Imgproc.rectangle(rgbaMat, patternRect.tl(), patternRect.br(), new Scalar(255, 0, 0, 255), 5);

                Utils.matToTexture2D(rgbaMat, texture, webCamTextureToMatHelper.GetBufferColors());
            }
        }
Exemple #2
0
        // Update is called once per frame
        void Update()
        {
            if (webCamTextureToMatHelper.IsPlaying() && webCamTextureToMatHelper.DidUpdateThisFrame())
            {
                Mat rgbaMat = webCamTextureToMatHelper.GetMat();

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


                bool patternFound = patternDetector.findPattern(grayMat, patternTrackingInfo);

//              Debug.Log ("patternFound " + patternFound);
                if (patternFound)
                {
                    patternTrackingInfo.computePose(pattern, camMatrix, distCoeffs);

                    //Marker to Camera Coordinate System Convert Matrix
                    transformationM = patternTrackingInfo.pose3d;
                    //Debug.Log ("transformationM " + transformationM.ToString ());

                    if (shouldMoveARCamera)
                    {
                        ARM = ARGameObject.transform.localToWorldMatrix * invertZM * transformationM.inverse * invertYM;
                        //Debug.Log ("ARM " + ARM.ToString ());

                        ARUtils.SetTransformFromMatrix(ARCamera.transform, ref ARM);
                    }
                    else
                    {
                        ARM = ARCamera.transform.localToWorldMatrix * invertYM * transformationM * invertZM;
                        //Debug.Log ("ARM " + ARM.ToString ());

                        ARUtils.SetTransformFromMatrix(ARGameObject.transform, ref ARM);
                    }

                    ARGameObject.GetComponent <DelayableSetActive> ().SetActive(true);
                }
                else
                {
                    ARGameObject.GetComponent <DelayableSetActive> ().SetActive(false, 0.5f);
                }


                Utils.matToTexture2D(rgbaMat, texture, webCamTextureToMatHelper.GetBufferColors());
            }
        }