using System;
using c;
using ;
using s;
using ;
using er;
using ls;
using ives;
using ;
using g;
using ;
using ;
using ls;
using ;
namespace KinectHubDemo
{
public partial class MainWindow : Window
{
KinectSensor kinect;
private List
s).OrderBy(s => [].Position.Z)
.FirstOrDefault();
if (clostSkeleton == null)
return;
if (ngState != d)
return;
var joints = ;
Joint rightHand = joints[ght];
Joint leftHand = joints[ft];
//通过Y轴坐标判断是左手习惯还是右手习惯:举起的那支手的Y轴坐标值更大
var hand = (on.Y > on.Y)
? rightHand
: leftHand;
if (ngState != d)
return;
//获得屏幕的宽度和高度
int screenWidth = (int)yScreenWidth;
int screenHeight = (int)yScreenHeight;
//将部位“手”的骨骼坐标映射为屏幕坐标;手只需要在有限范围内移动即可覆盖整个屏幕区域
float posX = o(screenWidth, screenHeight, 0.2f, 0.2f).Position.X;
float posY = o(screenWidth, screenHeight, 0.2f, 0.2f).Position.Y;
//判断是否悬浮在图片按钮上,有则触发Click事件
OnButtonLocationChanged(kinectButton, buttons, (int)posX, (int)posY);
}
}
void kinect_ColorFrameReady(object nder, ColorImageFrameReadyEventArgs e)
{
using (ColorImageFrame colorFrame = lorImageFrame())
{
if (colorFrame == null)
{
return;
}
//屏幕右下角显示彩色摄像,使用的扩展方法
= apSource();
}
}
public MainWindow()
{
InitializeComponent();
+= new RoutedEventHandler(kinectButton_Clicked);
}
private void InitializeButtons()
{
buttons = new List
e();
//移动手型光标
t(hand, X - (Width / 2));
(hand, Y - (Height / 2));
}
private void kinectButton_Clicked(object nder, RoutedEventArgs e)
{ttt
vent(new RoutedEventArgs(vent, hoveredButton));
}
public bool IsButtonOverObject(FrameworkElement hand, List
{
if (isWindowsClosing || !dow(hand).IsActive)
return fal;
// 找到悬浮手型控件的中心点位置
var handTopLeft = new Point((hand), t(hand));
double handLeft = handTopLeft.X + (Width / 2);
double handTop = handTopLeft.Y + (Height / 2);
//遍历图片按钮,判断Hand图标是否悬浮在其中之一
foreach (Button target in buttons)
{
Point targetTopLeft = oScreen(new Point());
if (handTop > targetTopLeft.X
&& handTop < targetTopLeft.X + Width
&& handLeft > targetTopLeft.Y
&& handLeft < targetTopLeft.Y + Height)
{
hoveredButton = target;
return true;
}
}
return fal;
}
private void promoteButtonClickEvent(string info)
{
(("{0} : {1}", info, ng("t")));
}
private void button1_Click(object nder, RoutedEventArgs e)
{
promoteButtonClickEvent("Button 1 Clicked");
}
private void button2_Click(object nder, RoutedEventArgs e)
{
promoteButtonClickEvent("Button 2 Clicked");
}
private void button3_Click(object nder, RoutedEventArgs e)
{
promoteButtonClickEvent("Button 3 Clicked");
}
private void button4_Click(object nder, RoutedEventArgs e)
{
promoteButtonClickEvent("Button 4 Clicked");
}
private void button5_Click(object nder, RoutedEventArgs e)
{
promoteButtonClickEvent("Button 5 Clicked");
}
private void button6_Click(object nder, RoutedEventArgs e)
{
promoteButtonClickEvent("Button 6 Clicked");
}
private void Canvas_Loaded(object nder, RoutedEventArgs e)
{
}
private void stopKinect()
{
if (kinect != null)
{
if ( == ted)
{
//关闭Kinect设备
();
}
}
}
private void Window_Loaded(object nder, RoutedEventArgs e)
{
InitializeButtons();
startKinect();
}
private void Window_Closing(object nder, EventArgs e)
{
isWindowsClosing = true;
stopKinect();
}
}
}
//界面::::
WindowState="Maximized"
WindowStyle="SingleBorderWindow"
xmlns="/winfx/2006/xaml/prentation"
xmlns:x="/winfx/2006/xaml"
Background="#1E1C37"
xmlns:Controls="clr-namespace:ls;asmbly="
Title="Kinect Hub Demo" Height="800" Width="1280" Loaded="Window_Loaded" Closing="Window_Closing">
HorizontalContentAlignment="Right" VerticalContentAlignment="Bottom" Click="button6_Click">
本文发布于:2022-10-25 12:34:18,感谢您对本站的认可!
本文链接:http://www.wtabcd.cn/fanwen/fan/82/372587.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |