2017-03-24 7 views
1

kinect에 대한 깊이 수집을 위해 Get and Display Depth Data in C#에 fps를 계산했습니다. 깊이 날짜 시간kinect data acquisition fps> 30

if (this.sensor != null) 
    { 
     this.sensor.DepthFrameReady += this.DepthImageReady; 
    } 

    private void DepthImageReady(object sender, DepthImageFrameReadyEventArgs e) 
    { 
    DateTime before = DateTime.Now; 
     using (DepthImageFrame depthFrame = e.OpenDepthImageFrame()) 
     { 
      if (depthFrame != null) 
      { 
       depthFrame.CopyDepthImagePixelDataTo(this.depthPixels); 
      } 
      else 
      { 
       // depthFrame is null because the request did not arrive in time 
      } 
     } 
    DateTime after = DateTime.Now; 
    TimeSpan result = after.Subtract(before); 
     float seconds = (float)result.TotalSeconds; 
     this.Text = "Kinect (" + (1/seconds) + "fps)"; 

    } 

나는> 60 FPS를 받고 오전 믿을 수 없을 정도로 무한을 구현하기위한

가 FPS를 계산하기 위해 언젠가

KINECT 왜 내가 무한대를 얻고 초당 30 프레임을 제공하지만, 내가 뭘 잘못 했니?

+0

, 난 당신의 코드를 보면 _ "질문이 답을 제거한 모두 이전 및 날짜 시간 변수는 DateTime.Now로 설정 한 후 - 그래서 차이 초는 0이됩니다. 무한대는 0으로 나눈 결과입니다. "_ – PaulF

답변

3

함수를 호출 할 때마다 간격을 측정해야합니다. 함수를 실행하는 데 걸리는 시간이 아니라 시간 간격을 측정해야합니다. 이 같은 뭔가 : AlexDev 당신에게 해결책을 주신으로

static DateTime lastFrame = DateTime.Now; 
private void DepthImageReady(object sender, DepthImageFrameReadyEventArgs e) 
{ 
    using (DepthImageFrame depthFrame = e.OpenDepthImageFrame()) 
    { 
     if (depthFrame != null) 
     { 
      depthFrame.CopyDepthImagePixelDataTo(this.depthPixels); 
     } 
     else 
     { 
      // depthFrame is null because the request did not arrive in time 
     } 
    } 
    var now = DateTime.Now; 
    TimeSpan result = now.Subtract(lastFrame); 
    lastFrame = now; 
    var milliseconds = result.TotalMilliseconds; 

    this.Text = "Kinect (" + (1000.0/milliseconds) + "fps)"; 
} 
+0

@PaulF TotalSeconds는 두 배입니다. https://msdn.microsoft.com/en-us/library/system.timespan.totalseconds(v=vs.110).aspx. 나는 귀하의 의견에 따라 답변을 편집 했으므로 아마도 더 정확하기 때문에 나는 그것을 떠날 것이라고 생각합니다. – AlexDev

+1

예 - 제 실수는 당신이 옳습니다 - 저는 int 인 Seconds 속성을보고있었습니다. – PaulF

+0

@AlexDev에서 double 또는 var를 사용하면 큰 차이가 있습니까? –