コード例 #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);

                foreach (MarkerSettings settings in markerSettingsList)
                {
                    settings.setAllARGameObjectsDisable();
                }

                Aruco.detectMarkers(rgbMat, dictionaryAruco, cornersAruco, idsAruco);

                if (idsAruco.total() > 0)
                {
                    SetMarker();
                }
                else
                {
                    SetMarkerLess();
                }

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

                markerDetector.processFrame(rgbaMat, 1);


                foreach (MarkerSettings settings in markerSettings)
                {
                    settings.setAllARGameObjectsDisable();
                }

                if (shouldMoveARCamera)
                {
                    List <Marker> findMarkers = markerDetector.getFindMarkers();
                    if (findMarkers.Count > 0)
                    {
                        Marker marker = findMarkers [0];

                        if (markerSettings.Length > 0)
                        {
                            MarkerSettings settings = markerSettings [0];

                            if (marker.id == settings.getMarkerId())
                            {
                                transformationM = marker.transformation;
//                                                      Debug.Log ("transformationM " + transformationM.ToString ());


                                GameObject ARGameObject = settings.getARGameObject();
                                if (ARGameObject != null)
                                {
                                    ARM = ARGameObject.transform.localToWorldMatrix * invertZM * transformationM.inverse * invertYM;
                                    //Debug.Log ("arM " + arM.ToString ());
                                    ARGameObject.SetActive(true);
                                    ARUtils.SetTransformFromMatrix(ARCamera.transform, ref ARM);
                                }
                            }
                        }
                    }
                }
                else
                {
                    List <Marker> findMarkers = markerDetector.getFindMarkers();
                    for (int i = 0; i < findMarkers.Count; i++)
                    {
                        Marker marker = findMarkers [i];

                        foreach (MarkerSettings settings in markerSettings)
                        {
                            if (marker.id == settings.getMarkerId())
                            {
                                transformationM = marker.transformation;
//                                                              Debug.Log ("transformationM " + transformationM.ToString ());

                                ARM = ARCamera.transform.localToWorldMatrix * invertYM * transformationM * invertZM;
                                //Debug.Log ("arM " + arM.ToString ());

                                GameObject ARGameObject = settings.getARGameObject();
                                if (ARGameObject != null)
                                {
                                    ARUtils.SetTransformFromMatrix(ARGameObject.transform, ref ARM);
                                    ARGameObject.SetActive(true);
                                }
                            }
                        }
                    }
                }


                Utils.matToTexture2D(rgbaMat, texture, webCamTextureToMatHelper.GetBufferColors());
            }
        }
コード例 #3
0
        // Update is called once per frame
        void Update()
        {
            if (webCamTextureToMatHelper.IsPlaying() && webCamTextureToMatHelper.DidUpdateThisFrame())
            {
                UpdateARCameraTransform();

                Mat rgbaMat = webCamTextureToMatHelper.GetMat();

                markerDetector.processFrame(rgbaMat, 1);


                foreach (MarkerSettings settings in markerSettings)
                {
                    if (!settings.shouldNotSetToInactivePerFrame)
                    {
                        settings.setAllARGameObjectsDisable();
                    }
                    else
                    {
                        GameObject ARGameObject = settings.getARGameObject();
                        if (ARGameObject != null)
                        {
                            DelayableSetActive obj = ARGameObject.GetComponent <DelayableSetActive>();
                            if (obj != null)
                            {
                                obj.SetActive(false, 0.5f);
                            }
                        }
                    }
                }

                List <Marker> findMarkers = markerDetector.getFindMarkers();
                for (int i = 0; i < findMarkers.Count; i++)
                {
                    Marker marker = findMarkers[i];

                    foreach (MarkerSettings settings in markerSettings)
                    {
                        if (marker.id == settings.getMarkerId())
                        {
                            Matrix4x4 transformationM = marker.transformation;

                            // right-handed coordinates system (OpenCV) to left-handed one (Unity)
                            // https://stackoverflow.com/questions/30234945/change-handedness-of-a-row-major-4x4-transformation-matrix
                            Matrix4x4 ARM = invertYM * transformationM * invertYM;

                            // Apply Y-axis and Z-axis refletion matrix. (Adjust the posture of the AR object)
                            ARM = ARM * invertYM * invertZM;

                            ARM = ARCamera.transform.localToWorldMatrix * ARM;

                            //Debug.Log("ARM " + ARM.ToString());

                            GameObject ARGameObject = settings.getARGameObject();
                            if (ARGameObject != null)
                            {
                                ARUtils.SetTransformFromMatrix(ARGameObject.transform, ref ARM);

                                DelayableSetActive obj = ARGameObject.GetComponent <DelayableSetActive>();
                                if (obj != null)
                                {
                                    obj.SetActive(true);
                                }
                                else
                                {
                                    ARGameObject.SetActive(true);
                                }
                            }
                        }
                    }
                }
                Utils.fastMatToTexture2D(rgbaMat, texture);
            }
        }
コード例 #4
0
        // Update is called once per frame
        void Update()
        {
            if (webCamTextureToMatHelper.IsPlaying() && webCamTextureToMatHelper.DidUpdateThisFrame())
            {
                UpdateARCameraTransform();

                Mat rgbaMat = webCamTextureToMatHelper.GetMat();

                markerDetector.processFrame(rgbaMat, 1);


                foreach (MarkerSettings settings in markerSettings)
                {
                    if (!settings.shouldNotSetToInactivePerFrame)
                    {
                        settings.setAllARGameObjectsDisable();
                    }
                    else
                    {
                        GameObject ARGameObject = settings.getARGameObject();
                        if (ARGameObject != null)
                        {
                            DelayableSetActive obj = ARGameObject.GetComponent <DelayableSetActive> ();
                            if (obj != null)
                            {
                                obj.SetActive(false, 0.5f);
                            }
                        }
                    }
                }

                List <Marker> findMarkers = markerDetector.getFindMarkers();
                for (int i = 0; i < findMarkers.Count; i++)
                {
                    Marker marker = findMarkers [i];

                    foreach (MarkerSettings settings in markerSettings)
                    {
                        if (marker.id == settings.getMarkerId())
                        {
                            transformationM = marker.transformation;
                            //Debug.Log ("transformationM " + transformationM.ToString ());

                            ARM = ARCamera.transform.localToWorldMatrix * invertYM * transformationM * invertZM;
                            //Debug.Log ("arM " + arM.ToString ());

                            GameObject ARGameObject = settings.getARGameObject();
                            if (ARGameObject != null)
                            {
                                ARUtils.SetTransformFromMatrix(ARGameObject.transform, ref ARM);

                                DelayableSetActive obj = ARGameObject.GetComponent <DelayableSetActive> ();
                                if (obj != null)
                                {
                                    obj.SetActive(true);
                                }
                                else
                                {
                                    ARGameObject.SetActive(true);
                                }
                            }
                        }
                    }
                }
                Utils.matToTexture2D(rgbaMat, texture, webCamTextureToMatHelper.GetBufferColors());
            }
        }