private void ValidateAndLoadImage(string file) { if (string.IsNullOrEmpty(file)) { return; } // Validate the file try { sourceImage = new Bitmap(file); } catch (System.ArgumentException ex) { throw new Galatea.TeaArgumentException("Invalid image type.", ex); } // Display in the User Control SetDisplayImage(sourceImage); // Stream Bitmap to Recognition Manager ImagingContextStream stream = ImagingContextStream.FromImage(displayImage); Program.Engine.ExecutiveFunctions.StreamContext(this, Program.Engine.Vision.ImageAnalyzer, ContextType.Machine, InputType.Visual, stream, typeof(Bitmap)); // Get Blob blobImage = Program.Engine.Vision.ImageAnalyzer.ContextBlobImage; }
internal string GetShapeResponse(string filename) { ImagingContextStream stream; using (Bitmap bitmap = new Bitmap(filename)) { if (VisualProcessor.ImagingSettings.DebugRecognitionSaveImages) { bitmap.Save("bitmap.png", System.Drawing.Imaging.ImageFormat.Png); } stream = ImagingContextStream.FromImage(bitmap); } TestEngine.ExecutiveFunctions.StreamContext(TestEngine, TestEngine.Vision.ImageAnalyzer, ContextType.Machine, InputType.Visual, stream, typeof(Bitmap)); string result = TestEngine.ExecutiveFunctions.GetResponse(TestEngine.AI.LanguageModel, "What SHAPE?"); // Verify Creator if (NamedTemplate.FriendlyName.Equals("I don't know", StringComparison.CurrentCultureIgnoreCase)) { // Creator is Recognition Model } else { Assert.AreEqual(_creator, NamedTemplate.Creator); } // Finalize return(result); }
protected static ImagingContextStream GetImagingContextStream(string fileName) { if (!File.Exists(fileName)) { throw new FileNotFoundException("File not Found!", new FileInfo(fileName).FullName); } using (Bitmap bitmap = new Bitmap(fileName)) { return(ImagingContextStream.FromImage(bitmap)); } }
private void ValidateAndLoadImage(string file) { if (string.IsNullOrEmpty(file)) { return; } string errorMessage = null; // Validate the file try { sourceImage = new Bitmap(file); } catch (System.ArgumentException ex) { errorMessage = "Invalid image type."; Program.Engine.Debugger.HandleTeaException(new Galatea.TeaArgumentException(errorMessage, ex), this); } if (Settings.Default.ImagingSettings.DebugRecognitionSaveImages) { ImageDump(sourceImage, "Load"); } // Display in the User Control SetDisplayImage(sourceImage); StaticMode = true; // Stream Bitmap to Recognition Manager ImagingContextStream stream = ImagingContextStream.FromImage(displayImage); try { Program.Engine.ExecutiveFunctions.StreamContext(this, Program.Engine.Vision.ImageAnalyzer, ContextType.Machine, InputType.Visual, stream, typeof(Bitmap)); } catch (TeaImagingException ex) { Program.Engine.Debugger.HandleTeaException(ex, this); } // Notify if Error if (Program.Engine.Debugger.Exception != null) { if (errorMessage == null) { errorMessage = string.Format( CultureInfo.CurrentCulture, Program.Engine.Debugger.ErrorMessage, Galatea.Globalization.ProviderResources.ImagingModel_Provider_Name); } // Send Error Notification to Speech Module SmartEngine.AI.LanguageModel.SpeechModule.TextToSpeech.Speak(errorMessage, this); //Program.BaseForm.Chatbot.SendResponse(errorMessage); // Restore Debugger Error Status Program.Engine.Debugger.ClearError(); } }