浏览代码

Bounding box 3d visualizer (#175)

* 3D bounding box visualizer

* Updated changelog
/main
GitHub 4 年前
当前提交
4127b7b2
共有 2 个文件被更改,包括 59 次插入1 次删除
  1. 2
      com.unity.perception/CHANGELOG.md
  2. 58
      com.unity.perception/Runtime/GroundTruth/Labelers/BoundingBox3DLabeler.cs

2
com.unity.perception/CHANGELOG.md


* Can now render intermediate frames between captures.
* Capture can now be triggered manually using a function call, instead of automatic capturing on a schedule.
Added 3D bounding box visualizer
Categorical Parameters will now validate that their specified options are unique at runtime.
### Changed

58
com.unity.perception/Runtime/GroundTruth/Labelers/BoundingBox3DLabeler.cs


int m_CurrentFrame;
/// <summary>
/// Color to use for 3D visualization box
/// </summary>
// ReSharper disable once MemberCanBePrivate.Global
public Color visualizationColor = Color.green;
protected override bool supportsVisualization => false;
protected override bool supportsVisualization => true;
/// <summary>
/// Fired when the bounding boxes are computed for a frame.

m_BoundingBoxValues[m_CurrentFrame][labeledEntity.instanceId] = converted;
}
}
}
static Vector3 CalculateRotatedPoint(Camera cam, Vector3 start, Vector3 xDirection, Vector3 yDirection, Vector3 zDirection, float xScalar, float yScalar, float zScalar)
{
var rotatedPoint = start + xDirection * xScalar + yDirection * yScalar + zDirection * zScalar;
var worldPoint = cam.transform.TransformPoint(rotatedPoint);
return VisualizationHelper.ConvertToScreenSpace(cam, worldPoint);
}
protected override void OnVisualize()
{
if (m_ToReport == null) return;
var cam = perceptionCamera.attachedCamera;
foreach (var box in m_ToReport)
{
var t = box.translation;
var right = box.rotation * Vector3.right;
var up = box.rotation * Vector3.up;
var forward = box.rotation * Vector3.forward;
var s = box.size * 0.5f;
var bbl = CalculateRotatedPoint(cam, t,right, up, forward,-s.x,-s.y, -s.z);
var btl = CalculateRotatedPoint(cam, t,right, up, forward,-s.x, s.y, -s.z);
var btr = CalculateRotatedPoint(cam, t,right, up, forward,s.x, s.y, -s.z);
var bbr = CalculateRotatedPoint(cam, t,right, up, forward,s.x, -s.y, -s.z);
VisualizationHelper.DrawLine(bbl, btl, visualizationColor);
VisualizationHelper.DrawLine(bbl, bbr, visualizationColor);
VisualizationHelper.DrawLine(btr, btl, visualizationColor);
VisualizationHelper.DrawLine(btr, bbr, visualizationColor);
var fbl = CalculateRotatedPoint(cam, t,right, up, forward,-s.x,-s.y, s.z);
var ftl = CalculateRotatedPoint(cam, t,right, up, forward,-s.x, s.y, s.z);
var ftr = CalculateRotatedPoint(cam, t,right, up, forward,s.x, s.y, s.z);
var fbr = CalculateRotatedPoint(cam, t,right, up, forward,s.x, -s.y, s.z);
VisualizationHelper.DrawLine(fbl, ftl, visualizationColor);
VisualizationHelper.DrawLine(fbl, fbr, visualizationColor);
VisualizationHelper.DrawLine(ftr, ftl, visualizationColor);
VisualizationHelper.DrawLine(ftr, fbr, visualizationColor);
VisualizationHelper.DrawLine(fbl, bbl, visualizationColor);
VisualizationHelper.DrawLine(fbr, bbr, visualizationColor);
VisualizationHelper.DrawLine(ftl, btl, visualizationColor);
VisualizationHelper.DrawLine(ftr, btr, visualizationColor);
}
}
}
正在加载...
取消
保存