Webcam experiment: dynamic pseudo-3D modelling

This is an extension of a little app I made around a year ago, which coloured and filled boxes with hex values based on the sampled colours of an image. Like this!:

That, however, was inspired bybased on … blatantly copied from some images by the hugely talented Luigi De Aloisio.

In the name of originality, and boredom, I more recently hooked the same function up to the Camera class, and updated the grid every frame. Useful if you need to know precisely what web colours your face is made up of, but the whole challenge with the original app was finding a good source image that would remain discernible once grid-ified, so most of the time you’re stuck with meaningless coloured blocks. (As a lifelong fan of Sesame Street, that was enough for me, but I’m trying to make a career out of this stuff.)

Removing the text and squarin’ up the rectangles, you effectively get an over-pixelated form of the video feed – just like having a webcam from the 90s! I thought it might be interesting to dynamically update the z-axis position of each cell, and overall brightness seemed to be the most sensible property to sample. It looks like this:

So, to recap what’s happening: per frame, the feed from the camera is sampled at regular intervals, across a grid of specified resolution, to capture the pixel colour at each point (I couldn’t afford the overhead of averaging across each blocks’ area). On the first pass, for each cell, a Shape object is created, filled with a square, and added to the grid array. On subsequent passes, each Shape object’s colorTransform property is set to the sampled pixel colour (computationally preferable to clearing and redrawing the square, but not hugely). The R, G and B values composing the cell colour are then averaged and normalised, before being used to move the cell backwards along the z-axis by an amount proportional to its darkness. (Because darker things are further away, sometimes, maybe…? It more or less works for the shadowy areas in faces anyway.)

The squares look ok, but with the grid floating in 3D space, I thought it might look cooler to use solid blocks instead. Unfortunately your CPU will not find it cooler. Quite the opposite; performance isn’t great with this one:

The code differences here involved replacing each Shape object with a Sprite (in order to contain the multiple cube sides), and the four extra panels were drawn and rotated into position. Side colours were varied to make the blocks appear shaded, and on updating the colorTransform property, the three channel multipliers were each set to 0.6, in order to avoid washing the shading out altogether.

Next steps? As I’m yet to identify a practical application for all this, there’s little need to have it running in a browser or on Flash at all, so I may take a crack at porting it to Processing or C++ with OpenGL, for the perfomance gain. It might be nice to see it draw one box per pixel, or to to use the brightness to set the Z co-ordinate of vertices rather than faces, and then stretch the video over a surface. A plain ol’ wireframe mesh might look nice too.

Any feedback on performance would be great.

Edit: Source code uploaded to my github repository here.

Related posts

  1. extractor
  2. catlight
  3. syn0p5
  4. p0809_sm


    Insanity Press
  5. inspiralmonkeysSM


    New Things
  6. one


  1. Allen Alvarez 2010.01.10 3:02am

    Hello Adam, my name is Allen. I’m from Mexico City and I study Phyisics in UNAM. I really find your flatCell and cubeCell examples very use useful for a project I need to run for my thermo course. It is possible to buy your codes?

    Very interesting stuff!

  2. Adam 2010.01.14 2:43am

    Hi Allen! I appreciate the interest, and have emailed the code for both variants of the experiment to the address you commented with. Looking forward to seeing what you come up with. =)

  3. Ryan 2012.07.25 11:01pm

    Very cool stuff. I’d like to tinker with your code a bit too, if you care to share.

  4. Adam 2012.08.07 9:08pm

    Hey, thanks for your comment. I’ve just added a link to the source code in the article above – hope it’s of some use to you!

  5. Andreia Gil 2016.11.16 1:31pm

    Hi Adam!
    I found your experiment very cool!
    I´m a visual/digital artist, and I thought that maybe I could make some very nice things with my images (like the first image example).Do you mind if I use it?
    If I make something to be seen or publish I will credit you, of course.
    : ) Thanks

HTML tag cannot be used in this comment.


I'm Adam Vernon: front-end developer, free-time photographer, small-hours musician and general-purpose humanoid.