如何创建3D边界框 [英] how to create a 3D Bounding Box

查看:115
本文介绍了如何创建3D边界框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好, 

我正在尝试在深度图像上围绕用户创建3D边界框。

I'm trying to create a 3D Bounding Box around a user on depth image.

有没有人知道怎么做?

感谢您的帮助

问候 

DKF

推荐答案

嗯,有一个使用kinect创建伪全息图的例子.kinect已经为玩家提供了X,Y,Z坐标骨架。使用此信息,您可以随身体旋转3-D盒子。困难的是如何在xaml中创建3-D框。你可以使用Viewport3D对象来创建3D对象,例子如下:

Well, there is an example using kinect to create pseudo-hologram.The kinect already provide X,Y,Z coordinate for a player skeleton. Using this information ,you can rotate the 3-D box with your body. The difficult thing is how to create 3-D box in the xaml.You can use Viewport3D object to create 3D object, the example are as follows:

主要的xaml:

<Viewport3D>
    <Viewport3D.Camera>
        <PerspectiveCamera x:Name="camera" Position="-40,160,100" LookDirection="40,-160,-100" 
                    UpDirection="0,1,0"  />
    </Viewport3D.Camera>
    <ModelVisual3D x:Name="mainBox">
        <ModelVisual3D.Transform>
            <Transform3DGroup>
                <TranslateTransform3D>
                    <TranslateTransform3D.OffsetY>10</TranslateTransform3D.OffsetY>
                </TranslateTransform3D>
                <ScaleTransform3D>
                    <ScaleTransform3D.ScaleZ>3</ScaleTransform3D.ScaleZ>
            </ScaleTransform3D>
            </Transform3DGroup>
        </ModelVisual3D.Transform>
        <ModelVisual3D.Content>
            <Model3DGroup>
                <DirectionalLight Color="White" Direction="-1,-1,-3" />
                <GeometryModel3D >
                    <GeometryModel3D.Geometry>
                        <MeshGeometry3D
                            Positions="1.000000,1.000000,-1.000000 1.000000,-1.000000,-1.000000 -1.000000,-1.000000,-1.000000 -1.000000,1.000000,-1.000000 1.000000,0.999999,1.000000 -1.000000,1.000000,1.000000 -1.000000,-1.000000,1.000000 0.999999,-1.000001,1.000000 1.000000,1.000000,-1.000000 1.000000,0.999999,1.000000 0.999999,-1.000001,1.000000 1.000000,-1.000000,-1.000000 1.000000,-1.000000,-1.000000 0.999999,-1.000001,1.000000 -1.000000,-1.000000,1.000000 -1.000000,-1.000000,-1.000000 -1.000000,-1.000000,-1.000000 -1.000000,-1.000000,1.000000 -1.000000,1.000000,1.000000 -1.000000,1.000000,-1.000000 1.000000,0.999999,1.000000 1.000000,1.000000,-1.000000 -1.000000,1.000000,-1.000000 -1.000000,1.000000,1.000000"
                            TriangleIndices="0,1,3 1,2,3 4,5,7 5,6,7 8,9,11 9,10,11 12,13,15 13,14,15 16,17,19 17,18,19 20,21,23 21,22,23"
                            Normals="0.000000,0.000000,-1.000000 0.000000,0.000000,-1.000000 0.000000,0.000000,-1.000000 0.000000,0.000000,-1.000000 0.000000,-0.000000,1.000000 0.000000,-0.000000,1.000000 0.000000,-0.000000,1.000000 0.000000,-0.000000,1.000000 1.000000,-0.000000,0.000000 1.000000,-0.000000,0.000000 1.000000,-0.000000,0.000000 1.000000,-0.000000,0.000000 -0.000000,-1.000000,-0.000000 -0.000000,-1.000000,-0.000000 -0.000000,-1.000000,-0.000000 -0.000000,-1.000000,-0.000000 -1.000000,0.000000,-0.000000 -1.000000,0.000000,-0.000000 -1.000000,0.000000,-0.000000 -1.000000,0.000000,-0.000000 0.000000,1.000000,0.000000 0.000000,1.000000,0.000000 0.000000,1.000000,0.000000 0.000000,1.000000,0.000000"/>
                    </GeometryModel3D.Geometry>
                    <GeometryModel3D.Material>
                        <DiffuseMaterial Brush="blue"/>
                    </GeometryModel3D.Material>

                </GeometryModel3D>
                <Model3DGroup.Transform>
                    <Transform3DGroup>
                        <Transform3DGroup.Children>
                            <TranslateTransform3D OffsetX="0" OffsetY="0" OffsetZ="0.0935395359992981"/>
                            <ScaleTransform3D ScaleX="12.5608325004577637" ScaleY="12.5608322620391846" ScaleZ="12.5608325004577637"/>
                        </Transform3DGroup.Children>
                    </Transform3DGroup>
                </Model3DGroup.Transform>
            </Model3DGroup>
        </ModelVisual3D.Content>
    </ModelVisual3D>
  </Viewport3D>

代码:

KinectSensor _kinectSensor;

public MainWindow()
{
    InitializeComponent();
    this.Unloaded += delegate
    {
        _kinectSensor.DepthStream.Disable();
        _kinectSensor.SkeletonStream.Disable();
    };

    this.Loaded += delegate
    {
        _kinectSensor = KinectSensor.KinectSensors[0];
        _kinectSensor.SkeletonFrameReady += SkeletonFrameReady;
        _kinectSensor.DepthFrameReady += DepthFrameReady;
        _kinectSensor.SkeletonStream.Enable();
        _kinectSensor.DepthStream.Enable();
        _kinectSensor.Start();
    };
}




void SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)
{
    float x=0, y=0, z = 0;
    //get angle of skeleton
    using (var frame = e.OpenSkeletonFrame())
    {
        if (frame == null || frame.SkeletonArrayLength == 0)
            return;

        var skeletons = new Skeleton[frame.SkeletonArrayLength];
        frame.CopySkeletonDataTo(skeletons);
        for (int s = 0; s < skeletons.Length; s++)
        {
            if (skeletons[s].TrackingState == SkeletonTrackingState.Tracked)
            {
                border.BorderBrush = new SolidColorBrush(Colors.Red);
                var skeleton = skeletons[s];
                x = skeleton.Position.X * 60;
                z = skeleton.Position.Z * 120;
                y = skeleton.Position.Y;
                break;
            }
            else
            {
                border.BorderBrush = new SolidColorBrush(Colors.Black);
            }

        }
    }
    if (Math.Abs(x) > 0)
    {
        camera.Position = new System.Windows.Media.Media3D.Point3D(x, y , z);
        camera.LookDirection = new System.Windows.Media.Media3D.Vector3D(-x, -y , -z);
    }
}

效果如下,三维盒子可根据骨架方向旋转

这可以为您提供一些在用户周围创建3D边界框的线索。

and the effect are as followings , the 3-D box can rotate acoording to you skeleton direction
this can give you some clue to create 3D Bounding Box around a user.





这篇关于如何创建3D边界框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆