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); }
/// <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); } }
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); }
public WebCamSpecs( float horizontalFOV, float verticalFOV, float nearClippingPlane, float farClippingPlane, WebcamDeviceNames webcamDeviceName, string deviceName, int horizontalResolution, int verticalResolution ) { HorizontalFOV = horizontalFOV; VerticalFOV = verticalFOV; NearClippingPlane = nearClippingPlane; FarClippingPlane = farClippingPlane; WebcamDeviceName = webcamDeviceName; DeviceName = deviceName; HorizontalResolution = horizontalResolution; VerticalResolution = verticalResolution; }
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); }
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); }