Hello.
I have problem with Emgu cv and Microsoft Speech.
Speech recognition works fine until I turn on face detection (button1_Click).
Where is problem? What I'm doing wrong?
I'm thinking the problem may be in:
sre.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(sre_SpeechRecognized);
and
Application.Idle += new EventHandler(FrameGrabber);
but I don't know how solve this.
- using System;
- using System.Collections.Generic;
- using System.Drawing;
- using System.Windows.Forms;
- using Emgu.CV;
- using Emgu.CV.Structure;
- using Emgu.CV.CvEnum;
- using System.IO;
- using System.Diagnostics;
- using Microsoft.Speech.Recognition;
- using Microsoft.Speech.Synthesis;
- namespace MultiFaceRec
- {
- public partial class FrmPrincipal : Form
- {
- //Declararation of all variables, vectors and haarcascades
- Image
currentFrame; - Capture grabber;
- HaarCascade face;
- HaarCascade eye;
- MCvFont font = new MCvFont(FONT.CV_FONT_HERSHEY_TRIPLEX, 0.5d, 0.5d);
- Image
byte > result, TrainedFace = null; - Image
byte > gray = null; - List
byte >> trainingImages = new Listbyte>>(); - List<string> labels= new List<string>();
- List<string> NamePersons = new List<string>();
- int ContTrain, NumLabels, t;
- string name, names = null;
- SpeechSynthesizer synth = new SpeechSynthesizer();
- public FrmPrincipal()
- {
- InitializeComponent();
- //Load haarcascades for face detection
- face = new HaarCascade("haarcascade_frontalface_default.xml");
- synth.SelectVoice("Microsoft Server Speech Text to Speech Voice (pl-PL, Paulina)");
- synth.SetOutputToDefaultAudioDevice();
- System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo("pl-PL");
- SpeechRecognitionEngine sre = new SpeechRecognitionEngine(ci);
- sre.SetInputToDefaultAudioDevice();
- sre.SpeechRecognized += new EventHandler
(sre_SpeechRecognized); - Choices numbers = new Choices();
- numbers.Add(new string[] { "Pierwszy test aplikacji.", "dwa", "szczyt", "jeden"});
- GrammarBuilder gb = new GrammarBuilder();
- gb.Append(numbers);
- Grammar g = new Grammar(gb);
- sre.LoadGrammar(g);
- sre.RecognizeAsync(RecognizeMode.Multiple);
- try
- {
- //Load of previus trainned faces and labels for each image
- string Labelsinfo = File.ReadAllText(Application.StartupPath + "/TrainedFaces/TrainedLabels.txt");
- string[] Labels = Labelsinfo.Split('%');
- NumLabels = Convert.ToInt16(Labels[0]);
- ContTrain = NumLabels;
- string LoadFaces;
- for (int tf = 1; tf < NumLabels+1; tf++)
- {
- LoadFaces = "face" + tf + ".bmp";
- trainingImages.Add(new Image
byte>(Application.StartupPath + "/TrainedFaces/" + LoadFaces)); - labels.Add(Labels[tf]);
- }
- }
- catch(Exception e)
- {
- //MessageBox.Show(e.ToString());
- MessageBox.Show("Nothing in binary database, please add at least a face(Simply train the prototype with the Add Face Button).", "Triained faces load", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
- }
- }
- private void sre_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
- {
- if (e.Result.Confidence > 0.82)
- {
- label6.Text = e.Result.Text;
- synth.Speak("Powiedziales: ");
- synth.SpeakAsync(label6.Text);
- //label6.Text = "";
- }
- //throw new NotImplementedException();
- return;
- }
- private void button1_Click(object sender, EventArgs e)
- {
- //Initialize the capture device
- grabber = new Capture();
- grabber.QueryFrame();
- //Initialize the FrameGraber event
- Application.Idle += new EventHandler(FrameGrabber);
- button1.Enabled = false;
- }
Replies
Know the answer? Post it — somebody with the same question will find it here.