public float GetHighestFrameRate(HoloLensCameraStream.Resolution forResolution) { if (videoCapture == null) { throw new Exception("Please call this method after a VideoCapture instance has been created."); } return(videoCapture.GetSupportedFrameRatesForResolution(forResolution).OrderByDescending(r => r).FirstOrDefault()); }
public VideoCaptureController() { filepath = System.IO.Path.Combine(Application.persistentDataPath, filename); filepath = filepath.Replace("/", @"\"); #if UNITY_METRO && !UNITY_EDITOR //StartVideoCaptureTest(); try { Resolution cameraResolution = VideoCapture.SupportedResolutions.OrderByDescending((res) => res.width * res.height).First(); //Debug.Log(cameraResolution); float cameraFramerate = VideoCapture.GetSupportedFrameRatesForResolution(cameraResolution).OrderByDescending((fps) => fps).First(); //Debug.Log(cameraFramerate); cameraParameters = new CameraParameters(); cameraParameters.hologramOpacity = 1.0f; cameraParameters.frameRate = cameraFramerate; cameraParameters.cameraResolutionWidth = cameraResolution.width; cameraParameters.cameraResolutionHeight = cameraResolution.height; cameraParameters.pixelFormat = CapturePixelFormat.BGRA32; } catch (System.Exception e) { } //StartVideoCaptureTest(); #endif }
void StartVideoCaptureTest() { DebugManager.Instance.PrintToInfoLog("Cam Init"); Resolution cameraResolution = VideoCapture.SupportedResolutions.OrderByDescending((res) => res.width * res.height).First(); DebugManager.Instance.PrintToInfoLog(cameraResolution.ToString()); float cameraFramerate = VideoCapture.GetSupportedFrameRatesForResolution(cameraResolution).OrderByDescending((fps) => fps).First(); DebugManager.Instance.PrintToInfoLog("Res: " + cameraResolution + ", fps:" + cameraFramerate); VideoCapture.CreateAsync(false, delegate(VideoCapture videoCapture) { if (videoCapture != null) { m_VideoCapture = videoCapture; DebugManager.Instance.PrintToInfoLog("Created VideoCapture Instance!"); CameraParameters cameraParameters = new CameraParameters(); cameraParameters.hologramOpacity = 0.0f; cameraParameters.frameRate = cameraFramerate; cameraParameters.cameraResolutionWidth = cameraResolution.width; cameraParameters.cameraResolutionHeight = cameraResolution.height; cameraParameters.pixelFormat = CapturePixelFormat.BGRA32; m_VideoCapture.StartVideoModeAsync(cameraParameters, VideoCapture.AudioState.ApplicationAndMicAudio, OnStartedVideoCaptureMode); } else { DebugManager.Instance.PrintToInfoLog("Failed to create VideoCapture Instance!"); } }); }
void Start() { //_cameraResolution = VideoCapture.SupportedResolutions.OrderByDescending((res) => res.width * res.height).First(); //_cameraFramerate = VideoCapture.GetSupportedFrameRatesForResolution(_cameraResolution).OrderByDescending((fps) => fps).First(); // full resolution is lagging _cameraResolution = new Resolution() { width = 896, height = 504 }; try { _cameraFramerate = VideoCapture.GetSupportedFrameRatesForResolution(_cameraResolution).OrderByDescending((fps) => fps).First(); } catch (Exception) { _cameraFramerate = 30f; } _mediaPath = Path.Combine(Application.persistentDataPath, MediaPath); var mainCameraGameObject = GameObject.Find("Main Camera"); _cameraBorder = mainCameraGameObject.transform.Find(CameraBorder.name + "(Clone)")?.gameObject; if (_cameraBorder == null) { _cameraBorder = Instantiate(CameraBorder, mainCameraGameObject.transform); } _cameraBorderController = _cameraBorder.GetComponent <CameraBorderController>(); _cameraBorderController.Hide(); }
void OnVideoCaptureCreated(VideoCapture videoCapture) { if (videoCapture != null) { m_VideoCapture = videoCapture; Resolution cameraResolution = VideoCapture.SupportedResolutions.OrderByDescending((res) => res.width * res.height).First(); float cameraFramerate = VideoCapture.GetSupportedFrameRatesForResolution(cameraResolution).OrderByDescending((fps) => fps).First(); CameraParameters cameraParameters = new CameraParameters(); cameraParameters.hologramOpacity = 0.0f; cameraParameters.frameRate = cameraFramerate; cameraParameters.cameraResolutionWidth = cameraResolution.width; cameraParameters.cameraResolutionHeight = cameraResolution.height; cameraParameters.pixelFormat = CapturePixelFormat.BGRA32; m_VideoCapture.StartVideoModeAsync(cameraParameters, VideoCapture.AudioState.MicAudio, OnStartedVideoCaptureMode); } else { Debug.LogError("Failed to create VideoCapture Instance!"); } }
public void OnVideoCapture() { VideoCapture_Icon.SetActive(false); VideoCapture_Icon2.SetActive(true); Resolution cameraResolution = VideoCapture.SupportedResolutions.OrderByDescending((res) => res.width * res.height).First(); //print(cameraResolution); VideoCapture.CreateAsync(false, delegate(VideoCapture videoCapture) { //print("hi1"); if (videoCapture != null) { //print("hi2"); m_VideoCapture = videoCapture; float cameraFramerate = VideoCapture.GetSupportedFrameRatesForResolution(cameraResolution).OrderByDescending((fps) => fps).First(); CameraParameters cameraParameters = new CameraParameters(); cameraParameters.hologramOpacity = 0.0f; cameraParameters.frameRate = cameraFramerate; cameraParameters.cameraResolutionWidth = cameraResolution.width; cameraParameters.cameraResolutionHeight = cameraResolution.height; cameraParameters.pixelFormat = CapturePixelFormat.BGRA32; m_VideoCapture.StartVideoModeAsync(cameraParameters, VideoCapture.AudioState.MicAudio, OnStartedVideoCaptureMode); } }); }
void Start() { Application.targetFrameRate = 60; m_RuntimeModel = ModelLoader.Load(inputModel, false); m_Worker = WorkerFactory.CreateWorker(WorkerFactory.Type.ComputePrecompiled, m_RuntimeModel, false); #if (WEBCAM) #if UNITY_WSA Resolution cameraResolution = VideoCapture.SupportedResolutions.OrderByDescending((res) => res.width * res.height).First(); Debug.Log(cameraResolution); float cameraFramerate = VideoCapture.GetSupportedFrameRatesForResolution(cameraResolution).OrderByDescending((fps) => fps).First(); Debug.Log(cameraFramerate); VideoCapture.CreateAsync(false, delegate(VideoCapture videoCapture) { if (videoCapture != null) { m_VideoCapture = videoCapture; //Debug.Log("Created VideoCapture Instance!"); CameraParameters cameraParameters = new CameraParameters(); cameraParameters.hologramOpacity = 0.0f; cameraParameters.frameRate = cameraFramerate; cameraParameters.cameraResolutionWidth = cameraResolution.width; cameraParameters.cameraResolutionHeight = cameraResolution.height; cameraParameters.pixelFormat = CapturePixelFormat.BGRA32; m_VideoCapture.StartVideoModeAsync(cameraParameters, VideoCapture.AudioState.ApplicationAndMicAudio, OnStartedVideoCaptureMode); } else { Debug.LogError("Failed to create VideoCapture Instance!"); } }); #else m_WebcamTexture = new WebCamTexture(); m_WebcamTexture.Play(); #endif #else var targetRT = RenderTexture.GetTemporary(inputResolutionX, inputResolutionY, 0); Graphics.Blit(inputImage, targetRT, postprocessMaterial); m_Input = new Tensor(targetRT, 3); //m_Input = new Tensor(1, inputResolutionY, inputResolutionX, 3); #endif }
// Use this for initialization void Start() { _cameraResolution = VideoCapture.SupportedResolutions.OrderByDescending((res) => res.width * res.height).First(); _cameraFramerate = VideoCapture.GetSupportedFrameRatesForResolution(_cameraResolution).OrderByDescending((fps) => fps).First(); //_cameraResolution = new Resolution() { width = 896, height = 504 }; //try //{ // _cameraFramerate = VideoCapture.GetSupportedFrameRatesForResolution(_cameraResolution).OrderByDescending((fps) => fps).First(); //} //catch (Exception) //{ // _cameraFramerate = 30f; //} _mediaPath = Application.persistentDataPath;/* Path.Combine(Application.persistentDataPath, MediaPath);*/ }