예제 #1
0
        public Texture2D GenerateTexture(int camIndex)
        {
            GameObject        viewingCam = viewingCamManager.ViewingCameras[camIndex];
            WebcamDeviceNames deviceName = viewingCam.GetComponent <WebCamIdentifier>().DeviceName;
            WebCamSpecs       specs      = WebCamSpecsManager.GetSpecs(deviceName);
            WebCamTexture     webFeed    = viewingCam.GetComponent <WebCamIdentifier>().WebCamFeed;

            int width  = specs.HorizontalResolution;
            int height = specs.VerticalResolution;

            // https://forum.unity.com/threads/webcamtexture-texture2d.154057/
            // Tie the texture to the webcam feed texture associated with a viewing camera
            Texture2D tex = new Texture2D(width, height, TextureFormat.RGBA32, false);

            ////var ptr = webFeed.GetNativeTexturePtr();
            ////Debug.Log(ptr);
            ////Texture2D exTex = Texture2D.CreateExternalTexture(width, height, TextureFormat.RGBA32, false, false, ptr);
            ////Debug.Log("Created external texture");
            //tex.UpdateExternalTexture(webFeed.GetNativeTexturePtr());
            //tex.Apply();
            Graphics.CopyTexture(webFeed, tex);
            tex.name = webFeed.name;

            return(tex);
        }
        public void Update()
        {
            WebCamSpecs specs = WebCamSpecsManager.GetSpecs(WebcamDeviceNames.NULL);

            switch (WebcamDeviceName)
            {
            case WebcamDeviceNames.ADESSO_CYBERTRACK_V10:
                specs = WebCamSpecsManager.GetSpecs(WebcamDeviceNames.ADESSO_CYBERTRACK_V10);
                break;

            case WebcamDeviceNames.LAPTOP_WEBCAM:
                specs = WebCamSpecsManager.GetSpecs(WebcamDeviceNames.LAPTOP_WEBCAM);
                break;

            case WebcamDeviceNames.LOGITECH_C920:
                specs = WebCamSpecsManager.GetSpecs(WebcamDeviceNames.LOGITECH_C920);
                break;

            case WebcamDeviceNames.NULL:
                specs = WebCamSpecsManager.GetSpecs(WebcamDeviceNames.NULL);
                break;
            }

            SetReviewedInfo(specs);
        }
예제 #3
0
 /// <summary>
 /// Retrieves an instance of a WebCamManager and the camera index
 /// to be used to fetch information about a camera.
 /// </summary>
 /// <param name="managerInstance"></param>
 /// <param name="camIndex"></param>
 public void SetInfo(WebCamManager managerInstance, int camIndex)
 {
     if (camIndex < managerInstance.NumWebCams)
     {
         webCamManager    = managerInstance;
         this.camIndex    = camIndex;
         DeviceNameString = managerInstance.WebCams[camIndex].name;
         WebCam           = managerInstance.WebCams[camIndex];
         WebCamFeed       = managerInstance.VideoFeeds[camIndex];
         DeviceName       = WebCamSpecsManager.WebCamDeviceToSpecsName(WebCam);
     }
 }
예제 #4
0
        public List <int> GetIndicesFor(WebcamDeviceNames deviceName)
        {
            List <int> indexList = new List <int>();

            for (int i = 0; i < NumWebCams; i++)
            {
                if (VideoFeeds.Length > i)
                {
                    var specsName = WebCamSpecsManager.WebCamDeviceToSpecsName(WebCams[i]);
                    if (specsName == deviceName)
                    {
                        indexList.Add(i);
                    }
                }
            }

            return(indexList);
        }
예제 #5
0
        public WebCamTexture GetTextureFor(WebcamDeviceNames deviceName)
        {
            for (int i = 0; i < NumWebCams; i++)
            {
                if (VideoFeeds.Length > i)
                {
                    var specsName = WebCamSpecsManager.WebCamDeviceToSpecsName(WebCams[i]);
                    if (specsName == deviceName)
                    {
                        return(VideoFeeds[i]);
                    }
                }
                else
                {
                    Debug.LogError("Inconsistent number of webcams and feeds.");
                    break;
                }
            }

            return(null);
        }
        public GameObject GenerateViewingCamera(int camIndex)
        {
            GameObject viewingCam = new GameObject();
            Camera     cam        = viewingCam.AddComponent <Camera>();

            viewingCam.AddComponent <GUILayer>();
            viewingCam.AddComponent <FlareLayer>();
            // Avoid adding an AudioListener, this messes with Unity
            //viewingCam.AddComponent<AudioListener>();
            viewingCam.name = "ViewingCamera_";
            viewingCam.tag  = TagManager.GetViewingCameraTag();

            // Associate a webcam
            if (webCamManager.WebCams.Length > camIndex)
            {
                WebCamDevice  webCamDevice  = webCamManager.WebCams[camIndex];
                WebCamTexture webCamTexture = null;
                if (webCamManager.VideoFeeds.Length > camIndex)
                {
                    webCamTexture = webCamManager.VideoFeeds[camIndex];
                }

                WebcamDeviceNames webCamDeviceName = WebCamSpecsManager.WebCamDeviceToSpecsName(webCamDevice);
                WebCamSpecs       specs            = WebCamSpecsManager.GetSpecs(webCamDeviceName);

                // Assign attributes from webcam
                WebCamSpecsManager.AssignSpecsToCamera(cam, specs);
                WebCamIdentifier webcamID = viewingCam.AddComponent <WebCamIdentifier>();
                webcamID.SetInfo(webCamManager, camIndex);

                viewingCam.name = "ViewingCamera_" + "(" + camIndex.ToString() + ")";
            }

            cam.depth = -2;

            return(viewingCam);
        }