Kinect虚拟试衣间开发(5)-动作识别
2017-08-10 17:45
926 查看
kinect SDK2 比起 Kinect SDK1 多了两个大杀器 Kinect Studio 和 Visual Gesture Builder,这两个软件可以让我们很简单的使用微软自带的机器学习模型,建立自己的姿势库。简单来说就是Kinect Studio 录制和剪辑视频(可以选择自己想要Stream ),然后用Visual Gesture Builder标记视频中的动作,然后生成gba数据库文件。
具体操作过程见 微软发布在 Microsoft Visual Academy 的官方教程视频
这里我用两个动作执行拍照和脱衣的操作
准备过程
添加AdaBoostRech.dll 和 RFRProgressTech.dll 的引用
在解决方案中添加DataBase文件夹,并在文件夹中加入之前软件生产的gba数据库文件
代码部分
变量声明
变量初始化
处理gesture_arrive 事件
清空衣物操作,即把image 控件隐藏
执行拍照操作,使用前面编写的takephoto函数
具体操作过程见 微软发布在 Microsoft Visual Academy 的官方教程视频
这里我用两个动作执行拍照和脱衣的操作
准备过程
添加AdaBoostRech.dll 和 RFRProgressTech.dll 的引用
在解决方案中添加DataBase文件夹,并在文件夹中加入之前软件生产的gba数据库文件
代码部分
变量声明
//路径不对 private readonly string gestureDatabase = "WpfApplication1/WpfApplication1/DataBase/clean.gba"; private readonly string photoDatabase = "C:/Users/Wen/Desktop/实验DataBase/take_photo.gba"; private readonly string cleanGestureName = "clean"; private string photoGestureName = "take_photo"; private VisualGestureBuilderFrameSource vgbFrameSource = null; private VisualGestureBuilderFrameReader vgbFrameReader = null;
变量初始化
// create the vgb source. The associated body tracking ID will be set when a valid body frame arrives from the sensor. this.vgbFrameSource = new VisualGestureBuilderFrameSource(kinectSensor, 0); this.vgbFrameSource.TrackingIdLost += this.Source_TrackingIdLost; // 打开 vgb frames和写入FrameArrive 事件 this.vgbFrameReader = this.vgbFrameSource.OpenReader(); if (this.vgbFrameReader != null) { this.vgbFrameReader.IsPaused = false; this.vgbFrameReader.FrameArrived += this.Reader_GestureFrameArrived; } // 从 gesture database 导入clean gesture using (VisualGestureBuilderDatabase database = new VisualGestureBuilderDatabase(this.gestureDatabase)) { // we could load all available gestures in the database with a call to vgbFrameSource.AddGestures(database.AvailableGestures), // but for this program, we only want to track one discrete gesture from the database, so we'll load it by name foreach (Gesture gesture in database.AvailableGestures) { if (gesture.Name.Equals(this.cleanGestureName)) { this.vgbFrameSource.AddGesture(gesture); } } } using (VisualGestureBuilderDatabase photodatabase = new VisualGestureBuilderDatabase(this.photoDatabase)) { // we could load all available gestures in the photodatabase with a call to vgbFrameSource.AddGestures(photodatabase.AvailableGestures), // but for this program, we only want to track one discrete gesture from the database, so we'll load it by name foreach (Gesture gesture in photodatabase.AvailableGestures) { if (gesture.Name.Equals(this.photoGestureName) ) { this.vgbFrameSource.AddGesture(gesture); } } }
处理gesture_arrive 事件
//处理gesture事件 private void Reader_GestureFrameArrived(object sender, VisualGestureBuilderFrameArrivedEventArgs e) { VisualGestureBuilderFrameReference frameReference = e.FrameReference; using (VisualGestureBuilderFrame frame = frameReference.AcquireFrame()) { if (frame != null) { // get the discrete gesture results which arrived with the latest frame IReadOnlyDictionary<Gesture, DiscreteGestureResult> discreteResults = frame.DiscreteGestureResults; if (discreteResults != null) { // we only have one gesture in this source object, but you can get multiple gestures foreach (Gesture gesture in this.vgbFrameSource.Gestures) { if (gesture.Name.Equals(this.cleanGestureName) && gesture.GestureType == GestureType.Discrete) { DiscreteGestureResult result = null; discreteResults.TryGetValue(gesture, out result); if (result != null) { this.cleanClothesByGesture(true, result.Detected, result.Confidence); } } else if(gesture.Name.Equals(this.photoGestureName) && gesture.GestureType == GestureType.Discrete) { DiscreteGestureResult result = null; discreteResults.TryGetValue(gesture, out result); if (result != null) { this.takePhotoByGesture(true, result.Detected, result.Confidence); } } } } } } }
清空衣物操作,即把image 控件隐藏
/// <summary> /// 识别动作,清空衣服 /// </summary> /// <param name="isBodyTrackingIdValid">True, if the body associated with the GestureResultView object is still being tracked</param> /// <param name="isGestureDetected">True, if the discrete gesture is currently detected for the associated body</param> /// <param name="detectionConfidence">Confidence value for detection of the discrete gesture</param> public void cleanClothesByGesture(bool isBodyTrackingIdValid,bool isGestureDetected,float detectionConfidence) { if (isGestureDetected&&detectionConfidence>0.5) { clth.Visibility = Visibility.Hidden; } }
执行拍照操作,使用前面编写的takephoto函数
/// <summary> /// 识别动作,拍照 /// </summary> /// <param name="isBodyTrackingIdValid">True, if the body associated with the GestureResultView object is still being tracked</param> /// <param name="isGestureDetected">True, if the discrete gesture is currently detected for the associated body</param> /// <param name="detectionConfidence">Confidence value for detection of the discrete gesture</param> public void takePhotoByGesture(bool isBodyTrackingIdValid, bool isGestureDetected, float detectionConfidence) { if (isGestureDetected && detectionConfidence > 0.5) { takephoto(); } }
相关文章推荐
- Kinect和U3d结合开发基础之基本的动作识别
- Kinect虚拟试衣间开发(2)-Hand Point Gesture,手掌交互部分
- Kinect开发教程三:利用OpenNI进行手势识别
- [译]Kinect for Windows SDK开发入门(十):手势识别 上:基本概念
- 下一代Kinect将增加唇部动作识别功能
- Kinect+Unity实现虚拟人物动作同步
- [译]Kinect for Windows SDK开发入门(十):手势识别 上:基本概念
- Kinect开发教程三:利用OpenNI进行手势识别
- cocos2d-x游戏开发 跑酷(五) 跳起和下蹲动作 手势识别
- Kinect 开发 —— 常见手势识别(上)
- [译]Kinect for Windows SDK开发入门(十):手势识别 上:基本概念
- [译]Kinect for Windows SDK开发入门(十一):手势识别 下:基本手势识别
- Kinect for Windows SDK开发入门(十):手势识别 上:基本概念
- Kinect 开发 —— 手势识别(上)
- Kinect 开发 —— 手势识别(下)
- [译]Kinect for Windows SDK开发入门(十一):手势识别 下:基本手势识别
- Kinect for Windows SDK开发入门(十一):手势识别 下:基本手势识别
- [译]Kinect for Windows SDK开发入门(十一):手势识别 下:基本手势识别
- [译]Kinect for Windows SDK开发入门(十三):语音识别 下
- [译]Kinect for Windows SDK开发入门(十三):语音识别 下