Hey all,
I’m only a few months in to using openFrameworks and was pretty decent with Processing, but since update and draw are two separate functions I’m having a hard time understanding how to go through a 2D pixel array loop and draw rectangles.
Essentially I’m using a ofxKinect to read the depth data from a kinect. If anything is within a certain threshold of depth I want my program to read the RGB color and draw a 4x4 rectangle. The end effect should look like the user gets pixelated as they get closer to the camera.
I know how to read the depth data in the update() loop and set an ofImage titled curFrame to the latest RGB value, but I’m getting tripped up on how to get to the draw() loop to draw the rectangles that I want. See below for my .cpp code:
#include “testApp.h”
//--------------------------------------------------------------
void testApp::setup() {
ofSetLogLevel(OF_LOG_VERBOSE);
kinect.setDepthClipping(500,1000);
kinect.setRegistration(true);// enable depth->video image calibration
kinect.init();
kinect.open();
colorImg.allocate(kinect.width, kinect.height);
grayImage.allocate(kinect.width, kinect.height);
ofSetFrameRate(60);
angle = 17;
kinect.setCameraTiltAngle(angle);
// start from the front
bDrawPointCloud = false;
curFrame.allocate(kinect.width, kinect.height, OF_IMAGE_COLOR);
scale = 4;
cols = ofGetWindowWidth()/scale;
rows = ofGetWindowHeight()/scale;
}
void testApp::update() {
ofBackground(0, 0, 0);
kinect.update();
if(kinect.isFrameNew()) {
ofPixels& depthPixels = kinect.getDepthPixelsRef();
ofPixels& colorPixels = kinect.getPixelsRef();
for (int i= 0; i < 640; i++) {
for (int j = 0; j < 480; j++) {
color = colorPixels.getColor(i, j);
depth = depthPixels.getColor(i, j);
if(depth.getBrightness() < mouseX){
curFrame.setColor(i, j, color);
}else{
ofSetColor(curColor);
ofRect(x+ofRandom(-10,10),y+ofRandom(-10,10),scale,scale);
}
}
}
}
curFrame.update();
}
void testApp::draw() {
curFrame.draw(0,0,640,480);//modified image
}
Any help would be appreciated.