This openFrameworks project is based on the Depth Visualizer example that Kyle gave us.  Our assignment was to create a bounding box in 3D around our target objects, along with centroids, in a similar manner as the Computer Vision example with the Centroids that Kyle also provided.

Zach explained the concept that every pixel of the “depthImage” in the Depth Visualizer example represents an x, y and z value and that we just needed to iterate through all the pixels, add up the x, y and z values and find the middle value, which would be the centroid.

Mike Knuepfel helped me with the creation of the bounding box, as well as the blob centroid and bounding box center.  All of this is handled in the “drawPointCloud” function. We created a boolean called “firstTime” [iterating through the pixels contained within cameraHeight and cameraWidth] and set it to “true”.  We also created local “long’s” for “totalX”, “totalY”, “totalZ” [all set to 0] and “pointTotal” [set to 1].  Within the pixel loop, we created a local “int” for the “z” value, equal to “depthPixels[i]”.  Then we added x, y, and z pixels to the totalX, totalY, and totalZ values and incremented the pointTotal value.  An “if” statement followed, setting the initial min/max values for x, y, z and changing the firstTime boolean to false.  A series of “if” statements follow, setting the min and max values for each x, y, z.  After the “glEnd();”, we set the centroid x, y, z values to the total for each, divided by the pointTotal, and also the centers of the bounding box (the min value plus difference between the max and min values divided by 2).  We then drew the centroid (I colored mine blue) and bounding box center (colored red) with GL_POINTS.  Finally, we drew the lines of the bounding box (actually a “boxoid” because this is 3D) by first drawing the front and back planes and then drawing the sides, all with GL_LINES.  (Eric Mica mentioned afterward that we could use the “glutWireCube” for this.)

The Depth Visualizer example draws both the “depthImage” and the “pointCloud” to the screen, which can be distracting to look at. So to simplify, I commented out the drawing of the depthImage and adjusted the “ofTranslate” code to center the drawing of the pointCloud.

I wanted to spice it up, so I added the project files from the “opticalFlow with Lines” example and drew that to the screen in red.  I also created variables for the differences between the centroids and the bounding box centers and set those to absolute numbers.  I then based the rotation of the pointCloud on these differences, so that it would dynamically change in relation to the movement of the subject being tracked.  Here’s the code: DepthVisualizer_BoundingBoxHW I set the near/far threshold of the pointCloud via the controlPanel and then made this recording:

« »