Image always appearing as empty

I've been trying to get the degree of redness in an RGB image and show it in another image. But the destination image always appears empty. I'm pretty much a newb at processing. here's my code.

//code to get Degree of Redness
import processing.video.*;
Capture cam; 
PImage img,imDeg,imThresh;
void setup()
 {
  imDeg=createImage(320,240,GRAY);
  imThresh=createImage(320,240,GRAY);
  size(640, 480);
  String [] cameras=cam.list();
  cam = new Capture(this,320,240,cameras[0]);
  cam.start(); 
} 

void DegreeRed()
{
  img.loadPixels();
  imDeg.loadPixels();
  for(int x=0;x<320;x++)
  {
    for(int y=0;y<240;y++)
    {

      //location of pixel
      int loc=x*240+y;

      //get RGB values
      float r1=red(img.pixels[loc]);
      float g1=green(img.pixels[loc]);
      float b1=blue(img.pixels[loc]);

      //Degree of Redness
      float r=r1-(g1+b1);
      float g=r1-g1;
      float b=r1-b1;
      if(r<0) r=0;
      if(g<0) g=0;
      if(b<0) b=0;
      float Dr=r+g+b;
      imDeg.pixels[loc]=int(Dr);
    }
  }
  imDeg.updatePixels();
}

void draw() 
{
  scale(2);
  if (cam.available()) { 
    // Reads the new frame
    cam.read(); 
  }
  img=cam;
  DegreeRed();
  //Thresh();
  image(imDeg, 0, 0); 
}

I'm continuously taking images from a camera and passing it through this function and printing the resulting imDeg image on the screen. But the image always appears empty. Thank You for your help.

Answers

Sign In or Register to comment.