2017-04-14 17 views
2

私はKinectPV2ライブラリを使用していますが、これは非常に説明はされていません。マップの奥行きをRGBスペース

"MapDepthToColor"の例を参照して、私は各RGBピクセルの深度を取得しようとしています。

DepthをRGB空間にマッピングするために元の例を調整すると、奇妙な重複したエッジが残っています(左下の画像を参照)。

誰かが何が起こっているかを指摘できますか?

/* 
Thomas Sanchez Lengeling. 
<a href="http://codigogenerativo.com/" target="_blank" rel="nofollow">http://codigogenerativo.com/</a> 

KinectPV2, Kinect for Windows v2 library for processing 

Color to fepth Example, 
Color Frame is aligned to the depth frame 
*/ 

import KinectPV2.*; 

KinectPV2 kinect; 

int [] depthZero; 

//BUFFER ARRAY TO CLEAN DE PIXLES 
PImage depthToColorImg; 

void setup() { 
    size(1024, 848, P3D); 

    depthToColorImg = createImage(512, 424, PImage.RGB); 
    depthZero = new int[ KinectPV2.WIDTHDepth * KinectPV2.HEIGHTDepth]; 

    //SET THE ARRAY TO 0s 
    for (int i = 0; i < KinectPV2.WIDTHDepth; i++) { 
    for (int j = 0; j < KinectPV2.HEIGHTDepth; j++) { 
     depthZero[424*i + j] = 0; 
    } 
    } 

    kinect = new KinectPV2(this); 
    kinect.enableDepthImg(true); 
    kinect.enableColorImg(true); 
    kinect.enablePointCloud(true); 

    kinect.init(); 
} 

void draw() { 
    background(0); 

    float [] mapDCT = kinect.getMapDepthToColor(); // Size: 434,176 (512*424) 

    //get the raw data from depth and color 
    int [] colorRaw = kinect.getRawColor(); // Size: 2,073,600 (1920*1080) 

    int [] depthRaw = kinect.getRawDepthData(); // 434176 

    //clean de pixels 
    PApplet.arrayCopy(depthZero, depthToColorImg.pixels); 

    int count = 0; 
    depthToColorImg.loadPixels(); 
    for (int i = 0; i < KinectPV2.WIDTHDepth; i++) { 
    for (int j = 0; j < KinectPV2.HEIGHTDepth; j++) { 

     //incoming pixels 512 x 424 with position in 1920 x 1080 
     float valX = mapDCT[count * 2 + 0]; 
     float valY = mapDCT[count * 2 + 1]; 


     //maps the pixels to 512 x 424, not necessary but looks better 
     int valXDepth = (int)((valX/1920.0) * 512.0); 
     int valYDepth = (int)((valY/1080.0) * 424.0); 

     int valXColor = (int)(valX); 
     int valYColor = (int)(valY); 

     if (valXDepth >= 0 && valXDepth < 512 && valYDepth >= 0 && valYDepth < 424 && 
     valXColor >= 0 && valXColor < 1920 && valYColor >= 0 && valYColor < 1080) { 
     float col = map(depthRaw[valYDepth * 512 + valXDepth], 0, 4500, 0, 255); 
     //color colorPixel = colorRaw[valYColor * 1920 + valXColor]; // This works as intended 
     color colorPixel = color(col); // This doesn't 
     depthToColorImg.pixels[valYDepth * 512 + valXDepth] = colorPixel; 
     } 
     count++; 
    } 
    } 
    depthToColorImg.updatePixels(); 

    image(depthToColorImg, 0, 424); 
    image(kinect.getColorImage(), 0, 0, 512, 424); 
    image(kinect.getDepthImage(), 512, 0); 

    text("fps: "+frameRate, 50, 50); 
} 

Current faulty result

+0

私は彼のライブラリwitht慣れていないんだので、いくつかの推測を唯一提供することができます:それはあなたがそのように反復していることが可能です(丸め誤差のために)それらのピクセルを見逃してしまった。また、「深さ」という言葉には混乱があると思います。いくつかの場所では、width:valXDepth <512を意味し、それ以外の場合は、kinextからの距離を意味します。int [] depthRaw = kinect.getRawDepthData(); 'valXDepth> = 0 && ...'ブロックで奥行きデータを無視し、単色を出力する場合は、内部を変更してみてください。 – Basic

+0

...一方、反復処理の問題がある場合は、出力に同じバンドが含まれている必要があります。 – Basic

+0

「深さデータを無視する」という意味を明確にしてください。この例では、 'kinect.getMapDepthToColor()'が正確に何を返しているのかまだ分かりませんが、私はこの問題をさらに説明するために上記のコードを少し微調整しました。 'colorRaw [ ] 'それはdup効果を引き起こす' depthRaw [] 'とは異なり、意図的なものとして動作します。 –

答えて

関連する問題