getColor() for Kinect

howdy folks

so ive come back to coding after a long time. I used to do openFrameworks & other things for many moons, & have come to Processing due to wanting to cut out the huge IDE & in some ways, not use C++ :wink:
plus Processing has reached version 4, well done :+1:

but im trying to convert some old Kinect code & would like a finger to gently point me in a good direction.
ive been looking at examples, other code & the such & cant find much on what im looking for.
but I decided to do another β€œsimple” Kinect example I had done years ago.
when you are in front of the camera, it turns some Xs around depending on the color of the camera. so light/brightness affects it, basically

here is my code from the old C++

void ofApp::draw(){
  kinect.draw(0, 0, 640, 480);
  for (int i = 0; i < kinect.getWidth(); i += 16) {
    for (int j = 0; j < kinect.getHeight(); j += 16) {
      ofColor color = kinect.getPixels().getColor(i, j);
      float brightness = color.getBrightness();
      ofPushMatrix();
      ofTranslate(i, j);
      ofRotateZDeg(ofMap(brightness, 0, 255, 0, 360));
      ofDrawLine(0 - 8, 0, 0 + 8, 0);
      ofDrawLine(0, 0 - 8, 0, 0 + 8);
      ofPopMatrix();
    }
  }
}

I am using the Open Kinect library.
the part im having some trouble understanding or trying to find is this line:

ofColor color = kinect.getPixels().getColor(i, j);

everything else im cool with, it works to a point. but grabbing color with the getColor(I, j); is getting me hit against a wall & im somewhat lost now. so I figured its worth asking the crowd for help

this is my current Processing code & I got to a point & had to come away from it. so the line im trying to get is incomplete

void draw(){
  image(kinect.getVideoImage(), 0, 0);
  
  for (int i = 0; i < kinect.width; i += 16){
    for (int j = 0; j < kinect.height; j += 16){
      int col = kinect.getVideoImage().
      float bright = brightness(col);
      pushMatrix();
      translate(i, j);
      rotateZ(map(bright, 0, 255, 0, 360));
      line(0 - 8, 0, 0 + 8, 0);
      line(0, 0 - 8, 0, 0 + 8);
      popMatrix();
    }
  }
}

any help or direction to help me understand this change from openFrameworks code to Processing would be absolutely helpful

thanks

LL

1 Like

hi,

i guess it depends on the kinect library you use
but if you get the image by image(kinect.getVideoImage(), 0, 0);
then, you can read pixels from this image by:
color p=kinect.getVideoImage().pixels[ i+j*kinect.width ];

( if you have performance issue may be consider to copy kinect.getVideoImage() to a PImage before the loop, i don’t know if getVideoImage trigger some work in the background )

ok cool. good to know. ill give that a try & see how it goes :+1:

I also forgot to put up what library, so thank you you pointing that out, I updated the post. its using the Open Kinect library