Tuesday, July 3, 2012

grabbing hands

        ...grab all the video frames they can.  Or maybe they don't...

        It's funny, i've always been a graphics-ish programmer.  I don't mean hardcore rendering programmer or any of that madness, but i've always been motivated to code by graphics.  Back in high school, the first thing I dove into while learning C was the BGI, mainly so I could learn how to code graphics for demos (never mind that everyone was writing demos in assembly, which i was also learning so i could...yeah, write graphics routines).  I can only imagine where I'd be nowadays if I'd had things like openframeworks to tinker with.  Of course, we did have GLUT back in my day, which i did spend a fair amount of time mucking about with.  Cool how somethings just stand the test of time.

        Taking the plunge into video capture with openframeworks tonight, whipped up another quick, bitcrushesque-type vis. Took some cues from some of the processing vidcap samples i've been doing, some ideas just keep working:


ofVidTest
Should you lose your disc, you will be subject to immediate de-resolution...


        ...And of course, here're some codes:
/* testApp.h */ 
#pragma once

#include "ofMain.h"

class testApp : public ofBaseApp{
 public:
  void setup();
  void update();
  void draw();
  
  ofVideoGrabber grabber;
  unsigned char* gPixels;
  ofImage img;
};

/* testApp.cpp */
#include "testApp.h"

void testApp::setup()
{
 grabber = ofVideoGrabber();
 grabber.setVerbose(true);
 grabber.initGrabber(640,480,true);
 ofEnableAlphaBlending();
}

void testApp::update()
{
 grabber.update();
}

void testApp::draw()
{
 ofBackground(0,0,0);
 gPixels = grabber.getPixels();
 for(int x=0;x<64;x++)
 {
  int xStep = x*10;
  for(int y=0;y<48;y++)
  {
   int yStep = y*10;
   int i = (yStep)*640*3+xStep*3;
   ofSetColor(gPixels[i],gPixels[i+1],gPixels[i+2],128);
   ofRectMode(OF_RECTMODE_CENTER);
   ofNoFill();
   ofRect(xStep,yStep,10,10);
   ofSetColor(gPixels[i],gPixels[i+1],gPixels[i+2],255);
   ofFill();
   ofCircle(xStep,yStep,3);
  }
 }
}