- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 Kinect v1。我写了一些代码,涉及计算 ARM 和 body 之间的角度。现在想实现语音识别,但是一直没成功。
我的目标:向 Kinect 发出命令。这个命令触发一个函数,它会做一些事情。它所做的事情暂时无关紧要。这是我的代码:
namespace Kinect_Robot
{
using System.IO;
using System.IO.Ports;
using System.Threading;
using System;
using System.Windows;
using System.Windows.Forms;
using System.Windows.Media;
using Microsoft.Kinect;
using Microsoft.Kinect.Toolkit.Fusion;
using System.Windows.Media.Media3D;
using Microsoft.Speech.AudioFormat;
using Microsoft.Speech.Recognition;
using System.Windows.Documents;
using System.Text;
using System.ComponentModel;
using System.Collections.Generic;
public class Angles
{
public double AngleBetweenTwoVectors(Vector3D vectorA, Vector3D vectorB)
{
double dotProduct;
vectorA.Normalize();
vectorB.Normalize();
dotProduct = Vector3D.DotProduct(vectorA, vectorB);
return (double)Math.Acos(dotProduct) / Math.PI * 180;
}
public byte[] GetVector(Skeleton skeleton)
{
Vector3D ShoulderCenter = new Vector3D(skeleton.Joints[JointType.ShoulderCenter].Position.X, skeleton.Joints[JointType.ShoulderCenter].Position.Y, skeleton.Joints[JointType.ShoulderCenter].Position.Z);
Vector3D RightShoulder = new Vector3D(skeleton.Joints[JointType.ShoulderRight].Position.X, skeleton.Joints[JointType.ShoulderRight].Position.Y, skeleton.Joints[JointType.ShoulderRight].Position.Z);
Vector3D LeftShoulder = new Vector3D(skeleton.Joints[JointType.ShoulderLeft].Position.X, skeleton.Joints[JointType.ShoulderLeft].Position.Y, skeleton.Joints[JointType.ShoulderLeft].Position.Z);
Vector3D RightElbow = new Vector3D(skeleton.Joints[JointType.ElbowRight].Position.X, skeleton.Joints[JointType.ElbowRight].Position.Y, skeleton.Joints[JointType.ElbowRight].Position.Z);
Vector3D LeftElbow = new Vector3D(skeleton.Joints[JointType.ElbowLeft].Position.X, skeleton.Joints[JointType.ElbowLeft].Position.Y, skeleton.Joints[JointType.ElbowLeft].Position.Z);
Vector3D RightWrist = new Vector3D(skeleton.Joints[JointType.WristRight].Position.X, skeleton.Joints[JointType.WristRight].Position.Y, skeleton.Joints[JointType.WristRight].Position.Z);
Vector3D LeftWrist = new Vector3D(skeleton.Joints[JointType.WristLeft].Position.X, skeleton.Joints[JointType.WristLeft].Position.Y, skeleton.Joints[JointType.WristLeft].Position.Z);
Vector3D UpVector = new Vector3D(0.0, 1.0, 0.0);
double AngleRightElbow = AngleBetweenTwoVectors(RightElbow - RightShoulder, RightElbow - RightWrist);
double AngleRightShoulder = AngleBetweenTwoVectors(UpVector, RightShoulder - RightElbow);
double AngleLeftElbow = AngleBetweenTwoVectors(LeftElbow - LeftShoulder, LeftElbow - LeftWrist);
double AngleLeftShoulder = AngleBetweenTwoVectors(UpVector, LeftShoulder - LeftElbow);
byte[] Angles = { Convert.ToByte(AngleRightElbow), Convert.ToByte(180 - AngleRightShoulder), Convert.ToByte(180 - AngleLeftElbow), Convert.ToByte(AngleLeftShoulder) };
return Angles;
}
}
/// Interaction logic for MainWindow.xaml
public partial class MainWindow : Window
{
SerialPort ArduinoPort;
public Boolean PortOpen = false;
/// Width of output drawing
private const float RenderWidth = 640.0f;
/// Height of our output drawing
private const float RenderHeight = 480.0f;
/// Thickness of drawn joint lines
private const double JointThickness = 3;
/// Thickness of body center ellipse
private const double BodyCenterThickness = 10;
/// Thickness of clip edge rectangles
private const double ClipBoundsThickness = 10;
/// Brush used to draw skeleton center point
private readonly Brush centerPointBrush = Brushes.Blue;
/// Brush used for drawing joints that are currently tracked
private readonly Brush trackedJointBrush = new SolidColorBrush(Color.FromArgb(255, 68, 192, 68));
/// Brush used for drawing joints that are currently inferred
private readonly Brush inferredJointBrush = Brushes.Yellow;
/// Pen used for drawing bones that are currently tracked
private readonly Pen trackedBonePen = new Pen(Brushes.Green, 6);
/// Pen used for drawing bones that are currently inferred
private readonly Pen inferredBonePen = new Pen(Brushes.Gray, 1);
/// Active Kinect sensor
private KinectSensor sensor;
private SpeechRecognitionEngine speechEngine;
/// Drawing group for skeleton rendering output
private DrawingGroup drawingGroup;
/// Drawing image that we will display
private DrawingImage imageSource;
/// Initializes a new instance of the MainWindow class.
public MainWindow()
{
InitializeComponent();
}
private static RecognizerInfo GetKinectRecognizer()
{
foreach (RecognizerInfo recognizer in SpeechRecognitionEngine.InstalledRecognizers())
{
string value;
recognizer.AdditionalInfo.TryGetValue("Kinect", out value);
if ("True".Equals(value, StringComparison.OrdinalIgnoreCase) && "en-US".Equals(recognizer.Culture.Name, StringComparison.OrdinalIgnoreCase))
{
return recognizer;
}
}
return null;
}
private static void RenderClippedEdges(Skeleton skeleton, DrawingContext drawingContext)
{
if (skeleton.ClippedEdges.HasFlag(FrameEdges.Bottom))
{
drawingContext.DrawRectangle(
Brushes.Red,
null,
new Rect(0, RenderHeight - ClipBoundsThickness, RenderWidth, ClipBoundsThickness));
}
if (skeleton.ClippedEdges.HasFlag(FrameEdges.Top))
{
drawingContext.DrawRectangle(
Brushes.Red,
null,
new Rect(0, 0, RenderWidth, ClipBoundsThickness));
}
if (skeleton.ClippedEdges.HasFlag(FrameEdges.Left))
{
drawingContext.DrawRectangle(
Brushes.Red,
null,
new Rect(0, 0, ClipBoundsThickness, RenderHeight));
}
if (skeleton.ClippedEdges.HasFlag(FrameEdges.Right))
{
drawingContext.DrawRectangle(
Brushes.Red,
null,
new Rect(RenderWidth - ClipBoundsThickness, 0, ClipBoundsThickness, RenderHeight));
}
}
private void WindowLoaded(object sender, RoutedEventArgs e)
{
// Create the drawing group we'll use for drawing
this.drawingGroup = new DrawingGroup();
// Create an image source that we can use in our image control
this.imageSource = new DrawingImage(this.drawingGroup);
// Display the drawing using our image control
Image.Source = this.imageSource;
// Look through all sensors and start the first connected one.
// This requires that a Kinect is connected at the time of app startup.
// To make your app robust against plug/unplug,
// it is recommended to use KinectSensorChooser provided in Microsoft.Kinect.Toolkit (See components in Toolkit Browser).
foreach (var potentialSensor in KinectSensor.KinectSensors)
{
if (potentialSensor.Status == KinectStatus.Connected)
{
this.sensor = potentialSensor;
break;
}
}
if (null != this.sensor)
{
// Turn on the skeleton stream to receive skeleton frames
this.sensor.SkeletonStream.Enable();
// Add an event handler to be called whenever there is new color frame data
this.sensor.SkeletonFrameReady += this.SensorSkeletonFrameReady;
// Start the sensor!
try
{
this.sensor.Start();
}
catch (IOException)
{
this.sensor = null;
}
}
if (null == this.sensor)
{
this.statusBarText.Text = Properties.Resources.NoKinectReady;
}
RecognizerInfo ri = GetKinectRecognizer();
if (null != ri)
{
this.speechEngine = new SpeechRecognitionEngine(ri.Id);
using (var memoryStream = new MemoryStream(Encoding.ASCII.GetBytes(Properties.Resources.SpeechGrammar)))
{
var g = new Grammar(memoryStream);
speechEngine.LoadGrammar(g);
}
speechEngine.SpeechRecognized += SpeechRecognized;
speechEngine.SpeechRecognitionRejected += SpeechRejected;
speechEngine.SetInputToAudioStream(
sensor.AudioSource.Start(), new SpeechAudioFormatInfo(EncodingFormat.Pcm, 16000, 16, 1, 32000, 2, null));
speechEngine.RecognizeAsync(RecognizeMode.Multiple);
}
else
{
this.statusBarText.Text = Properties.Resources.NoSpeechRecognizer;
}
}
private void WindowClosing(object sender, System.ComponentModel.CancelEventArgs e)
{
if (null != this.sensor)
{
this.sensor.AudioSource.Stop();
try
{
ArduinoPort.Close();
}
catch (NullReferenceException) { };
this.sensor.Stop();
this.sensor = null;
}
if (null != this.speechEngine)
{
this.speechEngine.SpeechRecognized -= SpeechRecognized;
this.speechEngine.SpeechRecognitionRejected -= SpeechRejected;
this.speechEngine.RecognizeAsyncStop();
}
}
private void SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
// Speech utterance confidence below which we treat speech as if it hadn't been heard
const double ConfidenceThreshold = 0.3;
if (e.Result.Confidence >= ConfidenceThreshold)
{
switch (e.Result.Semantics.Value.ToString())
{
case "SPREAD":
this.CommandTextBox.Text = "Spread";
break;
case "SOMETHING1":
break;
case "SOMETHING2":
break;
case "SOMETHING3":
break;
}
}
}
private void SpeechRejected(object sender, SpeechRecognitionRejectedEventArgs e)
{
}
private void SensorSkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)
{
Skeleton[] skeletons = new Skeleton[0];
using (SkeletonFrame skeletonFrame = e.OpenSkeletonFrame())
{
if (skeletonFrame != null)
{
skeletons = new Skeleton[skeletonFrame.SkeletonArrayLength];
skeletonFrame.CopySkeletonDataTo(skeletons);
}
}
using (DrawingContext dc = this.drawingGroup.Open())
{
// Draw a transparent background to set the render size
dc.DrawRectangle(Brushes.Black, null, new Rect(0.0, 0.0, RenderWidth, RenderHeight));
if (skeletons.Length != 0)
{
foreach (Skeleton skel in skeletons)
{
RenderClippedEdges(skel, dc);
if (skel.TrackingState == SkeletonTrackingState.Tracked)
{
this.DrawBonesAndJoints(skel, dc);
Angles MyAngles = new Angles(); //Instance of class angles
byte[] ReadyAngles = MyAngles.GetVector(skel);//Save angles to byte array and call GetVector
RightElbow.Text = ReadyAngles[0].ToString(); //Write Angle into textbox
RightShoulder.Text = ReadyAngles[1].ToString();//Write Angle into textbox
LeftElbow.Text = ReadyAngles[2].ToString();//Write Angle into textbox
LeftShoulder.Text = ReadyAngles[3].ToString();//Write Angle into textbox
byte[] SequenceStart = { 255 };
//if (ArduinoPort.IsOpen)
if (PortOpen)
{
ArduinoPort.Write(SequenceStart, 0, 1);
ArduinoPort.Write(ReadyAngles, 0, 4);
}
}
else if (skel.TrackingState == SkeletonTrackingState.PositionOnly)
{
dc.DrawEllipse(
this.centerPointBrush,
null,
this.SkeletonPointToScreen(skel.Position),
BodyCenterThickness,
BodyCenterThickness);
}
}
}
// prevent drawing outside of our render area
this.drawingGroup.ClipGeometry = new RectangleGeometry(new Rect(0.0, 0.0, RenderWidth, RenderHeight));
}
}
private void DrawBonesAndJoints(Skeleton skeleton, DrawingContext drawingContext)
{
// Render Torso
this.DrawBone(skeleton, drawingContext, JointType.Head, JointType.ShoulderCenter);
this.DrawBone(skeleton, drawingContext, JointType.ShoulderCenter, JointType.ShoulderLeft);
this.DrawBone(skeleton, drawingContext, JointType.ShoulderCenter, JointType.ShoulderRight);
this.DrawBone(skeleton, drawingContext, JointType.ShoulderCenter, JointType.Spine);
this.DrawBone(skeleton, drawingContext, JointType.Spine, JointType.HipCenter);
this.DrawBone(skeleton, drawingContext, JointType.HipCenter, JointType.HipLeft);
this.DrawBone(skeleton, drawingContext, JointType.HipCenter, JointType.HipRight);
// Left Arm
this.DrawBone(skeleton, drawingContext, JointType.ShoulderLeft, JointType.ElbowLeft);
this.DrawBone(skeleton, drawingContext, JointType.ElbowLeft, JointType.WristLeft);
this.DrawBone(skeleton, drawingContext, JointType.WristLeft, JointType.HandLeft);
// Right Arm
this.DrawBone(skeleton, drawingContext, JointType.ShoulderRight, JointType.ElbowRight);
this.DrawBone(skeleton, drawingContext, JointType.ElbowRight, JointType.WristRight);
this.DrawBone(skeleton, drawingContext, JointType.WristRight, JointType.HandRight);
// Left Leg
this.DrawBone(skeleton, drawingContext, JointType.HipLeft, JointType.KneeLeft);
this.DrawBone(skeleton, drawingContext, JointType.KneeLeft, JointType.AnkleLeft);
this.DrawBone(skeleton, drawingContext, JointType.AnkleLeft, JointType.FootLeft);
// Right Leg
this.DrawBone(skeleton, drawingContext, JointType.HipRight, JointType.KneeRight);
this.DrawBone(skeleton, drawingContext, JointType.KneeRight, JointType.AnkleRight);
this.DrawBone(skeleton, drawingContext, JointType.AnkleRight, JointType.FootRight);
// Render Joints
foreach (Joint joint in skeleton.Joints)
{
Brush drawBrush = null;
if (joint.TrackingState == JointTrackingState.Tracked)
{
drawBrush = this.trackedJointBrush;
}
else if (joint.TrackingState == JointTrackingState.Inferred)
{
drawBrush = this.inferredJointBrush;
}
if (drawBrush != null)
{
drawingContext.DrawEllipse(drawBrush, null, this.SkeletonPointToScreen(joint.Position), JointThickness, JointThickness);
}
}
}
private Point SkeletonPointToScreen(SkeletonPoint skelpoint)
{
// Convert point to depth space.
// We are not using depth directly, but we do want the points in our 640x480 output resolution.
DepthImagePoint depthPoint = this.sensor.CoordinateMapper.MapSkeletonPointToDepthPoint(skelpoint, DepthImageFormat.Resolution640x480Fps30);
return new Point(depthPoint.X, depthPoint.Y);
}
private void DrawBone(Skeleton skeleton, DrawingContext drawingContext, JointType jointType0, JointType jointType1)
{
Joint joint0 = skeleton.Joints[jointType0];
Joint joint1 = skeleton.Joints[jointType1];
// If we can't find either of these joints, exit
if (joint0.TrackingState == JointTrackingState.NotTracked ||
joint1.TrackingState == JointTrackingState.NotTracked)
{
return;
}
// Don't draw if both points are inferred
if (joint0.TrackingState == JointTrackingState.Inferred &&
joint1.TrackingState == JointTrackingState.Inferred)
{
return;
}
// We assume all drawn bones are inferred unless BOTH joints are tracked
Pen drawPen = this.inferredBonePen;
if (joint0.TrackingState == JointTrackingState.Tracked && joint1.TrackingState == JointTrackingState.Tracked)
{
drawPen = this.trackedBonePen;
}
drawingContext.DrawLine(drawPen, this.SkeletonPointToScreen(joint0.Position), this.SkeletonPointToScreen(joint1.Position));
}
private void CheckBoxSeatedModeChanged(object sender, RoutedEventArgs e)
{
if (null != this.sensor)
{
if (this.checkBoxSeatedMode.IsChecked.GetValueOrDefault())
{
this.sensor.SkeletonStream.TrackingMode = SkeletonTrackingMode.Seated;
}
else
{
this.sensor.SkeletonStream.TrackingMode = SkeletonTrackingMode.Default;
}
}
}
private void CheckBoxConnectArduino(object sender, RoutedEventArgs e)
{
if (this.checkArduinoConnected.IsChecked.GetValueOrDefault())
{
string MyCOM = "COM10";
ArduinoPort = new SerialPort(MyCOM, 9600);
ArduinoPort.Open();
Thread.Sleep(200);
byte[] SequenceStart = { 254, 0, 0, 0, 0 };
if (ArduinoPort.IsOpen)
{
PortOpen = true;
ArduinoPort.Write(SequenceStart, 0, 5);
Thread.Sleep(200);
}
int count = ArduinoPort.BytesToRead;
if (count == 2)
{
short Voltage;
double VoltageDouble;
byte[] SerialInBytes = { 0, 0 };
SerialInBytes[0] = Convert.ToByte(ArduinoPort.ReadByte());
SerialInBytes[1] = Convert.ToByte(ArduinoPort.ReadByte());
Voltage = BitConverter.ToInt16(SerialInBytes, 0);
VoltageDouble = Voltage * 10.653 / 1000;
string VoltageString = String.Format("{0:0.00}", VoltageDouble);
VoltageTextBox.Text = VoltageString;
}
else
{
System.Windows.Forms.MessageBox.Show("No Arduino connected");
}
}
else
{
ArduinoPort.Close();
PortOpen = false;
}
}
}
}
描述:我有两个类:Angles 和 mainClass。 Angles 类计算角度。这是无关紧要的。在 mainClass 中,我们从一些变量开始。我们还声明了一个语音引擎和传感器。
这是我遇到问题的部分:如您所见,我有一个事件处理程序,它在每一帧调用一个函数。一旦进入此函数 (SensorSkeletonFrameReady),它就会继续绘制骨架并调用该函数的循环。
我的问题:我应该在哪里以及如何实现已经编写好的语音识别代码?
我知道这是一大段代码,但我很感激任何建议!谢谢。
最佳答案
我发现了我的错误。显然我必须启动传感器,然后启动音频流,然后添加骨骼跟踪的事件处理程序。现在可以了。谢谢。
关于c# - 如何在我的骨骼追踪程序中实现语音识别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33789766/
我正在开发一个网站,在不使用任何第三方 API 的情况下使用 Firebase 云消息传递(Chrome 和 Firefox 浏览器)向我的订阅者发送推送通知。推送通知发送工作正常,但我不知道“如何跟
我在尝试追踪此 OutOfMemoryError 时遇到了非常糟糕的时间,非常感谢您的帮助。我的应用程序分为架构部分和一个模块,该模块公开一些基本的 REST WS 以及 Hibernate 进行的数
在 Android 操作系统源代码中(路径:/drivers/staging/android/binder_trace.h),我们有一个名为 binder_trace.h 的文件,并且在 /drive
我正在查看我的 CakePHP 应用程序的 error.log,并看到我定期收到此类信息: 2011-07-28 14:49:39 Warning: Warning (2): Missing argu
我收到了有关我的应用程序中内存泄漏的报告,但我无法准确追踪到底发生了什么。我有一个功能可以取出旧 View 并交换新 View 。我没有使用 NavControllers 或任何 @propertie
这是真气! >_< 我编写了一个庞大而复杂的 Haskell 库。我写了一个小测试程序,到目前为止,我已经花了大约 8 个小时试图弄清楚为什么它一直在我身上崩溃。有时 GHC 会提示“奇怪的封闭类型”
是否有系统的方法来调试导致组件在 React 中重新渲染的原因?我放置了一个简单的 console.log() 来查看它渲染了多少次,但我很难弄清楚是什么导致组件渲染多次,即在我的情况下(4 次)。是
我已经升级到 Django 1.4,现在当我运行我的开发服务器时,我收到以下警告: /home/flc/venvs/myprj/lib/python2.6/site-packages/django/v
我有一个 Web 应用程序在某处存在内存泄漏,但我无法检测到它。我已经尝试过 Chrome 开发者工具,通常效果很好,但我无法追踪负责的代码行。 Chrome 工具给了我太多信息,我无法将内存中的对象
直接从标记调用函数的好处之一是更容易跟踪所调用的内容。我想知道是否有浏览器插件或其他东西支持附加(绑定(bind))到元素的每个事件的“Goto javascript 源函数”。理想情况下,这会将我带
我在工作中使用 darcs 已经一年多了,但我一直在问自己同样的问题: 跟踪导致两个补丁之间依赖的代码行/文件/代码更改的最佳方法是什么?目前我的做法如下: 我使用 darcs changes -i
我知道以前有人问过此类问题,但我无法解决我的疑问。我有一个简单的黑白棋引擎(实际上它玩得很好),它使用下面的类来获得最佳棋步: import java.util.*; import java.util
上下文:我们正在构建用于快速交付 WPF 应用程序的框架。该框架使用 Autofac 作为 IoC 容器,还使用 Prism v1 中的区域。我们正在使用 Microsoft 的并行扩展来安排任务
有什么追踪东西的技巧吗?技术?任何可用于检查函数 x 的调用者的工具(调用堆栈的某些部分显示为 ??? 或被跳过)。 --track-origins=yes 是否会使速度变慢(当我尝试这样做时,我使用
我有一个基于 KnockoutJS 2.2.1 创建的 jQuery 网格插件。到目前为止它进展顺利,但是当插件在一个元素上初始化时,'computed' loadGrid 方法调用 3 次。 为了说
我是这种开发的新手。我正在尝试创建一个涉及 GPS 跟踪的 android 应用程序。我正在使用 Nutiteq,因为我必须使用 openstreetmap 作为默认 map 。请帮助我。 最佳答案
我希望用户能够通过我的应用程序之一跟踪他们的 friend 。该应用程序适用于音乐节。 我一直在想办法做到这一点: 让用户为设备设置昵称(与 UDID 关联),并让用户通过昵称将彼此添加到“好友列表”
有没有办法找到所有者或域名示例,如果我给谷歌的IP,我的工具发现谷歌的IP,这应该以编程方式完成地址最喜欢的编程语言将是VC++其他语言也不是问题 最佳答案 您正在寻找的关键字似乎是WHOIS 通常可
我的 VC++ 项目中有几个包含大量类的 map ,其中一些默认可构造,另一些则不能。尝试构建时,出现“没有合适的默认构造函数可用”错误。问题是错误被列为发生在 map.cpp 的第 173 行,这是
我平均工作(约 20k 行代码,Objective-C 与 C++ 混合),我正在努力寻找 EXC_BAD_ACCESS 错误。 我已经尝试了所有常见的技术(比如启用 NSZombie、guard e
我是一名优秀的程序员,十分优秀!