【问题标题】:Projecting an object into a scene based on world coordinates only仅基于世界坐标将对象投影到场景中
【发布时间】:2010-05-31 20:06:45
【问题描述】:

我想将 3D 图像放置到基于世界/全局坐标的场景中。我有一个场景的图像。图像是在某个全局坐标 (x1, y1, z1) 上捕获的。我得到了一个需要根据其全局坐标 (x2, y2, y3) 放置到此场景中的对象。类似于透视投影,该对象需要准确地投影到场景中。

一个例子可能有助于说明这一点。想象一下有一个带有一些全局坐标的停车场。为停车场的一部分拍照。记录图像拍摄地点的坐标。目标是使用该车辆的全局坐标将虚拟车辆放置到该图像中。因为车辆的全局坐标可能不在图像全局坐标的 fov 中,所以我假设我需要图像坐标、角度和可能的 fov。

3D 图形不是我的领域,所以我一直在关注http://en.wikipedia.org/wiki/Perspective_projection#Perspective_projection。我也一直在研究 Matrix3DProjection,这似乎可能是我正在寻找的东西,但它只适用于 Silverlight,我正试图在 WPF 中做到这一点。在我看来,我似乎需要确定图像 fov 中的 (X,Y,Z) 坐标,确定世界坐标到像素的转换,然后将车辆准确投影到图像中,使其具有正确的视角,这样看起来是 3D 的,即越远越小越近

WPF 中是否有可以帮助解决此问题的函数,或者我需要重新学习矩阵并手动执行此操作?

【问题讨论】:

    标签: c# wpf


    【解决方案1】:

    我不确定我是否理解为什么这很困难。如果我的理解是正确的,那么您需要做的就是在您的 Model3D 对象上设置变换。我假设您已经拥有汽车模型的 Model3D 对象(Model3DGroup 或 GeometryModel3D)。以下是如何将其与场景图像结合起来:

    1. 在表示您的汽车模型的 Model3D 上使用任何方便的坐标,然后添加一个由 ScaleTransform3D、RotateTransform3D 和 TranslateTransform3D 组成的 Transform3DGroup 来调整您的汽车模型的大小并将其定位到全局坐标

      李>
    2. 为场景创建一个 GeometryModel3D,使用一个 ImageBrush 作为材质、一个简单的矩形 Geometry3D 和一个由 ScaleTransform3D、一个 TranslateTransform3D、一个 RotateTransform3D 和一个 TranslateTransform3D 组成的 Transform3DGroup,以调整场景的大小和位置(参见代码详情见下文)

    3. 使用 PerspectiveCamera 构造一个 Viewport3DVisual 并包含一个 Model3DVisual,该 Model3DVisual 包含一个包含 AmbientLight 的 Model3DGroup 以及在步骤 1 和 2 中创建的模型

    所以 XAML 应该是这样的:

    ...
    <Viewport3DVisual>
    
      <!-- the camera -->
      <Viewport3DVisual.Camera>
        <PerspectiveCamera ... camera parameters ... />
      </Viewport3DVisual.Camera>
    
      <ModelVisual3D>
        <ModelVisual3D.Content>
          <Model3DGroup>
    
            <!-- the light -->
            <AmbientLight ... light parameters ... />
    
            <!-- the car model -->
            <Model3DGroup>
              <Model3DGroup.Transform>
                <Transform3DGroup>
                  <ScaleTransform3D    ... scale car to proper size ... />
                  <RotateTransform3D   ... face car in proper direction ... />
                  <TranslateTranform3D ... move car to proper global coordinates ... />
                </Transform3DGroup>
              </Model3DGroup.Transform>
    
              ... GeometryModel3D or Model3DGroup for the car model goes here ...
    
            </Model3DGroup>
    
            <!-- the scene image -->
            <GeometryModel3D>
    
              <GeometryModel3D.Material>
                <ImageBrush ImageSource=... scene image ... />
              </GeometryModel3D.Material>
    
              <GeometryModel3D.Geometry>
                <MeshGeometry3D Positions="0,0,0 1,0,0 1,1,0 0,1,0" Indices="0,1,2 2,3,0" />
              </GeometryModel3D.Geometry>
    
              <GeometryModel3D.Transform>
                <Transform3DGroup>
                  <ScaleTransform3D     ... scale scene to apparent size ... />
                  <TranslateTransform3D ... translate scene along Z axis to apparent distance from camera ... />
                  <RotateTransform3D    ... rotate distanced scene to original camera orientation ... />
                  <TranslateTransform3D ... move to global coordinates of original camera location ... />
                </Transform3DGroup>
              </GeometryModel3D.Transform>
    
            </GeometryModel3D>
    
          </Model3DGroup>
        </ModelVisual3D.Content>
      </ModelVisual3D>
    </Viewport3DVisual>
    

    请注意,您的场景图像是使用表观大小和距离设置的,而不是视野。为场景图像选择较大的视距,使其始终位于汽车模型后面。像这样计算表观大小:

    var verticalFieldOfView = 60.0;    // Degrees
    var horizontalFieldOfView = 60.0;  // Degrees
    SceneApparentDistance = 1000.0;    // In global coordinate units
    
    SceneApparentHeight = image.Height * SceneApparentDistance * Math.Tan(verticalFieldOfView * Math.Pi/180));
    SceneApparentWidth = image.Width * SceneApparentDistance * Math.Tan(horizontalFieldOfView * Math.Pi/180));
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-08
      • 2013-06-17
      • 1970-01-01
      相关资源
      最近更新 更多