2012-05-03 46 views
0

[背景]我幫助一個研究生(MFA)與一個藝術項目:SimpleOpenNI/Kinect的:sceneMap /深度圖顏色控制

我試圖控制深度圖產生的輸出顏色,使紅,綠色,&藍色值可以是獨立控制。期望的最終遊戲是每個depthMap生成的值可以更改爲品紅色(255,0,255)的各種色調,以便每個SimpleOpenNI用戶都會出現差異化。

到目前爲止,我還沒有找到一種方法在PDE文件要做到這一點,也沒有修改SimpleOpenNI類,以適應同一個目標的正確方法。 - 無論出於何種原因,色調()調用更改畫布的Alpha值,但不似乎調整顏色值。

任何適用的建議,將不勝感激。

資源:SimpleOpenNI Souce 我的PDE:

import SimpleOpenNI.*; 


SimpleOpenNI context; 

void setup() 
{ 
    context = new SimpleOpenNI(this); 

    // enable depthMap generation 
    if(context.enableScene() == false) 
    { 
    println("Can't open the sceneMap, maybe the camera is not connected!"); 
    exit(); 
    return; 
    } 

    frameRate(30); 
    background(128); 
    size(context.sceneWidth() , context.sceneHeight()); 
} 

void draw() 
{ 

    // update the cam 
    context.update(); 

    // draw irImageMap && Sets frame size. 
    image(context.sceneImage(),25,25, 590,430); 

    // "blend" shapes BG & previous the frame 
    tint(#ED145B, 125); 

} 
+0

[題外話]:什麼MFA是什麼? :) –

+0

有一些混亂的事情:(「期望的最終遊戲是每個深度圖。」 - 你的意思是深度圖或sceneMap?),「使每個用戶SimpleOpenNI會出現分化」 - 每個用戶在默認情況下是有區別的 - 你的意思是每個用戶的顏色不同的自定義色調/獨立於深度?此外,您應該在調用image()之前調用tint() –

+0

您可以使用Java編程Kinect?!?????????????我每天都會學到一件新東西 –

回答

0

除了sceneImage(),SimpleOpenNI還提供了一個名爲sceneMap()方法,該方法採用int []作爲輸入。它填充數組中映射到具有與該用戶相對應的編號的特定用戶的值。

例如,如果你沒有用戶,sceneMap陣列將用零填充(例如[0,0,0.....0]) 如果有1個用戶,一些元件將被填充有1的像素屬於該用戶(例如[0,0,0,1,1,...1,0,0,0,1,0...etc.])和等等。

您可以嘗試在PImage中進行一些顏色替換,但這不是很靈活(如果您還啓用了深度貼圖,那麼該怎麼辦?),並且您依賴於每個用戶的硬編碼值(R,B ,G,C,M,Y,這可能是SimpleOpenNI中的順序),所以sceneMap()是更靈活的選項。

下面是關於如何使用這個註釋過的例子:如果你要滿足多個用戶

import SimpleOpenNI.*; 

SimpleOpenNI context; 

int[] sceneMap;//this will store data about the scene (bg pixels will be 0, and if there are any users, they will have the value of the user id - e.g. if there are no users, the array will be filled with zeros, if there is one user, some array entries will be equal to 1, etc. the size of the array is the same as the number of pixels in scene image, so it's easy to use with the pixels[] of a PImage 
PImage myUserImage;//this is where we'll draw the user 
int user1Colour = color(180,130,30);//change to whatever you like 

void setup() 
{ 
    context = new SimpleOpenNI(this); 
    context.enableScene(); 

    background(200,0,0); 
    size(context.sceneWidth() , context.sceneHeight()); 
    //set scene map array 
    sceneMap = new int[context.sceneWidth()*context.sceneHeight()]; 
    //create the image to draw the user into, by default it will be filled black 
    myUserImage = createImage(context.sceneWidth() , context.sceneHeight(), RGB); 
} 

void draw() 
{ 
    context.update(); 

    // // gives you a label map, 0 = no person, 0+n = person n - tell OpenNI to update the numbers in the array 
    context.sceneMap(sceneMap); 
    //clear myUserImage - fill everything with black 
    Arrays.fill(myUserImage.pixels,color(0));//We've never used Arrays.fill() before, but all it does is it loops through all elements on an array you pass and sets a value you want for each element - fills an array with a value 
    for(int i = 0 ; i < myUserImage.pixels.length; i++){ 
    //check if there is a user for the current pixel, if so, use our custom colour for the pixel at this index 
    if(sceneMap[i] > 0) myUserImage.pixels[i] = user1Colour; 
    } 
    myUserImage.updatePixels(); 

    //display image 
    image(myUserImage,0,0); 
} 

從長遠來看,這是值得書寫一個基本的實用工具類:

import SimpleOpenNI.*; 

SimpleOpenNI context; 

SceneMapper sceneMap; 

void setup() 
{ 
    context = new SimpleOpenNI(this); 
    context.enableScene(); 

    background(200,0,0); 
    size(context.sceneWidth() , context.sceneHeight()); 

    sceneMap = new SceneMapper(context); 
} 

void draw() 
{ 
    context.update(); 
    sceneMap.update(); 
    //display image 
    image(sceneMap.scene,0,0); 
} 
class SceneMapper{ 
    PImage scene;//this is a PImage where we'll actually draw the user with what colour we want 
    int[] sceneMap;//this will store scene data - an array of ints which has the same length as context.sceneImage().pixels, the only difference is, sceneImage already has colours set, while scene map has numbers representing user(1,2,3etc.) on top of background(0s) 
    int numPixels;//total number of pixels, we only store it so we can reuse it 
    color bg;//background colour 
    color[] users = {color(255),color(192),color(127),color(64),color(32)};//fill colours for users 

    SceneMapper(SimpleOpenNI context){ 
    numPixels = context.sceneWidth()*context.sceneHeight(); 
    sceneMap = new int[numPixels];//init scene nap array 
    scene = createImage(context.sceneWidth(), context.sceneHeight(), RGB);//create a PImage to display scene data 
    scene.loadPixels(); 
    bg = color(0); 
    } 
    void update(){ 
    context.sceneMap(sceneMap);//ask SimpleOpenNI to store scene map data into our array 
    Arrays.fill(scene.pixels, bg);//clear the image - fill it with the background colours 
    for(int i = 0 ; i < numPixels ; i++){//loop through all pixels 
     for(int u = 0 ; u < users.length; u++){//loop through user colours 
     if(sceneMap[i] > 0) scene.pixels[i] = users[u];//if there are user pixels, use set user colour for those pixels (e.g. pixels with value 1 will use colours stored in users[0], pixels with value 2 will use colour from users[1], etc.) 
     } 
    } 
    scene.updatePixels();//we've use pixels, so update the image at the end 
    } 
} 

但這取決於學生是否熟悉課程,並且考慮到它是MFA,對於清潔代碼的壓力更小,並且我承擔的工作壓力更大。

+0

你是當場上。 MFA椅子不關心乾淨的代碼,他們關心[美學]輸出。他們不知道它是如何完成的,或者需要多長時間,他們現在需要它。 非常感謝您的幫助。正如您所指出的,我對這些課程並不熟悉,而且對Kinect&Processing來說也是新手。這非常有幫助。 – user1371072

+0

如果你有時間的話,後續問題。使用SceneMapper更新方法,如何爲下四個用戶設置顏色[s]? - 另外,你如何獨自測試? – user1371072

+0

- 相反,如果我已經聲明「color [] users = {color(MAGENTA),color(MAGENTA2),color(MAGENTA3),color(MAGENTA4),那麼我如何獲取sceneMap來更新用戶以顯示不同的顏色。 ,顏色(MAGENTA5)}; //爲用戶填充顏色「 – user1371072