public char GetPrediction(KerasController ctrl) { using (Bitmap img = new Bitmap(imagePath)) { Bitmap bmp = ImageProcessing.CropWhite(img, 75, 75); bmp.RotateFlip(RotateFlipType.Rotate180FlipNone); bmp.Save(newImagePath); img.Dispose(); return(ctrl.RecogniseImage(newImagePath)); } }
private void StartKerasForUnity() { KerasController ctrl = new KerasController("smallModelBest.json", "smallBest.h5"); while (true) { if (File.Exists(imagePath)) { try { Thread.Sleep(500); char c = GetPrediction(ctrl); File.WriteAllText(responsePath, c.ToString()); Console.WriteLine("Predicted: " + c); File.Delete(newImagePath); File.Delete(imagePath); } catch (Exception e) { Console.WriteLine(e.Message); } } } }