0
我與Kinect的SDK工作,我試圖以兩種方式來過濾深度圖像數據:高效的Kinect深度圖像(或大陣列)過濾
- 刪除不與玩家相關的所有深度
- 刪除比給定深度更大的所有深度(計算值形成一玩家手腕的位置)
其結果是實質上只顯示其是小於一定的一個玩家身體部位來自傳感器的深度。
雖然下面的代碼做了我想做的事情,但是當我運行性能分析時,它沒有證明非常好,所以我正在尋找可以改進的方法。
基本問題是該數組包含307200值(深度圖像大小爲640x480),我試圖讓這種方法每秒調用30次左右。
有沒有人有任何指示,如何可以更有效地做到這一點?該代碼還在其他部分使用EmguCV庫,並且使用cvInvokeThreshold方法修飾了它,但它看起來並不像這個代碼一樣工作...
如果您需要更多信息,請告訴我。
非常感謝,
戴夫MCB
public static byte[] GetDepths(byte[] depths, DepthImagePixel[] depthPixels, int width, int height, int threshold)
{
Parallel.For(0, width, i =>
{
for (int j = 0; j < height; j++)
{
//Have to calculate the index we are working on using i and j
int rawDepthDataIndex = i * height + j;
//gets the depth and player values
short depth = depthPixels[rawDepthDataIndex].Depth;
short player = depthPixels[rawDepthDataIndex].PlayerIndex;
if (player > 0 && depth < threshold)
depths[rawDepthDataIndex] = (byte)depth;
else
depths[rawDepthDataIndex] = 0;
}
});
return depths;
}
我想不出比其他的Parallel.For任何優化,你已經有了,但我有在代碼中一個小評論。不應您有:'的Parallel.For(0,高度,I => {對(INT J = 0;Ĵ<寬度; J ++){INT rawDepthDataIndex = I *高度+ J;' –
我給這樣的原因嗎?圓是寬度大於(680),因此其在並行的會帶來更大的性能比更小的指數較大的指數,就是南轅北轍? – DMcB1888
好吧,這是有道理的。我通常處理圖像的行明智的,因爲圖像被逐行存儲。您是否嘗試過的其他方式?一個建議,以使代碼快是下采樣圖像。此外,嘗試剖析代碼,看看哪個指令是最慢的。 –