async void Start() { try { // Create a new instance of the network model class // and asynchronously load the onnx model _networkModel = new NetworkModel(); await _networkModel.LoadModelAsync(); StatusBlock.text = $"Loaded model. Starting camera..."; #if ENABLE_WINMD_SUPPORT // Configure camera to return frames fitting the model input size try { Debug.Log("Creating MediaCaptureUtility and initializing frame reader."); _mediaCaptureUtility = new MediaCaptureUtility(); await _mediaCaptureUtility.InitializeMediaFrameReaderAsync( (uint)InputFeatureSize.x, (uint)InputFeatureSize.y); StatusBlock.text = $"Camera started. Running!"; Debug.Log("Successfully initialized frame reader."); } catch (Exception ex) { StatusBlock.text = $"Failed to start camera: {ex.Message}. Using loaded/picked image."; } // Run processing loop in separate parallel Task, get the latest frame // and asynchronously evaluate Debug.Log("Begin performing inference in frame grab loop."); _isRunning = true; await Task.Run(async() => { while (_isRunning) { if (_mediaCaptureUtility.IsCapturing) { using (var videoFrame = _mediaCaptureUtility.GetLatestFrame()) { await EvaluateFrame(videoFrame); } } else { return; } } }); #endif } catch (Exception ex) { StatusBlock.text = $"Error init: {ex.Message}"; Debug.LogError($"Failed to start model inference: {ex}"); } }