Jump to content

Frank_D

Verified Members
  • Posts

    18
  • Joined

  • Last visited

Posts posted by Frank_D

  1. On 6/11/2021 at 5:23 AM, Slim said:

    Hi,

    The forum seems not very active. I am also struggling, but maybe what I got so far can help someone.

    The problem with OpenCV is that you need the image to be in CPU memory. So first you need to copy it somehow from GPU.

    I used AsyncGPUReadbackRequest for it. Now I am stuck on how to Apply this modified Texture back to SRWorks.

    Here is my code:

    
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using Vive.Plugin.SR;
    using OpenCvSharp;
    using UnityEngine.Rendering;
    
    public class OpenCVMat : MonoBehaviour
    {
        Texture2D left;
        public Texture2D leftCPU;
        public Texture2D gray;
        Texture2D right;
        int frameIndex;
        int timeIndex;
        Matrix4x4 poseLeft;
        Matrix4x4 poseRight;
    
        AsyncGPUReadbackRequest request;
        private bool initialized;
    
    
        void OnCompleteReadback(AsyncGPUReadbackRequest request)
        {
            if (request.hasError)
            {
                Debug.Log("GPU readback error detected.");
                return;
            }
    
            var tex = new Texture2D(ViveSR_DualCameraImageCapture.UndistortedImageWidth, ViveSR_DualCameraImageCapture.UndistortedImageHeight, TextureFormat.RGBA32, false);
            tex.LoadRawTextureData(request.GetData<uint>());
            tex.Apply();
            Graphics.CopyTexture(tex, leftCPU);
            Destroy(tex);
        }
    
        void Update()
        {
            if(ViveSR.FrameworkStatus == FrameworkStatus.WORKING)
            {
                if (!initialized)
                {
                    InitTextures();
                    initialized = true;
                }
    
                if(initialized && request.done)
                {
                    Mat mat = OpenCvSharp.Unity.TextureToMat(leftCPU);
                    Mat grayMat = new Mat();
                    Cv2.CvtColor(mat, grayMat, ColorConversionCodes.BGRA2GRAY);
                    gray = OpenCvSharp.Unity.MatToTexture(grayMat);
    
                    grayMat.Dispose();
                    mat.Dispose();
    
                    ViveSR_DualCameraImageCapture.GetUndistortedTexture(out left, out right, out frameIndex, out timeIndex, out poseLeft, out poseRight);
                    request = AsyncGPUReadback.Request(left, 0, TextureFormat.RGBA32, OnCompleteReadback);
                }
            }
        }
    
        void InitTextures()
        {
            left = new Texture2D(ViveSR_DualCameraImageCapture.UndistortedImageWidth, ViveSR_DualCameraImageCapture.UndistortedImageHeight, TextureFormat.RGBA32, false);
            leftCPU = new Texture2D(ViveSR_DualCameraImageCapture.UndistortedImageWidth, ViveSR_DualCameraImageCapture.UndistortedImageHeight, TextureFormat.RGBA32, false);
            gray = new Texture2D(ViveSR_DualCameraImageCapture.UndistortedImageWidth, ViveSR_DualCameraImageCapture.UndistortedImageHeight, TextureFormat.RGBA32, false);
            right = new Texture2D(ViveSR_DualCameraImageCapture.UndistortedImageWidth, ViveSR_DualCameraImageCapture.UndistortedImageHeight, TextureFormat.RGBA32, false);
        }
    }

     

    Hi~

    Thank you for your great work!

    Yet this script make the texture transparent and 180 degree rotation.

  2. I am using a VIVE pro which can provide a passthrough view. I am developing a game, but without Unreal or Unity3D.

    So we choose to use C++ with SRwork.

    However, when we try to write the content of passthrough view, we can only get the first frame.

    image.png.744df946fa259e3911ce7cf5e58fa1c5.png

     After 1st frame the res is False ( in  res = ViveSR_GetModuleData(ID_PASSTHROUGH, see_through_element.data(), see_through_count);)

    image.png.552f9c641ce626c666aa8409f38bdbd8.png

    Is there anything wrong?

     

    image.png.26586a454c7ede6e55b23d78f706c994.png

  3. Hi! I am a game developer.

    I just bought one eye pro and one VIVE COSMOS. For VIVE COSMOS, I want to develop a game which is a little like the AR game, I need to see the environment around me. How can I get the content of the six cameras on the headset ? the 'content' means the video stream. since I need to detect the objects around me through the video, it is better to be the RGB video.

×
×
  • Create New...