public Task <bool> Initialize() { _cameraResolution = PhotoCapture.SupportedResolutions.OrderByDescending((res) => res.width * res.height).First(); FrameHeight = _cameraResolution.height; FrameWidth = _cameraResolution.width; CameraInitializedEventArgs a = new CameraInitializedEventArgs(FrameWidth, FrameHeight, _format); CameraInitialized?.Invoke(this, a); return(Task.FromResult(true)); }
public async Task <bool> Initialize() { #if ENABLE_WINMD_SUPPORT bool initialized = await InitializeMediaCaptureAsyncTask(); CameraInitializedEventArgs args = new CameraInitializedEventArgs(FrameWidth, FrameHeight, _format); CameraInitialized?.Invoke(this, args); return(initialized); #else return(await Task.FromResult(false)); #endif }
public async Task <bool> Initialize() { WebCamDevice[] devices = WebCamTexture.devices; _logger.Log($"Found {devices.Length} devices."); if (devices.Length == 0) { return(false); } WebCamDevice device = devices[0]; foreach (WebCamDevice webcamDevice in devices) { //if (webcamDevice.name == "OBS Virtual Camera") //if (webcamDevice.name == "OBS-Camera") if (webcamDevice.name == "Integrated Camera") { device = webcamDevice; } } // default _targetVideoWidth = 1280; _targetVideoHeight = 720; _cameraTexture = new WebCamTexture(device.name, _targetVideoWidth, _targetVideoHeight); if (_cameraTexture == null) { _logger.LogError("Could not create camera texture."); } ; _logger.Log($"Selected {device.name}"); //Debug.LogFormat("Available resolutions: {0}", string.Join(", ", devices[0].availableResolutions)); FrameWidth = Convert.ToInt32(_targetVideoWidth); FrameHeight = Convert.ToInt32(_targetVideoHeight); CameraInitializedEventArgs args = new CameraInitializedEventArgs(FrameWidth, FrameHeight, ColorFormat.Unknown); CameraInitialized?.Invoke(this, args); return(await Task.FromResult(true)); }
/// <summary> /// Instantiates required textures and registers RGB conversion if requested. /// </summary> private void OnCameraInitialized(object sender, CameraInitializedEventArgs e) { if (Format == ColorFormat.RGB) { _rgb = new Mat(FrameHeight, FrameWidth, CvType.CV_8UC3); _mediaMaterialRGB = new Material(Yuv2RGBNv12Shader); if (_mediaMaterialRGB == null) { throw new InvalidOperationException("Media Material shader not found"); } // A single-component, 8-bit unsigned-normalized-integer format that supports 8 bits for the red channel. _luminance = new Texture2D(FrameWidth, FrameHeight, TextureFormat.R8, false); // A two-component, 16-bit unsigned-normalized-integer format that supports 8 bits for the red channel and 8 bits for the green channel. _chrominance = new Texture2D(FrameWidth / 2, FrameHeight / 2, TextureFormat.RG16, false); _mediaMaterialRGB.SetTexture("luminanceChannel", _luminance); _mediaMaterialRGB.SetTexture("chrominanceChannel", _chrominance); Camera.onPreRender += OnPreRenderCallback; } CameraInitialized?.Invoke(this, e); Initialized = true; }