您的位置 首页 被动

怎么使用Kinect操控51单片机

如何利用Kinect控制51单片机-新建 Visual C# –》 WPF工程,记得右键点击“引用”,添加相应驱动版本的Microsoft.Kinect.dll 和Microsoft.Speech动态库。App.xaml 文件及 App.xaml.cs文件无需改动。

WPF部分:

(1) 新建 Visual C# –》 WPF工程,记住右键点击“引证”,增加相应驱动版别的Microsoft.Kinect.dll 和Microsoft.Speech动态库。App.xaml 文件及 App.xaml.cs文件无需改动。

(2)下面是MainWindow.xaml.cs文件的内容。

using System;

using System.CollecTIons.Generic;

using System.Linq;

using System.Text;

using System.Windows;

using System.Windows.Controls;

using System.Windows.Data;

using System.Windows.Documents;

using System.Windows.Input;

using System.Windows.Media;

using System.Windows.Media.Imaging;

using System.Windows.NavigaTIon;

using System.Windows.Shapes;

using Microsoft.Kinect;

using Microsoft.Speech.AudioFormat;

using Microsoft.Speech.RecogniTIon;

using System.IO;

using System.IO.Ports; //跟串口相关,不能仅仅引证system.IO

using System.Threading; //跟串口相关,线程的引进

namespace VoiceControlLED

{

///

/// InteracTIon logic for MainWindow.xaml

///

public partial class MainWindow : Window

{

KinectSensor myKinect;

///

/// 音控相关

///

RecognizerInfo kinectRecognizerInfo;

SpeechRecognitionEngine recognizer;

KinectAudioSource kinectSource;

Stream audioStream;

///

/// 串口相关

///

///

delegate void HandleInterfaceUpdateDelagate(string text);//托付;此为要点

///

/// 实例化串口

///

SerialPort serialPort1 = new SerialPort();

///

/// 串口初始化函数

///

private void SerialPort1_Init()

{

serialPort1.PortName = “COM1”; //串标语(参阅串口调试帮手)

serialPort1.BaudRate = 9600; //波特率

serialPort1.Parity = Parity.None; //校验位

serialPort1.DataBits = 8; //数据位

serialPort1.StopBits = StopBits.One; //中止位

if (!serialPort1.IsOpen)

{

serialPort1.Open();

}

else

MessageBox.Show(“Port is open!”);

}

///

/// 发送字节数据函数

///

///

///

private int send_command(string Command)

{

try

{

serialPort1.Write(Command);

return (1);

}

catch (Exception)

{

// comm error

return (0);

}

}

private RecognizerInfo findKinectRecognizerInfo()

{

var recognizers = SpeechRecognitionEngine.InstalledRecognizers();

foreach (RecognizerInfo recInfo in recognizers)

{

// look at each recognizer info value to find the one that works for Kinect

if (recInfo.AdditionalInfo.ContainsKey(“Kinect”))

{

string details = recInfo.AdditionalInfo[“Kinect”];

if (details == “True” && recInfo.Culture.Name == “en-US”)

{

// If we get here we have found the info we want to use

return recInfo;

}

}

}

return null;

}

private void createSpeechEngine()

{

kinectRecognizerInfo = findKinectRecognizerInfo();

if (kinectRecognizerInfo == null)

{

MessageBox.Show(“Kinect recognizer not found”, “Kinect Speech Demo”);

Application.Current.Shutdown();

return;

}

try

{

recognizer = new SpeechRecognitionEngine(kinectRecognizerInfo);

}

catch

{

MessageBox.Show(“Speech recognition engine could not be loaded”, “Kinect Speech Demo”);

Application.Current.Shutdown();

}

}

private void buildCommands()

{

Choices commands = new Choices();

commands.Add(“One”);

commands.Add(“Two”);

commands.Add(“Three”);

commands.Add(“Four”);

commands.Add(“Five”);

commands.Add(“Six”);

commands.Add(“Seven”);

commands.Add(“Eight”);

GrammarBuilder grammarBuilder = new GrammarBuilder();

grammarBuilder.Culture = kinectRecognizerInfo.Culture;

grammarBuilder.Append(commands);

Grammar grammar = new Grammar(grammarBuilder);

recognizer.LoadGrammar(grammar);

}

private void setupAudio()

{

try

{

myKinect = KinectSensor.KinectSensors[0];

myKinect.Start();

kinectSource = myKinect.AudioSource;

kinectSource.BeamAngleMode = BeamAngleMode.Automatic;

audioStream = kinectSource.Start();

recognizer.SetInputToAudioStream(audioStream, new SpeechAudioFormatInfo(

EncodingFormat.Pcm, 16000, 16, 1,

32000, 2, null));

recognizer.RecognizeAsync(RecognizeMode.Multiple);

}

catch

{

MessageBox.Show(“Audio stream could not be connected”, “Kinect Speech Demo”);

Application.Current.Shutdown();

}

}

private void SetupSpeechRecognition()

{

声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/ziliao/beidong/346236.html

为您推荐

联系我们

联系我们

在线咨询: QQ交谈

邮箱: kf@86ic.com

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

返回顶部