我不得不说,我是VisualBasic和VisualStudio的新手(我对Java,android和web更熟悉)。我刚刚找到了一个关于如何用VB进行骨架跟踪的好教程。
在我的应用程序中,我有一个图片框(窗口的左半部分),显示图像和骨架。在另一半,我有一些标签,我想显示骨骼关节的数字值。
我已设法将shoulderright.X
的值分配给Label2
,但它始终无法正常工作。它实际上只是在我构建它之后第一次运行我的应用程序。当我关闭并再次重新打开我的应用程序时显示“0”并保持这样。
这是我的代码:
If skeletons.Length <> 0 Then
For Each skel As Skeleton In skeletons
'Right Arm
Dim shoulderright As DepthImagePoint = kinz.MapSkeletonPointToDepth(skel.Joints(JointType.ShoulderRight).Position, DepthImageFormat.Resolution640x480Fps30)
Dim elbowright As DepthImagePoint = kinz.MapSkeletonPointToDepth(skel.Joints(JointType.ElbowRight).Position, DepthImageFormat.Resolution640x480Fps30)
Dim wristright As DepthImagePoint = kinz.MapSkeletonPointToDepth(skel.Joints(JointType.WristRight).Position, DepthImageFormat.Resolution640x480Fps30)
Dim handright As DepthImagePoint = kinz.MapSkeletonPointToDepth(skel.Joints(JointType.HandRight).Position, DepthImageFormat.Resolution640x480Fps30)
gfx.DrawLine(penz, New Point(shoulderright.X, shoulderright.Y), New Point(elbowright.X, elbowright.Y))
gfx.DrawLine(penz, New Point(elbowright.X, elbowright.Y), New Point(wristright.X, wristright.Y))
gfx.DrawLine(penz, New Point(wristright.X, wristright.Y), New Point(handright.X, handright.Y))
Label2.Text = shoulderright.X.ToString() //assigning the value to the Label
Label2.Update()
有谁能建议我如何修复它?我尝试过很多变种,比如
Label2.Text = shoulderright.X.ToString
Label2.Update()
或者
Label2.Text = shoulderright.X.ToString()
谢谢。
答案 0 :(得分:0)
对于每个骨架,首先清零“肩膀”,得到一些值,然后将值赋给Label2.Text。每次循环时都会覆盖标签。
尝试创建一个文本框,并为每个骨架创建它:Textbox1.Text + = shoulderright.X.ToString()&amp; vbCrLf(lineshift)
这应该列出循环中的每个值。
答案 1 :(得分:0)
好的,我们可以按原样使用您的代码,但请使用我建议的文本框。确保文本框属性设置为多行:
If skeletons.Length <> 0 Then
For Each skel As Skeleton In skeletons
'Right Arm
Dim shoulderright As DepthImagePoint = kinz.MapSkeletonPointToDepth(skel.Joints(JointType.ShoulderRight).Position, DepthImageFormat.Resolution640x480Fps30)
Dim elbowright As DepthImagePoint = kinz.MapSkeletonPointToDepth(skel.Joints(JointType.ElbowRight).Position, DepthImageFormat.Resolution640x480Fps30)
Dim wristright As DepthImagePoint = kinz.MapSkeletonPointToDepth(skel.Joints(JointType.WristRight).Position, DepthImageFormat.Resolution640x480Fps30)
Dim handright As DepthImagePoint = kinz.MapSkeletonPointToDepth(skel.Joints(JointType.HandRight).Position, DepthImageFormat.Resolution640x480Fps30)
gfx.DrawLine(penz, New Point(shoulderright.X, shoulderright.Y), New Point(elbowright.X, elbowright.Y))
gfx.DrawLine(penz, New Point(elbowright.X, elbowright.Y), New Point(wristright.X, wristright.Y))
gfx.DrawLine(penz, New Point(wristright.X, wristright.Y), New Point(handright.X, handright.Y))
TextBox1.Text += shoulderright.X.ToString() & vbCrLf
Next
现在可以看到文本框中的所有值吗?