关于使用kinect播放PPT
来源:互联网 发布:幕墙易云计算手机 编辑:程序博客网 时间:2024/04/30 18:36
最近也找了不少资料,编写了一个使用kinect来播放ppt的程序,基于c#,不足之处大家一起交流
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
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 OFFICECORE = Microsoft.Office.Core;
using POWERPOINT = Microsoft.Office.Interop.PowerPoint;
using System.IO;
using System.Windows.Forms;
using Microsoft.Kinect;
using System.Diagnostics;
using System.ComponentModel;
using System.Globalization;
namespace WpfApplication3
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window, INotifyPropertyChanged
{
POWERPOINT.Application objApp = null;
POWERPOINT.Presentation objPresSet = null;
//POWERPOINT.SlideShowWindows objSSWs;
//POWERPOINT.SlideShowTransition objSST;
POWERPOINT.SlideShowSettings objSSS;
//POWERPOINT.SlideRange objSldRng;
KinectSensor kinectSensor = null;
private BodyFrameReader bodyFrameReader = null;
private Body[] bodies = null;
public MainWindow()
{
InitializeComponent();
this.kinectSensor = KinectSensor.GetDefault();
this.kinectSensor.Open();
this.bodyFrameReader = this.kinectSensor.BodyFrameSource.OpenReader();
if (bodyFrameReader != null)
{
bodyFrameReader.FrameArrived += BodyFrameReader_FrameArrived;
textbox1.Text = "读取骨架数据流1";
}
this.kinectSensor.IsAvailableChanged += this.Sensor_IsAvailableChanged;
}
private void BodyFrameReader_FrameArrived(object sender, BodyFrameArrivedEventArgs e)
{
bool data = false;
using (BodyFrame bodyframe = e.FrameReference.AcquireFrame())
{
if (bodyframe != null)
{
if (this.bodies == null)
{
this.bodies = new Body[bodyframe.BodyCount];
}
bodyframe.GetAndRefreshBodyData(this.bodies);
data = true;
}
}
if (data)
{
foreach (Body body in bodies)
{
if (body.IsTracked)
{
IReadOnlyDictionary<JointType, Joint> joints = body.Joints;
CameraSpacePoint righthand = joints[JointType.HandRight].Position;
//右手的位置获取
CameraSpacePoint righthip = joints[JointType.HipRight].Position;
//右臀位置获获取
CameraSpacePoint lefthand = joints[JointType.HandLeft].Position;
//右手的位置获取
CameraSpacePoint leftthip = joints[JointType.HipLeft].Position;
//右臀位置获获取
textbox1.Text = "读取骨架数据流2";
if (righthand.X - righthip.X > 0.45)
{
System.Windows.Forms.SendKeys.SendWait("{PGDN}");
System.Threading.Thread.Sleep(1000);
textbox1.Text = "右手";
}
if (leftthip.X - lefthand.X > 0.45)
{
System.Windows.Forms.SendKeys.SendWait("{PGUP}");
System.Threading.Thread.Sleep(1000);
textbox1.Text = "左手";
}
/* if (lefthand.X - righthand.X <0.2)
{
System.Windows.Forms.SendKeys.SendWait("{END}");
System.Threading.Thread.Sleep(1000);
textbox1.Text = "结束";
}*/
}
}
}
}
private void Button_Click_1(object sender, RoutedEventArgs e)
{
objApp = new POWERPOINT.Application();
objPresSet = objApp.Presentations.Open(@"C:\Users\xiong\Desktop\text.ppt", OFFICECORE.MsoTriState.msoCTrue, OFFICECORE.MsoTriState.msoFalse, OFFICECORE.MsoTriState.msoFalse);
objSSS = this.objPresSet.SlideShowSettings;
objSSS.Run();
textbox1.Text = "hellow";
openfile();//用于测试是否正常运行
}
private void openfile()
{
if (File.Exists(@"C:\Users\xiong\Desktop\新建文本文档.txt"))
{
FileStream TextFile = File.Open(@"C:\Users\xiong\Desktop\新建文本文档.txt", FileMode.Append);
byte[] Info = { (byte)'h', (byte)'e', (byte)'l', (byte)'l', (byte)'o', (byte)'w' };
TextFile.Write(Info, 0, Info.Length);
TextFile.Close();
textbox2.Text = "打开了!";
}
}
public event PropertyChangedEventHandler PropertyChanged;
private void Sensor_IsAvailableChanged(object sender, IsAvailableChangedEventArgs e)
{
textbox2.Text = "连接成功";
}
private void MainWindow_Closing(object sender, CancelEventArgs e)
{
if (this.bodyFrameReader != null)
{
// BodyFrameReader is IDisposable
this.bodyFrameReader.Dispose();
this.bodyFrameReader = null;
}
if (this.kinectSensor != null)
{
this.kinectSensor.Close();
this.kinectSensor = null;
}
}
}
}
我把PPT放在了桌面上,并且命名为text,大家可以自己改一下名称就可以啦,另外的新建文件夹是将Hellow以不打开txt的形式写入
- 关于使用kinect播放PPT
- 【Kinect】Kinect控制PPT播放
- Kinect-播放ppt
- PPT播放
- [Kinect]关于在Unity3D中使用Kinect的一些研究
- 关于mfc 对powerpoint的操作,控制ppt播放
- Kinect控制PowerPoint播放
- Kinect控制PowerPoint播放
- 使用手机控制PPT播放实现方法(含源码)
- ppt播放进度条问题
- 关于在Unity3D中使用Kinect的一些研究
- 关于使用VideoView播放视频
- PPT转SWF并播放
- PPT播放显示备注技巧
- 网页中播放PPT 幻灯片
- PPT不能播放下一页
- axWebBrowser组件自动播放ppt
- 可调速自动播放ppt
- 正则表达式
- C++中虚函数工作原理和(虚)继承类的内存占用大小计算
- 大数据预科班作业13
- JSON入门Java篇-4-用HashMap来构建JSON
- springmvc+freemark+spring+mybatis+druid示例
- 关于使用kinect播放PPT
- [python]leetcode(49). Group Anagrams
- Java练习(3)
- JAVA基础学习笔记
- Cookie与Session
- CentOS-5的yum源无法使用解决办法
- HDU
- 【第一周】机器学习之无监督学习 学期课程导学
- 文章标题