2013-02-25 2 views
0

내가 키 넥트 프로그래밍 초보자 해요, 난 KINECT를 사용하여 추적 공을 일하고 opencv..we 모두 KINECT가 깊이 데이터를 제공하는 것을 알고, 아래의 코드 :얻기 깊이 넥트

DepthImagePoint righthandDepthPoint = 
    sensor.CoordinateMapper.MapSkeletonPointToDepthPoint 
    (
     me.Joints[JointType.HandRight].Position, 
     DepthImageFormat.Resolution640x480Fps30 
    ); 

double rightdepthmeters = (righthandDepthPoint.Depth); 

.. 나는 jointtype을 명시 할하여 기능 MapSkeletonPointToDepthPoint()를 사용하여 오른쪽의 깊이를 얻을 수 있어요, 이것을 사용하여

는 어디 이미지에 지정하여 다른 개체의 깊이를 얻을 수 있습니까? 좌표가 주어진 ... 그 좌표에서 물체의 깊이를 얻고 싶습니까?

답변

0

Kinect SDK에서 추출하는 깊이 데이터는 DepthImagePixel 구조에서 추출 할 수 있습니다.

아래의 예제 코드는 전체 픽셀을 검사하기 위해 전체 DepthImageFrame을 반복합니다. 보고자하는 좌표가있는 경우 for 루프를 제거하고 xy을 특정 값으로 설정하십시오.

// global variables 

private const DepthImageFormat DepthFormat = DepthImageFormat.Resolution320x240Fps30; 
private const ColorImageFormat ColorFormat = ColorImageFormat.RgbResolution640x480Fps30; 

private DepthImagePixel[] depthPixels; 

// defined in an initialization function 

this.depthWidth = this.sensor.DepthStream.FrameWidth; 
this.depthHeight = this.sensor.DepthStream.FrameHeight; 

this.depthPixels = new DepthImagePixel[this.sensor.DepthStream.FramePixelDataLength]; 

private void SensorAllFramesReady(object sender, AllFramesReadyEventArgs e) 
{ 
    if (null == this.sensor) 
     return; 

    bool depthReceived = false; 

    using (DepthImageFrame depthFrame = e.OpenDepthImageFrame()) 
    { 
     if (null != depthFrame) 
     { 
      // Copy the pixel data from the image to a temporary array 
      depthFrame.CopyDepthImagePixelDataTo(this.depthPixels); 

      depthReceived = true; 
     } 
    } 

    if (true == depthReceived) 
    { 
     // loop over each row and column of the depth 
     for (int y = 0; y < this.depthHeight; ++y) 
     { 
      for (int x = 0; x < this.depthWidth; ++x) 
      { 
       // calculate index into depth array 
       int depthIndex = x + (y * this.depthWidth); 

       // extract the given index 
       DepthImagePixel depthPixel = this.depthPixels[depthIndex]; 

       Debug.WriteLine("Depth at [" + x + ", " + y + "] is: " + depthPixel.Depth); 
      } 
     } 
    } 
} 
+0

대단히 감사합니다! : D 이것은 단지 내가 필요로했던 것입니다. – muffin

+0

선생님, 또 다른 질문이 있습니다 ... depthPixels.Depth는 깊이의 밀리미터 단위를 반환하기 위해 의도 되었습니까? 아니면 여전히 어떤 변환이 필요합니까? ..이 코드는 훌륭합니다. 그러나 반환 된 깊이는 밀리미터로 표시된 해골 조인트와 다릅니다. 객체가 너무 가깝더라도 막대한 수를 봅니다. 내가 잘못한 일을하거나 코드가 완벽하게 작동해야합니까? – muffin

+0

값은 밀리미터 단위 여야합니다. http://msdn.microsoft.com/en-us/library/microsoft.kinect.depthimagepixel_members.aspx –

관련 문제