2014-04-09 1 views
1

연구 프로젝트에서 Kinect와 작업중인 Im은 지금까지 골격 추적을 망쳤습니다. 이제 깊이 흐름의 깊이로 들어가서 일부 깊이 스트림에서 볼 수있는 RGB 색상 비율을 만드는 방법을 알고 싶습니다. 내 것은 회색조입니다. 심도 이벤트에는 이해가 안되는 부분이 있는데 어떻게 작동하는지 이해하고 색을 바꿀 수있는 방법, 즉 intesity 변수의 정의를 이해하는 것이 중요합니다.거리에 따라 Kinect Depth를 그레이 스케일에서 RGB로 변환하려고 시도했습니다.

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

       // Get the min and max reliable depth for the current frame 
       int minDepth = depthFrame.MinDepth; 
       int maxDepth = depthFrame.MaxDepth; 

       // Convert the depth to RGB 
       int colorPixelIndex = 0;    
       for (int i = 0; i < this.depthPixels.Length; ++i) 
       { 
        // Get the depth for this pixel 
        short depth = depthPixels[i].Depth; 

        if (depth > 2000) depth = 0; //ive put this here just to test background elimination 

        byte intensity = (byte)(depth >= minDepth && depth <= maxDepth ? depth : 0); 
        //WHAT IS THIS LINE ABOVE DOING? 

        // Write out blue byte 
        this.colorPixels[colorPixelIndex++] = intensity; 

        // Write out green byte 
        this.colorPixels[colorPixelIndex++] = intensity; 

        // Write out red byte       
        this.colorPixels[colorPixelIndex++] = intensity; 

        // We're outputting BGR, the last byte in the 32 bits is unused so skip it 
        // If we were outputting BGRA, we would write alpha here. 


        ++colorPixelIndex; 
       } 
       // Write the pixel data into our bitmap 
       this.colorBitmap.WritePixels(
        new Int32Rect(0, 0, this.colorBitmap.PixelWidth, this.colorBitmap.PixelHeight), 
        this.colorPixels, 
        this.colorBitmap.PixelWidth * sizeof(int), 
        0); 
      } 
     } 
} 
+0

깊이 이미지의 색상을 지정하기위한 해결책을 찾았습니까? – ThunderWiring

+0

결국 나는 이것을위한 kinect 샘플에서 찾은 클래스를 사용했고, 파일의 이름은 DepthColorizer.cs입니다. 깊이있는 색상이있는 샘플을 살펴보십시오! – Diedre

답변

1
byte intensity = (byte)(depth >= minDepth && depth <= maxDepth ? depth : 0); 
//WHAT IS THIS LINE ABOVE DOING? 

if 문 및 상기 기본적으로는 하나 개의 라인을 Ternary Operator

을 사용하는 라인에 상당 :

byte intensity; 

if (depth >= minDepth && depth <= maxDepth) 
{ 
    intensity = (byte)depth; 
} 
else 
{ 
    intensity = 0; 
} 

깊이 이미지 착색에 트릭 곱한다 색조에 의한 강도. 예 :

Color tint = Color.FromArgb(0, 255, 0) // Green 

// Write out blue byte 
this.colorPixels[colorPixelIndex++] = intensity * tint.B; 

// Write out green byte 
this.colorPixels[colorPixelIndex++] = intensity * tint.G; 

// Write out red byte       
this.colorPixels[colorPixelIndex++] = intensity * tint.R; 
+0

설명해 주셔서 감사합니다. 일부 해결책이 있습니다. 나는 많은 조건문을 사용하여 약간의 속도 저하를 보았지만 당신의 대답이 충분히 설명했다고 생각합니다. 고마워요. 만약 누군가가 kinect를 색칠하고 나에게 힌트를주기위한 코드를 공유하고 싶다면, 당신은 환영합니다. – Diedre

관련 문제