Using Camera Tracking System with Processing

Some sample code I use to test this module.
 

Debug mode (streaming B&W)

I’m using this to see “real-time” what camera sees for debugging purposes. Data format is simple: a header with some control bytes and “start frame” byte, raw image data then “end of frame”. I am only controlling the “start frame” part, ignoring “end frame”.

void draw() {	
  myPort.write("Bw");
  while (myPort.available() > 0){
    byte[] inBuffer = new byte[H*(W/4+1)+2];
    myPort.readBytes(inBuffer);
    if ((inBuffer != null) && (inBuffer[1] == 0)){
      for (y=0;y<H;y++){
        for (x=0;x<(W/4);x++){
          noStroke();
          pixel1= inBuffer[y*(W/4)+x+3];

          fill(pixel1 & 0xF0);
          rect((x*4)*m, y*m, m*2, m);
          fill((pixel1 & 0x0F)<<4);          
          rect((x*4+2)*m, y*m, m*2, m);
        }
      }
    }
    myPort.clear();
  }
}

 

RGB444 streaming mode

I’m using this piece of code to retrieve a full frame (QVGA, 320 x 240) from my module and display it. Data format is already explained here.

void draw() {
    myPort.write("N1");
    while (myPort.available() > 0){
      byte[] inBuffer = new byte[2*H*W+4];
      myPort.readBytes(inBuffer);
      if ((inBuffer != null) && (inBuffer[1] == 0)){
        for (y=0;y<H;y++){
          for (x=0;x<W;x++){
            noStroke();
            colorMode(RGB, 255);
            pixel1= inBuffer[y*2*W+x*2+2]&0xff;
            pixel2= inBuffer[y*2*W+x*2+2+1]&0xFF;
            fill(pixel1<<4, pixel2 & 0xf0 , (pixel2 & 0x0f)<<4);
            rect(x, y, 1, 1);
          }
        }
      }
     myPort.clear();
    }
}

2 thoughts on “Using Camera Tracking System with Processing

Leave a comment