Example #1
0
 public static void AssignSpecsToCamera(Camera cam, WebCamSpecs specs)
 {
     cam.fieldOfView = specs.VerticalFOV;
     cam.aspect      = (float)((double)specs.HorizontalFOV / (double)specs.VerticalFOV);
     cam.near        = specs.NearClippingPlane;
     cam.far         = specs.FarClippingPlane;
 }
Example #2
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);
        }
 public void SetReviewedInfo(WebCamSpecs specs)
 {
     HorizontalFOV        = specs.HorizontalFOV;
     VerticalFOV          = specs.VerticalFOV;
     NearClippingPlane    = specs.NearClippingPlane;
     FarClippingPlane     = specs.FarClippingPlane;
     DeviceName           = specs.DeviceName;
     HorizontalResolution = specs.HorizontalResolution;
     VerticalResolution   = specs.VerticalResolution;
 }
        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);
        }
Example #6
0
        public static WebCamSpecs GetSpecs(WebcamDeviceNames deviceName)
        {
            WebCamSpecs camSpecs = new WebCamSpecs();

            float             HorizontalFOV;
            float             VerticalFOV;
            float             NearClippingPlane;
            float             FarClippingPlane;
            WebcamDeviceNames WebcamDeviceName;
            string            DeviceName;
            int HorizontalResolution;
            int VerticalResolution;

            switch (deviceName)
            {
            // Dimensions
            // W: 10"W paper 10" away from camera
            // H: 8.5"H paper 11.125" away from camera
            case WebcamDeviceNames.LOGITECH_C920:
                // http://therandomlab.blogspot.com/2013/03/logitech-c920-and-c910-fields-of-view.html
                //HorizontalFOV = 70.42f;
                //VerticalFOV = 43.30f;
                //HorizontalFOV = 26.565f;
                //VerticalFOV = 20.908f;
                // 11.5"W paper 10.75" away from camera
                // 8.5"H paper 10.75" away from camera
                HorizontalFOV        = 2 * 27.095552f;
                VerticalFOV          = 2 * 21.5713071913f;
                NearClippingPlane    = DefaultNearClippingPlane;
                FarClippingPlane     = DefaultFarClippingPlane;
                WebcamDeviceName     = WebcamDeviceNames.LOGITECH_C920;
                DeviceName           = WebcamDeviceName.ToString();
                HorizontalResolution = 640;
                VerticalResolution   = 480;

                camSpecs = new WebCamSpecs(
                    HorizontalFOV,
                    VerticalFOV,
                    NearClippingPlane,
                    FarClippingPlane,
                    WebcamDeviceName,
                    DeviceName,
                    HorizontalResolution,
                    VerticalResolution);

                break;

            // Dimensions
            // W: 10"W paper 12" away from camera
            // H: 8.5"H paper 15" away from camera
            case WebcamDeviceNames.ADESSO_CYBERTRACK_V10:
                //HorizontalFOV = 25.0f;
                //VerticalFOV = 25.0f;
                //HorizontalFOV = 22.620f;
                //VerticalFOV = 15.819f;
                HorizontalFOV        = 2 * 22.620f; // Not verified
                VerticalFOV          = 2 * 15.819f; // Not verified
                NearClippingPlane    = DefaultNearClippingPlane;
                FarClippingPlane     = DefaultFarClippingPlane;
                WebcamDeviceName     = WebcamDeviceNames.ADESSO_CYBERTRACK_V10;
                DeviceName           = WebcamDeviceName.ToString();
                HorizontalResolution = 320;
                VerticalResolution   = 240;

                camSpecs = new WebCamSpecs(
                    HorizontalFOV,
                    VerticalFOV,
                    NearClippingPlane,
                    FarClippingPlane,
                    WebcamDeviceName,
                    DeviceName,
                    HorizontalResolution,
                    VerticalResolution);

                break;

            // Dimensions
            // W: 10"W paper 11" away from camera
            // H: 8.5"H paper 11.75" away from camera
            case WebcamDeviceNames.LAPTOP_WEBCAM:
                //HorizontalFOV = 75.0f;
                //VerticalFOV = 56.25f;
                //HorizontalFOV = 24.4f;
                //VerticalFOV = 19.9f;
                // W: 11"W paper 10" away from camera
                // H: 8.5"H paper 10" away from camera
                HorizontalFOV        = 2 * 28.810793743f;  // Not verified
                VerticalFOV          = 2 * 23.0254920085f; // Not verified
                NearClippingPlane    = DefaultNearClippingPlane;
                FarClippingPlane     = DefaultFarClippingPlane;
                WebcamDeviceName     = WebcamDeviceNames.LAPTOP_WEBCAM;
                DeviceName           = WebcamDeviceName.ToString();
                HorizontalResolution = 640;
                VerticalResolution   = 480;

                camSpecs = new WebCamSpecs(
                    HorizontalFOV,
                    VerticalFOV,
                    NearClippingPlane,
                    FarClippingPlane,
                    WebcamDeviceName,
                    DeviceName,
                    HorizontalResolution,
                    VerticalResolution);

                break;

            case WebcamDeviceNames.NULL:
                HorizontalFOV        = 0.0f;
                VerticalFOV          = 0.0f;
                NearClippingPlane    = 0.0f;
                FarClippingPlane     = 0.0f;
                WebcamDeviceName     = WebcamDeviceNames.NULL;
                DeviceName           = WebcamDeviceName.ToString();
                HorizontalResolution = 0;
                VerticalResolution   = 0;

                camSpecs = new WebCamSpecs(
                    HorizontalFOV,
                    VerticalFOV,
                    NearClippingPlane,
                    FarClippingPlane,
                    WebcamDeviceName,
                    DeviceName,
                    HorizontalResolution,
                    VerticalResolution);
                break;

            default:
                camSpecs = new WebCamSpecs();
                Debug.LogError("Webcam Device name not recognized. To add webcam device, please modify WebCamSpecs class.");
                break;
            }

            return(camSpecs);
        }