// Use this for initialization void Start() { bool loaded = Emgu.TF.Lite.TfLiteInvoke.CheckLibraryLoaded(); _mobilenet = new Emgu.TF.Lite.Models.CocoSsdMobilenetV3(); _liveCameraView = false; WebCamDevice[] devices = WebCamTexture.devices; cameraCount = devices.Length; if (cameraCount == 0) { _liveCameraView = false; } else { _liveCameraView = true; webcamTexture = new WebCamTexture(devices[0].name); baseRotation = transform.rotation; webcamTexture.Play(); //data = new Color32[webcamTexture.width * webcamTexture.height]; } DisplayText.text = "Downloading model, please wait..."; StartCoroutine(_mobilenet.Init()); }
public async Task Init() { //IDelegate d1 = TfLiteInvoke.DefaultGpuDelegate; //IDelegate d2 = TfLiteInvoke.DefaultGpuDelegateV2; //await _mobileNet.Init(null, null, "CocoSsdMobilenetV3", TfLiteInvoke.DefaultGpuDelegateV2); await _mobileNet.Init(); }
// Use this for initialization void Start() { bool tryUseCamera = false; bool loaded = Emgu.TF.Lite.TfLiteInvoke.CheckLibraryLoaded(); _mobilenet = new Emgu.TF.Lite.Models.CocoSsdMobilenetV3(); WebCamDevice[] devices = WebCamTexture.devices; if (tryUseCamera && devices.Length != 0) { _webcamTexture = new WebCamTexture(devices[0].name); _webcamTexture.Play(); } DisplayText.text = "Downloading model, please wait..."; StartCoroutine(_mobilenet.Init()); }
private async void OnButtonClicked(Object sender, EventArgs args) { SetMessage("Please wait while the Coco SSD Mobilenet Model is being downloaded..."); #if !DEBUG try #endif { await _mobilenet.Init(); if (!_mobilenet.Imported) { SetMessage("Failed to initialize mobilenet."); return; } } #if !DEBUG catch (Exception e) { String msg = e.Message.Replace(System.Environment.NewLine, " "); SetMessage(msg); } #endif if (this.TopButton.Text.Equals("Stop")) { // Stop camera #if __IOS__ || __MACOS__ this.StopCaptureSession(); #endif this.TopButton.Text = "Perform Object Detection"; } else { String[] imageFiles = await LoadImages(new string[] { "dog416.png" }); //handle user cancel if (imageFiles == null || (imageFiles.Length > 0 && imageFiles[0] == null)) { SetMessage(""); return; } String imageFileName = imageFiles[0]; if (imageFileName.Equals("Camera Stream")) { #if __MACOS__ || __IOS__ SetMessage(String.Format("Model trained to recognize the following objects: {0}", String.Join("; ", _mobilenet.Labels))); this.TopButton.Text = "Stop"; CheckVideoPermissionAndStart(); #endif } else { Stopwatch watch = Stopwatch.StartNew(); var result = _mobilenet.Recognize(imageFileName, 0.5f); watch.Stop(); Annotation[] annotations = GetAnnotations(result); JpegData jpeg = NativeImageIO.ImageFileToJpeg(imageFileName, annotations); //NativeImageIO.JpegData jpeg = NativeImageIO.ImageFileToJpeg(_imageFiles[0]); //String names = String.Join(";", Array.ConvertAll(result, r => r.Label)); SetImage(jpeg.Raw, jpeg.Width, jpeg.Height); String resStr = String.Format("Detected {1} objects in {0} milliseconds.", watch.ElapsedMilliseconds, result.Length); SetMessage(resStr); } } }