|
@@ -22,29 +22,29 @@ namespace KinectCar
|
|
|
// 活动的 Kinect 传感器
|
|
|
private KinectSensor _kinectSensor = null;
|
|
|
// 坐标映射器将一种类型的点映射到另一种
|
|
|
- private CoordinateMapper coordinateMapper = null;
|
|
|
+ private CoordinateMapper _coordinateMapper = null;
|
|
|
// 身体框架渲染器
|
|
|
- private BodyFrameReader bodyFrameReader = null;
|
|
|
+ private BodyFrameReader _bodyFrameReader = null;
|
|
|
// 颜色框架渲染器
|
|
|
- private ColorFrameReader colorFrameReader = null;
|
|
|
+ private ColorFrameReader _colorFrameReader = null;
|
|
|
// 身体的数组
|
|
|
private Body[] _bodies = null;
|
|
|
// 骨骼的定义
|
|
|
private List<Tuple<JointType, JointType>> _bones;
|
|
|
// 显示宽度,高度(深度空间)
|
|
|
- private int displayWidth, displayHeight;
|
|
|
+ private int _displayWidth, _displayHeight;
|
|
|
// 要显示的当前状态文本
|
|
|
- private string statusText = null;
|
|
|
+ private string _statusText = null;
|
|
|
// 阈值(1/2框)(单位:米)
|
|
|
private const float Threshold = 0.15f;
|
|
|
// 当前状态
|
|
|
private int _gesture = -1;
|
|
|
// Bitmap to display
|
|
|
- private WriteableBitmap _colorBitmap = null;
|
|
|
+ private WriteableBitmap _colorBitmap;
|
|
|
|
|
|
private static string MQTT_BROKER_ADDRESS = "123.207.151.92";
|
|
|
// 创建客户端实例
|
|
|
- MqttClient _client = new MqttClient(IPAddress.Parse(MQTT_BROKER_ADDRESS), 1600, false, null, null, MqttSslProtocols.None); //主机为IP时
|
|
|
+ MqttClient _client = new MqttClient(IPAddress.Parse(MQTT_BROKER_ADDRESS), 1600, false, null, null, MqttSslProtocols.None); // 主机为IP时
|
|
|
|
|
|
// INotifyPropertyChangedPropertyChanged 事件允许窗口控件绑定到可更改的数据
|
|
|
public event PropertyChangedEventHandler PropertyChanged;
|
|
@@ -53,21 +53,15 @@ namespace KinectCar
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
- return statusText;
|
|
|
+ return _statusText;
|
|
|
}
|
|
|
|
|
|
set
|
|
|
{
|
|
|
- if (statusText != value)
|
|
|
- {
|
|
|
- statusText = value;
|
|
|
-
|
|
|
- // 通知任何绑定元素文本已更改
|
|
|
- if (PropertyChanged != null)
|
|
|
- {
|
|
|
- PropertyChanged(this, new PropertyChangedEventArgs("StatusText"));
|
|
|
- }
|
|
|
- }
|
|
|
+ if (_statusText == value) return;
|
|
|
+ _statusText = value;
|
|
|
+ // 通知任何绑定元素文本已更改
|
|
|
+ PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("StatusText"));
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -76,16 +70,16 @@ namespace KinectCar
|
|
|
// 目前支持一个传感器
|
|
|
_kinectSensor = KinectSensor.GetDefault();
|
|
|
// 获取坐标映射器
|
|
|
- coordinateMapper = _kinectSensor.CoordinateMapper;
|
|
|
+ _coordinateMapper = _kinectSensor.CoordinateMapper;
|
|
|
// 获取深度(显示)范围
|
|
|
var frameDescription = _kinectSensor.DepthFrameSource.FrameDescription;
|
|
|
// 得到关节空间的大小
|
|
|
- displayWidth = frameDescription.Width;
|
|
|
- displayHeight = frameDescription.Height;
|
|
|
+ _displayWidth = frameDescription.Width;
|
|
|
+ _displayHeight = frameDescription.Height;
|
|
|
// 打开身体框架的渲染器
|
|
|
- bodyFrameReader = _kinectSensor.BodyFrameSource.OpenReader();
|
|
|
+ _bodyFrameReader = _kinectSensor.BodyFrameSource.OpenReader();
|
|
|
// 打开颜色框架的渲染器
|
|
|
- colorFrameReader = _kinectSensor.ColorFrameSource.OpenReader();
|
|
|
+ _colorFrameReader = _kinectSensor.ColorFrameSource.OpenReader();
|
|
|
// 骨骼定义为两个关节之间的线
|
|
|
_bones = new List<Tuple<JointType, JointType>>
|
|
|
{
|
|
@@ -134,13 +128,13 @@ namespace KinectCar
|
|
|
|
|
|
private void Window_Loaded(object sender, RoutedEventArgs e)
|
|
|
{
|
|
|
- if (bodyFrameReader != null)
|
|
|
+ if (_bodyFrameReader != null)
|
|
|
{
|
|
|
- bodyFrameReader.FrameArrived += Reader_FrameArrived;
|
|
|
+ _bodyFrameReader.FrameArrived += Reader_FrameArrived;
|
|
|
}
|
|
|
- if (colorFrameReader != null)
|
|
|
+ if (_colorFrameReader != null)
|
|
|
{
|
|
|
- colorFrameReader.FrameArrived += Reader_ColorFrameArrived;
|
|
|
+ _colorFrameReader.FrameArrived += Reader_ColorFrameArrived;
|
|
|
}
|
|
|
// create the colorFrameDescription from the ColorFrameSource using Bgra format
|
|
|
var colorFrameDescription = _kinectSensor.ColorFrameSource.CreateFrameDescription(ColorImageFormat.Bgra);
|
|
@@ -150,7 +144,7 @@ namespace KinectCar
|
|
|
// 注册消息接收处理事件,还可以注册消息订阅成功、取消订阅成功、与服务器断开等事件处理函数
|
|
|
_client.MqttMsgPublishReceived += ClientMqttMsgPublishReceived;
|
|
|
//生成客户端 ID 并连接服务器
|
|
|
- string clientId = Guid.NewGuid().ToString();
|
|
|
+ var clientId = Guid.NewGuid().ToString();
|
|
|
_client.Connect(clientId, "yumin", "minbb.cn");
|
|
|
// 订阅主题"" 消息质量为 2
|
|
|
_client.Subscribe(new string[] { "iot.time" }, new byte[] { MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE });
|
|
@@ -160,16 +154,16 @@ namespace KinectCar
|
|
|
|
|
|
private void Window_Closing(object sender, CancelEventArgs e)
|
|
|
{
|
|
|
- if (bodyFrameReader != null)
|
|
|
+ if (_bodyFrameReader != null)
|
|
|
{
|
|
|
- bodyFrameReader.Dispose();
|
|
|
- bodyFrameReader = null;
|
|
|
+ _bodyFrameReader.Dispose();
|
|
|
+ _bodyFrameReader = null;
|
|
|
}
|
|
|
|
|
|
- if (colorFrameReader != null)
|
|
|
+ if (_colorFrameReader != null)
|
|
|
{
|
|
|
- colorFrameReader.Dispose();
|
|
|
- colorFrameReader = null;
|
|
|
+ _colorFrameReader.Dispose();
|
|
|
+ _colorFrameReader = null;
|
|
|
}
|
|
|
|
|
|
if (_kinectSensor != null)
|
|
@@ -341,7 +335,10 @@ namespace KinectCar
|
|
|
colorFrame.CopyConvertedFrameDataToIntPtr(_colorBitmap.BackBuffer,
|
|
|
(uint)(colorFrameDescription.Width * colorFrameDescription.Height * 4),
|
|
|
ColorImageFormat.Bgra);
|
|
|
- _colorBitmap.AddDirtyRect(new Int32Rect(0, 0, _colorBitmap.PixelWidth, _colorBitmap.PixelHeight));
|
|
|
+ var rect = new Int32Rect(0, 0, _colorBitmap.PixelWidth, _colorBitmap.PixelHeight);
|
|
|
+ Console.WriteLine(rect == null);
|
|
|
+ _colorBitmap.AddDirtyRect(rect);
|
|
|
+ Console.WriteLine(_colorBitmap == null);
|
|
|
Console.WriteLine(Image.Source == null);
|
|
|
}
|
|
|
_colorBitmap.Unlock();
|