我正在使用 Xbox-Kinect(Beta SDK)。
我尝试引导机器人从包含许多物体(单身汉)的盒子中抓取物体,因为我需要找到离 kinect 最近的物体的最近点。比我可以通过区域增长来定位整个对象并找出机器人的抓取点。
现在我对该主题有两个问题:
- 如何找出该点的 x 和 y 坐标?(我已经有距离了)
- 如何访问
private byte[] FindMinimum(ImageFrame imageFrame)
按按钮单击以找到最近的距离?
这是我的代码:
void nui_DepthFrameReady(object sender, ImageFrameReadyEventArgs e)
{
image1.Source = e.ImageFrame.ToBitmapSource();
byte[] Minumum = FindMinimum(e.ImageFrame);
}
private void button1_Click(object sender, RoutedEventArgs e)
{
FindMinimum();
}
private byte[] FindMinimum(ImageFrame imageFrame)
{
int height = imageFrame.Image.Height;
int width = imageFrame.Image.Width;
Byte[] depthData = imageFrame.Image.Bits;
Byte[] colorFrame = new byte[imageFrame.Image.Height * imageFrame.Image.Width * 4];
int min = int.MaxValue, max = int.MinValue;
for (int i = 0; i < depthData.Length; i += 2)
{
int dist = GetDistance(depthData[i], depthData[i + 1]);
if (dist < min && dist > 0) min = dist;
if (dist > max) max = dist;
}
textBox1.Text = Convert.ToString(min);
return colorFrame;
}
private int GetDistance(byte firstFrame, byte secondFrame)
{
int distance = (int)(firstFrame | secondFrame << 8);
return distance;
}
private void Window_Closed(object sender, EventArgs e)
{
nui.Uninitialize();
}
}
}