Loading...
Processing Forum
Recent Topics
All Forums
Screen name:
rbrazileiro
rbrazileiro's Profile
2
Posts
1
Responses
0
Followers
Activity Trend
Last 30 days
Last 30 days
Date Interval
From Date :
To Date :
Go
Loading Chart...
Posts
Responses
PM
Show:
All
Discussions
Questions
Expanded view
List view
Private Message
[SimpleOpenNI] How to set image pixels as silhouette?
[0 Replies]
12-Dec-2012 07:21 AM
Forum:
Contributed Library Questions
Hi all!
I'm trying to change a little bit of the SimpleOpenNI example that separate user pixels from background to set pixels from an image inside the silhouette of users.
Here's my code (doesn't work, pixels are only black)
import SimpleOpenNI.*;
SimpleOpenNI kinect;
boolean tracking = false;
int userID;
int[] userMap;
void setup() {
size(600, 480);
kinect = new SimpleOpenNI(this);
kinect.enableDepth();
// enable color image from the Kinect
kinect.enableRGB();
kinect.enableUser(SimpleOpenNI.SKEL_PROFILE_NONE);
// turn on depth-color alignment
kinect.alternativeViewPointDepthToImage();
// load the background image
backgroundImage = loadImage("lua.jpg");
}
void draw() {
// display the background image
background(0);
kinect.update();
if (tracking) {
// get the Kinect color image
PImage rgbImage = loadImage("empire_state.jpg");
// prepare the color pixels
rgbImage.loadPixels();
loadPixels();
userMap = kinect.getUsersPixels(SimpleOpenNI.USERS_ALL);
for (int i =0; i < userMap.length; i++) {
for (int j = 0; j < rgbImage.pixels.length; j++) {
color c = rgbImage.pixels[j];
float r = red(c);
float g = green(c);
float b = blue(c);
// if the pixel is part of the user
if (userMap[i] != 0) {
// set the sketch pixel to the color pixel
pixels[i] = color((r + g + b) / 3);
}
}
}
rgbImage.updatePixels();
updatePixels();
}
}
void onNewUser(int uID) {
userID = uID;
tracking = true;
println("tracking");
}
Any ideas?
[Kinect, OpenNI, Osceleton] How to create an ArrayList with floats and PImage?
[4 Replies]
22-Jul-2012 07:43 AM
Forum:
Contributed Library Questions
Hi All,
How to create an ArrayList with float[] and PImage[] structures?
I want to associate each pointers from kinect Osceletor to your float position (x,y,z) and your image.
For example: headCoords has x, y and z position and an cerebral image associated.
My code return
NullPointerException
...
Lets go:
I have a class Skeleton:
class Skeleton {
float headCoords[] = new float[3]
float neckCoords[] = new float[3]
PImage headImg[] = new PImage[1];
PImage neckImg[] = new PImage[1];
float[] allCoords[] = {headCoords, neckCoords};
PImage[] orgaos[] = {headImg, neckImg}
int id;
Skeleton(int id) {
this.id = id;
}
}
in main i have:
import processing.opengl.*;
import oscP5.*;
import netP5.*;
OscP5 oscP5;
Hashtable<Integer, Skeleton> skels = new Hashtable<Integer, Skeleton>();
void setup() {
size(screen.height*4/3/2, screen.height/2, OPENGL); //Keep 4/3 aspect ratio, since it matches the kinect's.
oscP5 = new OscP5(this, "127.0.0.1", 7110);
hint(ENABLE_OPENGL_4X_SMOOTH);
noStroke();
}
void oscEvent(OscMessage msg) {
msg.print();
if (msg.checkAddrPattern("/joint") && msg.checkTypetag("sifff")) {
// We have received joint coordinates, let's find out which skeleton/joint and save the values ;)
Integer id = msg.get(1).intValue();
Skeleton s = skels.get(id);
if (s == null) {
s = new Skeleton(id);
skels.put(id, s);
}
if (msg.get(0).stringValue().equals("head")) {
s.headCoords[0] = msg.get(2).floatValue();
s.headCoords[1] = msg.get(3).floatValue();
s.headCoords[2] = msg.get(4).floatValue();
s.headImg[0] = loadImage("data/1.png");
}
else if (msg.get(0).stringValue().equals("neck")) {
s.neckCoords[0] = msg.get(2).floatValue();
s.neckCoords[1] = msg.get(3).floatValue();
s.neckCoords[2] = msg.get(4).floatValue();
s.neckImg[0] = loadImage("data/2.png");
}
}
else if (msg.checkAddrPattern("/new_user") && msg.checkTypetag("i")) {
// A new user is in front of the kinect... Tell him to do the calibration pose!
println("New user with ID = " + msg.get(0).intValue());
}
else if(msg.checkAddrPattern("/new_skel") && msg.checkTypetag("i")) {
//New skeleton calibrated! Lets create it!
Integer id = msg.get(0).intValue();
Skeleton s = new Skeleton(id);
skels.put(id, s);
}
else if(msg.checkAddrPattern("/lost_user") && msg.checkTypetag("i")) {
//Lost user/skeleton
Integer id = msg.get(0).intValue();
println("Lost user " + id);
skels.remove(id);
}
}
void draw()
{
background(0);
for (Skeleton s: skels.values()) {
for (float[] j: s.allCoords) {
for (PImage[] i: s.orgaos) {
pushMatrix();
translate(j[0]*width, j[1]*height, -j[2]*300);
image(i[0], j[1], j[2]);
popMatrix();
}
}
}
}
}
Any suggestion?
This code is hacked from
https://github.com/Sensebloom/OSCeleton-examples/tree/master/processing/MotionCapture3D
best from brazil.
«Prev
Next »
Moderate user : rbrazileiro
Forum