Kinect V2 For Unity 代碼閱讀筆記

Kinect V2 For Unity 代碼閱讀筆記

KinectManager

void OnGUI()

將所選的Map顯示在右下角(Display*Map)。

通過public float DisplayMapsWidthPercent來控制該顯示區域佔渲染視口的百分比。

只支持同時顯示UserMap或ColorMap的其中一種。

顯示UserMap時要求computeUserMap的值不爲NoneRawUserDepth

BackgroundRemovalManager

管理背景去除的模塊。用於更新AlphaColorMask

單例模式。

在使用該模塊時,似乎無法顯示 UserMap。

void OnGUI()

foregroundCamera不爲空時,會通過GUI.DrawTexture()繪製指定的Map。

bool computeBodyTexOnly

若勾選computeBodyTexOnly,則只會繪製白色的sensorData.alphaBodyTexture,即人物輪廓圖。

該值可在runTime生效。

bool InverAlphaColorMask

該值不可在runTime生效。

UserMeshVisualizer

用於繪製人體部分的Mesh。

Texture:

renderer.material.mainTexture = backManager && backManager.IsBackgroundRemovalInitialized() ? 
				(Texture)sensorData.color2DepthTexture : (Texture)manager.GetUsersLblTex();

private KinectInterop.SensorData sensorData

private void UpdateMesh()

foregroundCamera

  • 爲空:頂點位置直接等於depth2SpaceCoords[]的值乘以local space到world space的變換矩陣kinectToWorld
  • 不爲空:會被繪製在相對於foregroundCamera的位置。先通過depth2ColorCoords[]取得以像素爲單位的colormap座標,再通過depthImage[]取得深度值,最後通過foregroundCamera.ScreenToWorldPoint()的調用獲得相對於foregroundCamera的位置。

uv座標的計算:

取當前遍歷depth map的座標(x, y),用(depthWidth, depthHeight)歸一化。

KinectInterop

public static bool MapDepthFrameToSpaceCoords(SensorData sensorData, ref Vector3[] vSpaceCoords)

estimates space coordinates for the current depth frame

KinectInterop.SensorData

Vector2[] depth2ColorCoords

存儲了給定某索引i時depth map對應的color map的座標,範圍爲([0, sensorData.colorImageWidth], [0, sensorData.colorImageHeight])

Vector3[] depth2SpaceCoords

存儲了點雲的local space位置。

KinectManager

public Matrix4x4 GetKinectToWorldMatrix()

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章