// 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); } }
// 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()); } }