人脸检测(Emgu.cv)和微软语音识别。 [英] Face detection (Emgu.cv) and Microsoft speech recognition.

查看:87
本文介绍了人脸检测(Emgu.cv)和微软语音识别。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好。

我有Emgu cv和Microsoft Speech的问题。

语音识别工作正常,直到我打开人脸检测(button1_Click)。 />
哪里有问题?我做错了什么?

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?

我认为问题可能在于:

sre.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(sre_SpeechRecognized);

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<Bgr, Byte> currentFrame;
        Capture grabber;
        HaarCascade face;
        HaarCascade eye;
        MCvFont font = new MCvFont(FONT.CV_FONT_HERSHEY_TRIPLEX, 0.5d, 0.5d);
        Image<Gray, byte> result, TrainedFace = null;
        Image<Gray, byte> gray = null;
        List<Image<Gray, byte>> trainingImages = new List<Image<Gray, byte>>();
        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<SpeechRecognizedEventArgs>(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<Gray, 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("Powiedziałeś: ");
                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;
        }

推荐答案

我不知道问题出在哪里。也许是逻辑问题,因为Emgu.cv是第三方的来源,我不能在我身边测试,我建议你查看你的代码,看看是否有关于SpeechRecognizer使用的错误。

I don't know where is the problem. Maybe is logic problem, Since Emgu.cv is a third-part source, I can not test in my side, I suggest you check your code to see if there is an error about usage of SpeechRecognizer.

以下是如何使用
SpeechRecognizer类


Below is steps of how to use SpeechRecognizer Class



  1. 初始化语音识别器。

  1. Initialize the speech recognizer.

创建语音识别语法。

将语法加载到语音识别器中。

Load the grammar into the speech recognizer.

注册语音识别事件通知。

Register for speech recognition event notification.

为语音识别事件创建处理程序。

Create a handler for the speech recognition event.

documnet中的一个很好的例子,展示如何使用SpeechRecognizer对象。

A good example in the documnet to show how to use SpeechRecognizer object.

希望它有所帮助。

Hope it helps.

最诚挚的问候,

Bob

Bob


这篇关于人脸检测(Emgu.cv)和微软语音识别。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆