void Update() { if (guiTex && guiTex.texture == null) { BackgroundRemovalManager backManager = BackgroundRemovalManager.Instance; KinectManager kinectManager = KinectManager.Instance; if (kinectManager && backManager && backManager.enabled /**&& backManager.IsBackgroundRemovalInitialized()*/) { guiTex.texture = backManager.GetForegroundTex(); // user's foreground texture } else if (kinectManager /**&& kinectManager.IsInitialized()*/) { guiTex.texture = kinectManager.GetUsersClrTex(); // color camera texture } } // else if(guiTex && guiTex != null) // { // KinectManager kinectManager = KinectManager.Instance; // if(kinectManager == null) // { // guiTex.texture = null; // } // } }
void Update() { BackgroundRemovalManager backManager = BackgroundRemovalManager.Instance; if (backManager && backManager.IsBackgroundRemovalInitialized()) { Texture foregroundTex = backManager.GetForegroundTex(); if (backgroundImage && (backgroundImage.texture == null) && foregroundTex) { backgroundImage.texture = foregroundTex; } } KinectManager manager = KinectManager.Instance; if (manager && manager.IsInitialized()) { if (currentCameraOffset != adjustedCameraOffset) { // update the camera automatically, according to the current sensor height and angle KinectInterop.SensorData sensorData = manager.GetSensorData(); if (foregroundCamera != null && sensorData != null) { Vector3 fgCameraPos = initialCameraPos; fgCameraPos.x += sensorData.faceOverlayOffset + adjustedCameraOffset; foregroundCamera.transform.position = fgCameraPos; currentCameraOffset = adjustedCameraOffset; } } } }
void Update() { if (rawImage && rawImage.texture == null) { BackgroundRemovalManager backManager = BackgroundRemovalManager.Instance; KinectManager kinectManager = KinectManager.Instance; if (kinectManager && backManager && backManager.enabled /**&& backManager.IsBackgroundRemovalInitialized()*/) { rawImage.texture = backManager.GetForegroundTex(); // user's foreground texture rawImage.rectTransform.localScale = kinectManager.GetColorImageScale(); rawImage.color = Color.white; } else if (kinectManager /**&& kinectManager.IsInitialized()*/) { SimpleBackgroundRemoval simpleBR = GameObject.FindObjectOfType <SimpleBackgroundRemoval>(); bool isSimpleBR = simpleBR && simpleBR.enabled; rawImage.texture = kinectManager.GetUsersClrTex(); // color camera texture rawImage.rectTransform.localScale = kinectManager.GetColorImageScale(); rawImage.color = !isSimpleBR ? Color.white : Color.clear; } } // else if(rawImage && rawImage.texture != null) // { // KinectManager kinectManager = KinectManager.Instance; // if(kinectManager == null) // { // rawImage.texture = null; // rawImage.color = Color.clear; // } // } }
void Update() { if (rawImage && rawImage.texture == null) { BackgroundRemovalManager backManager = BackgroundRemovalManager.Instance; KinectManager kinectManager = KinectManager.Instance; if (kinectManager && backManager && backManager.enabled /**&& backManager.IsBackgroundRemovalInitialized()*/) { rawImage.texture = backManager.GetForegroundTex(); // user's foreground texture rawImage.color = Color.white; } else if (kinectManager /**&& kinectManager.IsInitialized()*/) { rawImage.texture = kinectManager.GetUsersClrTex(); // color camera texture rawImage.color = Color.white; } } // else if(rawImage && rawImage.texture != null) // { // KinectManager kinectManager = KinectManager.Instance; // if(kinectManager == null) // { // rawImage.texture = null; // rawImage.color = Color.clear; // } // } }
/// <summary> /// 获取实时图像 /// </summary> /// <param name="orbbecImageType"></param> /// <returns></returns> public Texture GetOrbbecImage() { if (backManager == null) { backManager = KinectManager.Instance.gameObject.AddComponent <BackgroundRemovalManager>(); } return(backManager.GetForegroundTex()); }
void Update() { if (matRenderer == null || sensorData == null) { return; } if (backgroundRemovalManager != null && alphaTex == null) { // alpha texture alphaTex = backgroundRemovalManager.GetAlphaTex(); if (alphaTex != null) { matRenderer.SetTexture("_AlphaTex", alphaTex); } } if (colorTex == null) { // color texture colorTex = sensorData.colorImageTexture; if (backgroundRemovalManager != null) { colorTex = !backgroundRemovalManager.computeAlphaMaskOnly ? backgroundRemovalManager.GetForegroundTex() : alphaTex; } if (colorTex != null) { matRenderer.SetInt("_TexResX", colorTex.width); matRenderer.SetInt("_TexResY", colorTex.height); matRenderer.SetTexture("_ColorTex", colorTex); } } if (colorTex == null) { return; } if (sensorData.colorDepthBuffer == null) { int bufferLength = sensorData.colorImageWidth * sensorData.colorImageHeight / 2; sensorData.colorDepthBuffer = new ComputeBuffer(bufferLength, sizeof(uint)); matRenderer.SetBuffer("_DepthMap", sensorData.colorDepthBuffer); ScaleRendererTransform(colorTex); } matRenderer.SetFloat("_DepthDistance", depthDistance); matRenderer.SetFloat("_InvDepthVal", invalidDepthValue); // update lighting parameters lighting.UpdateLighting(matRenderer, applyLighting); }
void Update() { BackgroundRemovalManager backManager = BackgroundRemovalManager.Instance; if (thisRenderer && backManager && backManager.IsBackgroundRemovalInitialized()) { if (thisRenderer.sharedMaterial.mainTexture == null) { thisRenderer.sharedMaterial.mainTexture = backManager.GetForegroundTex(); } } }
void Update() { BackgroundRemovalManager backManager = BackgroundRemovalManager.Instance; if (backManager && backManager.IsBackgroundRemovalInitialized()) { GUITexture guiTexture = GetComponent <GUITexture>(); if (guiTexture && guiTexture.texture == null) { guiTexture.texture = backManager.GetForegroundTex(); } } }
void Update() { transform.localPosition = Player.JointOffset; transform.localScale = new Vector3(Player.AspectScale.x * Player.JointScale, -Player.AspectScale.y * Player.JointScale, Player.AspectScale.z * Player.JointScale); // Render the kinect color image onto a quad BackgroundRemovalManager backManager = BackgroundRemovalManager.Instance; if (backManager && backManager.IsBackgroundRemovalInitialized()) { var tex = backManager.GetForegroundTex(); MeshRenderer.material.SetTexture("_MainTex", tex); } }
// Update is called once per frame void Update() { if (foregroundTexture == null || backgroundRemovalManager == null) { return; } if (backgroundRemovalManager.GetForegroundTex() == null) { return; } foregroundTexture = backgroundRemovalManager.GetColorTex(); //foregroundTexture = backgroundRemovalManager.GetForegroundTex(); Debug.Log("assigning foreground tex"); }
void Update() { if (thisRenderer && thisRenderer.sharedMaterial.mainTexture == null) { if (kinectManager && backManager && backManager.enabled /**&& backManager.IsBackgroundRemovalInitialized()*/) { thisRenderer.sharedMaterial.mainTexture = backManager.GetForegroundTex(); } } //else if (thisRenderer && thisRenderer.sharedMaterial.mainTexture != null) //{ // if (KinectManager.Instance == null) // { // thisRenderer.sharedMaterial.mainTexture = null; // } //} }
void Update() { if (thisRenderer && thisRenderer.material.mainTexture == null) { if (kinectManager && backgroundRemovalManager && backgroundRemovalManager.enabled /**&& backManager.IsBackgroundRemovalInitialized()*/) { thisRenderer.material.mainTexture = backgroundRemovalManager.GetForegroundTex(); //Debug.Log("BR-manager: " + backroundRemovalManager + ", user index: " + backroundRemovalManager.playerIndex); } } //else if (thisRenderer && thisRenderer.material.mainTexture != null) //{ // if (KinectManager.Instance == null) // { // thisRenderer.sharedMaterial.mainTexture = null; // } //} }
void Update() { if (rawImage && rawImage.texture == null) { if (kinectManager && backManager && backManager.enabled /**&& backManager.IsBackgroundRemovalInitialized()*/) { rawImage.texture = backManager.GetForegroundTex(); // user's foreground texture rawImage.rectTransform.localScale = kinectManager.GetColorImageScale(backManager.sensorIndex); rawImage.color = Color.white; } } //else if (rawImage && rawImage.texture != null) //{ // if (KinectManager.Instance == null) // { // rawImage.texture = null; // rawImage.color = Color.clear; // } //} }
void Update() { if (faceManager == null) { faceManager = FacetrackingManager.Instance; } if (!kinectManager || !kinectManager.IsInitialized()) { return; } if (!faceManager || !faceManager.IsFaceTrackingInitialized()) { return; } long userId = kinectManager.GetUserIdByIndex(playerIndex); if (userId == 0) { if (targetObject && targetObject.material && targetObject.material.mainTexture != null) { targetObject.material.mainTexture = null; } return; } if (!backManager) { backManager = BackgroundRemovalManager.Instance; if (backManager) { // re-initialize the texture colorTex = null; } } if (!bSkipUpdatingForegroundTex && backManager && backManager.IsBackgroundRemovalInitialized()) { // use foreground image Texture bmForeTex = backManager.GetForegroundTex(); if (bmForeTex is RenderTexture) { foregroundTex = (RenderTexture)bmForeTex; bSkipUpdatingForegroundTex = (foregroundTex != null); } else { if (foregroundTex == null) { foregroundTex = new RenderTexture(bmForeTex.width, bmForeTex.height, 0); } Graphics.Blit(bmForeTex, foregroundTex); bSkipUpdatingForegroundTex = false; } // if (!colorTex) // { // colorTex = new Texture2D(kinectManager.GetColorImageWidth(), kinectManager.GetColorImageHeight(), TextureFormat.ARGB32, false); // } // // try // { // foregroundTex = (RenderTexture)backManager.GetForegroundTex (); // //KinectInterop.RenderTex2Tex2D (foregroundTex, ref colorTex); // } // catch (System.Exception) // { // colorTex = (Texture2D)backManager.GetForegroundTex (); // } } else { // use color camera image if (!colorTex) { colorTex = kinectManager.GetUsersClrTex2D(); } } //faceRect = faceManager.GetFaceColorRect(userId); faceRect = GetHeadJointFaceRect(userId); if (faceRect.width > 0 && faceRect.height > 0) { int faceX = (int)faceRect.x; int faceY = (int)faceRect.y; int faceW = (int)faceRect.width; int faceH = (int)faceRect.height; if (faceX < 0) { faceX = 0; } if (faceY < 0) { faceY = 0; } if (foregroundTex) { if ((faceX + faceW) > foregroundTex.width) { faceW = foregroundTex.width - faceX; } if ((faceY + faceH) > foregroundTex.height) { faceH = foregroundTex.height - faceY; } } else if (colorTex) { if ((faceX + faceW) > colorTex.width) { faceW = colorTex.width - faceX; } if ((faceY + faceH) > colorTex.height) { faceH = colorTex.height - faceY; } } if (faceTex.width != faceW || faceTex.height != faceH) { faceTex.Resize(faceW, faceH); } if (foregroundTex) { KinectInterop.RenderTex2Tex2D(foregroundTex, faceX, foregroundTex.height - faceY - faceH, faceW, faceH, ref faceTex); } else if (colorTex) { Color[] colorPixels = colorTex.GetPixels(faceX, faceY, faceW, faceH, 0); faceTex.SetPixels(colorPixels); faceTex.Apply(); } if (targetObject && !targetObject.gameObject.activeSelf) { targetObject.gameObject.SetActive(true); } if (targetObject && targetObject.material) { targetObject.material.mainTexture = faceTex; } // don't rotate the transform - mesh follows the head rotation if (targetObject.transform.rotation != Quaternion.identity) { targetObject.transform.rotation = Quaternion.identity; } } else { if (targetObject && targetObject.gameObject.activeSelf) { targetObject.gameObject.SetActive(false); } if (targetObject && targetObject.material && targetObject.material.mainTexture != null) { targetObject.material.mainTexture = null; } } }
void Update() { if (matRenderer == null || sensorData == null) { return; } if (alphaTex == null || alphaTex.width != sensorData.colorImageWidth || alphaTex.height != sensorData.colorImageHeight) { // alpha texture alphaTex = backgroundRemovalManager != null?backgroundRemovalManager.GetAlphaTex() : null; if (alphaTex != null) { matRenderer.SetTexture("_AlphaTex", alphaTex); } } if (colorTex == null || colorTex.width != sensorData.colorImageWidth || colorTex.height != sensorData.colorImageHeight) { // color texture colorTex = sensorData.colorImageTexture; if (backgroundRemovalManager != null) { colorTex = !backgroundRemovalManager.computeAlphaMaskOnly ? backgroundRemovalManager.GetForegroundTex() : alphaTex; } if (colorTex != null) { matRenderer.SetInt("_TexResX", colorTex.width); matRenderer.SetInt("_TexResY", colorTex.height); matRenderer.SetTexture("_ColorTex", colorTex); } } if (colorTex == null) { return; } int bufferLength = sensorData.colorImageWidth * sensorData.colorImageHeight / 2; if (sensorData.colorDepthBuffer == null || sensorData.colorDepthBuffer.count != bufferLength) { sensorData.colorDepthBuffer = new ComputeBuffer(bufferLength, sizeof(uint)); matRenderer.SetBuffer("_DepthMap", sensorData.colorDepthBuffer); //Debug.Log("Created colorDepthBuffer with len: " + bufferLength); } matRenderer.SetFloat("_DepthDistance", depthDistance); matRenderer.SetFloat("_InvDepthVal", invalidDepthValue); int curScreenW = foregroundCamera ? foregroundCamera.pixelWidth : Screen.width; int curScreenH = foregroundCamera ? foregroundCamera.pixelHeight : Screen.height; if (lastScreenW != curScreenW || lastScreenH != curScreenH || lastColorW != sensorData.colorImageWidth || lastColorH != sensorData.colorImageHeight) { ScaleRendererTransform(colorTex, curScreenW, curScreenH); } // update lighting parameters lighting.UpdateLighting(matRenderer, applyLighting); }
void Update() { if (faceManager == null) { faceManager = FacetrackingManager.Instance; } //unsafe for editor but can optimise if commented if (!kinectManager || !kinectManager.IsInitialized()) { return; } if (!faceManager || !faceManager.IsFaceTrackingInitialized()) { return; } long userId = kinectManager.GetUserIdByIndex(faceManager.playerIndex); if (userId == 0) { return; } if (!backManager) { backManager = BackgroundRemovalManager.Instance; if (backManager) { // re-initialize the texture colorTex = null; } } if (backManager && backManager.IsBackgroundRemovalInitialized()) { // use foreground image if (!colorTex) { colorTex = new Texture2D(kinectManager.GetColorImageWidth(), kinectManager.GetColorImageHeight(), TextureFormat.ARGB32, false); } try { RenderTexture foregroundTex = (RenderTexture)backManager.GetForegroundTex(); KinectInterop.RenderTex2Tex2D(foregroundTex, ref colorTex); } catch (System.Exception) { colorTex = (Texture2D)backManager.GetForegroundTex(); } } else { // use color camera image colorTex = kinectManager.GetUsersClrTex(); } //faceRect = faceManager.GetFaceColorRect(userId); faceRect = GetHeadJointFaceRect(userId); if (!colorTex || faceRect.width <= 0 || faceRect.height <= 0) { return; } int faceX = (int)faceRect.x; int faceY = (int)faceRect.y; int faceW = (int)faceRect.width; int faceH = (int)faceRect.height; if (faceX < 0) { faceX = 0; } if (faceY < 0) { faceY = 0; } if ((faceX + faceW) > colorTex.width) { faceW = colorTex.width - faceX; } if ((faceY + faceH) > colorTex.height) { faceH = colorTex.height - faceY; } if (faceTex.width != faceW || faceTex.height != faceH) { faceTex.Resize(faceW, faceH); } Color[] colorPixels = colorTex.GetPixels(faceX, faceY, faceW, faceH, 0); faceTex.SetPixels(colorPixels); faceTex.Apply(); if (targetRenderer && targetRenderer.material) { targetRenderer.material.mainTexture = faceTex; } }
void Update() { if (matRenderer == null || sensorInt == null) { return; } if (alphaTex == null) { // alpha texture alphaTex = backgroundRemovalManager.GetAlphaTex(); if (alphaTex != null) { matRenderer.SetTexture("_AlphaTex", alphaTex); } } if (colorTex == null) { // color texture colorTex = !backgroundRemovalManager.computeAlphaMaskOnly ? backgroundRemovalManager.GetForegroundTex() : alphaTex; // sensorInt.pointCloudColorTexture if (colorTex != null) { matRenderer.SetInt("_TexResX", colorTex.width); matRenderer.SetInt("_TexResY", colorTex.height); matRenderer.SetTexture("_ColorTex", colorTex); } } if (colorTex == null || alphaTex == null /**|| foregroundCamera == null*/) { return; } if (sensorInt.pointCloudResolution == DepthSensorBase.PointCloudResolution.DepthCameraResolution) { if (depthImageBuffer == null) { //int depthImageLength = sensorData.depthImageWidth * sensorData.depthImageHeight; //depthImageCopy = new ushort[depthImageLength]; int depthBufferLength = sensorData.depthImageWidth * sensorData.depthImageHeight / 2; depthImageBuffer = KinectInterop.CreateComputeBuffer(depthImageBuffer, depthBufferLength, sizeof(uint)); matRenderer.SetBuffer("_DepthMap", depthImageBuffer); ScaleRendererTransform(colorTex); } if (depthImageBuffer != null && sensorData.depthImage != null) { //KinectInterop.CopyBytes(sensorData.depthImage, sizeof(ushort), depthImageCopy, sizeof(ushort)); int depthBufferLength = sensorData.depthImageWidth * sensorData.depthImageHeight / 2; KinectInterop.SetComputeBufferData(depthImageBuffer, sensorData.depthImage, depthBufferLength, sizeof(uint)); } //Debug.Log("ForegroundBlendRenderer DepthFrameTime: " + lastDepthFrameTime); } else { if (sensorData.colorDepthBuffer == null) { int bufferLength = sensorData.colorImageWidth * sensorData.colorImageHeight / 2; sensorData.colorDepthBuffer = new ComputeBuffer(bufferLength, sizeof(uint)); matRenderer.SetBuffer("_DepthMap", sensorData.colorDepthBuffer); ScaleRendererTransform(colorTex); } //Debug.Log("ForegroundBlendRenderer ColorDepthBufferTime: " + sensorData.lastColorDepthBufferTime); } matRenderer.SetFloat("_DepthDistance", 0f); matRenderer.SetFloat("_InvDepthVal", invalidDepthValue); // update lighting parameters lighting.UpdateLighting(matRenderer, applyLighting); }