簡體   English   中英

使用kinect在骨架周圍繪制矩形

[英]Drawing rectangle around skeleton using kinect

我想知道如何使用SDK v1.5在骨架周圍繪制矩形

我想做的是,當識別出手勢時,骨架周圍應出現一個紅色矩形。

任何幫助,將不勝感激。

問候,

艾哈邁德

該代碼不會立即生效,其目的是提供要使用的算法和方法。

SkeletonPoint maxX = joints[0].Position, minX = joints[0].Position;
SkeletonPoint maxY = joints[0].Position, minY = joints[0].Position;
for(joint in joints){
    if(joint.Position.x>maxX) maxX = joint.Position;
    if(joint.Position.x<minX) minX = joint.Position;
    if(joint.Position.y>maxY) maxY = joint.Position;
    if(joint.Position.y<minY) minY = joint.Position;
}

// Adding a margin, because the articulations are not always placed
// at the extremities. Can adjust to get a better look.
float margin = .10f // 10 cm margin.
maxX.X += margin;
maxY.Y += margin;
minX.X -= margin;
minY.Y -= margin;

// Now we need to convert it to the video stream space.
DepthImagePoint maxXd = depthImageFrame.MapFromSkeletonPoint(maxX);
ColorImagePoint maxXc = depthImageFrame.MapToColorImagePoint(maxXd);
// **
// Same for other coordinates.
// **

// The buffer b will contains the current image, in bitmap format
// (without header). You may use colorImageFrame.Format to get more
// details on its encoding.
byte[] b = new byte[PixelDataLength];
colorImageFrame.CopyPixelDataTo(b);

// Then transform the buffer b into whatever you want,
// and draw the rect [[maxXc,maxYc],[minXc,minYc]] over it
// before rendering.

這樣,您可以獲得最外面的關節,而不僅僅是可能最外面的關節。

轉換字節數組的方法留給您,這取決於您的轉寫方法。

假設您正在使用Kinect SDK,這相對容易。 我正在使用畫布並獲取頭部,腳部,臀部和手部的坐標,因此我知道如何繪制該框,然后在每一側添加一些像素。 我正在使用算法:

|(頭疼+ 25)-(腳疼-25)| * |(右手+ 25)-(左手-25)|

得到盒子的高度。 我正在使用|| 在這種情況下的絕對值

然后,一旦您放置了畫布(和關節),就可以使用以下方法獲取它們的坐標:

Canvas.GetTop(element / 2);
Canvas.GetLeft(element / 2); // /2 so that we get the center

然后,您可以使用我的算法來找到要制造的盒子的大小,並且由於將元素放置在它們的左上角,因此可以使用偏頭坐標+一點Y坐標和右手x +坐標來放置元素有點像X。您可以使用

Canvas.SetTop(ycoord, box);
Canvas.SetLeft(xcoord, box);

我加了一點,所以對象和盒子之間有一些空隙。
希望這可以幫助。
當我完成所有代碼后,我將其發布

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM